rajops

user.yml

Mar 6th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.83 KB | None | 0 0
  1. Hi,
  2.  
  3. I was trying to deploy user and sudo privileges by ansible palybooks and for changing a particular line in sudoer file I've used "lineinfile"  module but when ever I execute it throws me any error. can any one explain me what is the error and how to troubleshoot it.
  4.  
  5. here is my yaml file
  6.  
  7.     - name: update yum cache
  8.       yum:
  9.         update_cache: yes
  10.         update_only:  yes
  11.         use_backend: yum
  12.       become: yes
  13.      # when: ansible_facts['os_family'] == "RedHat"
  14.  
  15.  
  16.     - name: creating user on target nodes webR1
  17.       user:
  18.         name: "{{ remote_user }}"
  19.         password: '$6$rounds=656000$nKmf6WS3KcQUYvql$RYKVpfwn8abFQnxXvDatcen.2c0RrUHVihG2yMXeNPrCgMup5azfeILb4Hf7p8VtszOLmAlAVoOG3TvP0fRz31'
  20.         shell: /bin/bash
  21.         state: present
  22.         home: /home/ "{{ remote_user }}"
  23.       become: yes
  24.  
  25.     - name: create wheel group
  26.       group:
  27.         name: wheel
  28.         state: present
  29.  
  30.     - name: granting the sudo previliges to remote user
  31.       lineinfile:
  32.         path: /etc/sudoers
  33.         regexp: "{{ remote_user }} ALL"
  34.         line: "{{ remote_user }} ALL=(ALL) NOPASSWD: ALL"
  35.         state: present
  36.  
  37.      #- name: copying the public key of control to traget
  38.      # command: sshpass -p password ssh-copy-id -i /home/ansadmctrl/.ssh/id_rsa.pub -o StrictHostKeyChecking=no "{{ remote_user }}"@172.31.19.69
  39.  
  40.     - name: Deploying the public key in the target machine
  41.       authorized_key:
  42.         user: "{{ remote_user }}"
  43.         state: present
  44.   This is the error
  45.  
  46. [ansadmctrl@ip-XXX-XX-XX-XX ex2]$ ansible-playbook -i inven-dev user.yml  -K
  47. SUDO password:
  48.  [WARNING]: Found variable using reserved name: remote_user
  49.  
  50.  
  51. PLAY [creating a user with sudo pervilges on target machine webR1] ***********************************************************************************
  52.  
  53. TASK [update yum cache] ******************************************************************************************************************************
  54. ok: [webR1]
  55.  
  56. TASK [creating user on target nodes webR1] ***********************************************************************************************************
  57. ok: [webR1]
  58.  
  59. TASK [create wheel group] ****************************************************************************************************************************
  60. ok: [webR1]
  61.  
  62. TASK [granting the sudo previliges to remote user] ***************************************************************************************************
  63. fatal: [webR1]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 172.31.19.69 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/.ansible-ansadm2/tmp/ansible-tmp-1551931429.95-102542624704258/AnsiballZ_lineinfile.py\", line 113, in <module>\r\n    _ansiballz_main()\r\n  File \"/tmp/.ansible-ansadm2/tmp/ansible-tmp-1551931429.95-102542624704258/AnsiballZ_lineinfile.py\", line 105, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/tmp/.ansible-ansadm2/tmp/ansible-tmp-1551931429.95-102542624704258/AnsiballZ_lineinfile.py\", line 48, in invoke_module\r\n    imp.load_module('__main__', mod, module, MOD_DESC)\r\n  File \"/tmp/ansible_lineinfile_payload_xhYrIb/__main__.py\", line 524, in <module>\r\n  File \"/tmp/ansible_lineinfile_payload_xhYrIb/__main__.py\", line 515, in main\r\n  File \"/tmp/ansible_lineinfile_payload_xhYrIb/__main__.py\", line 257, in present\r\nIOError: [Errno 13] Permission denied: '/etc/sudoers'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
  64.     to retry, use: --limit @/home/ansadmctrl/ansible/ex2/user.retry
  65.  
  66. PLAY RECAP *******************************************************************************************************************************************
  67. webR1                      : ok=3    changed=0    unreachable=0    failed=1
Add Comment
Please, Sign In to add comment