Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Creating a User with Adding into Sudoers file. And also providing user to public key login Access.
- # Author : Ashok Kalakoti
- # Date: 2017
- ---
- - hosts: all
- become: yes
- become_user: root
- tasks:
- - name: Copy sudoers file for safety
- command: cp -f /etc/sudoers /etc/sudoers.tmp
- - name: Create sudoers file backup
- command: cp -f /etc/sudoers /etc/sudoers.bak
- - name: Create admins group
- group: name=admins system=yes state=present
- - name: make sure we can sudo as admin group
- lineinfile: dest=/etc/sudoers.tmp state=present regexp='^%admins' line='%admins ALL=(ALL) ALL'
- - name: also make sure ssh-agent works via sudo
- lineinfile: dest=/etc/sudoers.tmp state=present regexp='^Defaults env_keep\+\=SSH_AUTH_SOCK' line='Defaults env_keep+=SSH_AUTH_SOCK'
- - name: User Adding and Appending in Sudoers file
- user:
- name: ashok
- groups: admins
- append: yes
- password: $1$Ashok$zyIc8nUhsB0urEKYNlktk.
- - name: Final sudoers file check
- shell: visudo -q -c -f /etc/sudoers.tmp && cp -f /etc/sudoers.tmp /etc/sudoers
- - name: Set up authorized keys for the Ashok user
- authorized_key: user=ashok key="{{item}}"
- with_file:
- - /home/ansadm/.ssh/id_rsa.pub
Add Comment
Please, Sign In to add comment