forked from msergiy87/ansible-create-users
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_users.yml
33 lines (28 loc) · 856 Bytes
/
create_users.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
---
- hosts: all
remote_user: blackman
become: true
become_user: root
# vars:
# users:
# - username: galya
# use_sudo: no
# - username: kolya
# use_sudo: yes
tasks:
- include_vars: users.yml
- name: Add Users
user: name={{ item.username }} shell=/bin/bash groups=apache,nginx,wheel,users createhome=yes comment='Created with Ansible'
with_items: '{{users}}'
- name: Upload SSH Authorized Keys
authorized_key: user={{ item.username }}
key="{{ lookup('file', 'pub_keys/{{ item.username }}.pub') }}"
with_items: '{{users}}'
- name: Update SUDOers file
lineinfile: "dest=/etc/sudoers
insertafter=EOF
line='{{ item.username }} ALL=(ALL) NOPASSWD: ALL'
regexp='^{{ item.username }} .*'
state=present"
when: 'item.use_sudo == True'
with_items: '{{users}}'