Last active
July 27, 2021 08:35
-
-
Save t0rik/4a30e2da36c7e9c22ae8d84798b718fb to your computer and use it in GitHub Desktop.
Create user playbook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Linux Create User and Upload User Public keys | |
hosts: test | |
#remote_user: xxxx | |
#sudo: yes | |
vars: | |
user_1: devuser | |
tasks: | |
- name: Make sure we have a 'wheel' group | |
group: | |
name: wheel | |
state: present | |
- name: Allow 'wheel' group to have passwordless sudo | |
lineinfile: | |
dest: /etc/sudoers | |
state: present | |
regexp: '^%wheel' | |
line: '%wheel ALL=(ALL) NOPASSWD: ALL' | |
- name: Create user {{ user_1 }} | |
user: | |
name: "{{ user_1 }}" | |
shell: /bin/bash | |
groups: wheel | |
createhome: yes | |
home: /home/{{ user_1 }} | |
state: present | |
- name: create key directory | |
action: file path=/home/{{ user_1 }}/.ssh/ state=directory owner={{ user_1 }} group={{ user_1 }} mode=0700 | |
- name: create key file | |
action: file path=/home/{{ user_1 }}/.ssh/authorized_keys state=touch owner={{ user_1 }} group={{ user_1 }} mode=0600 | |
- name: Set authorized key took from file | |
authorized_key: | |
user: "{{ user_1 }}" | |
state: present | |
key: "{{ lookup('file', '/tmp/pubkey/id_rsa.pub') }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment