enh: role now takes a list of users in the userlist variable
This commit is contained in:
+17
-11
@@ -3,25 +3,31 @@
|
||||
name: ssh_access
|
||||
state: present
|
||||
|
||||
- set_fact:
|
||||
plain_pass: "{{ lookup('password', '/dev/null chars=ascii_letters,digits,hexdigitsi length=15') }}"
|
||||
|
||||
- name: Create user {{ user.name }}
|
||||
- name: Create user
|
||||
user:
|
||||
name: "{{ user.name }}"
|
||||
name: "{{item}}"
|
||||
shell: /bin/bash
|
||||
groups: "{{ user.group }},ssh_access"
|
||||
password: "{{ plain_pass | password_hash('sha512') }}"
|
||||
groups: "{{ group }},ssh_access"
|
||||
password: "{{lookup('password', 'cred.' + item + '.pass chars=ascii_letters,digits,hexdigitsi length=15') | password_hash('sha512')}}"
|
||||
with_items: "{{userlist}}"
|
||||
|
||||
- name: Add user to sudoers
|
||||
lineinfile:
|
||||
path: "/etc/sudoers.d/{{ user.name }}"
|
||||
path: "/etc/sudoers.d/{{item}}"
|
||||
create: yes
|
||||
line: "{{ user.name }} ALL=(ALL) NOPASSWD: ALL"
|
||||
line: "{{ item }} ALL=(ALL) NOPASSWD: ALL"
|
||||
mode: 0440
|
||||
when: user.sudoers
|
||||
when: sudoers
|
||||
with_items: "{{userlist}}"
|
||||
|
||||
- name: Display generated password
|
||||
debug:
|
||||
msg: "Generated password for {{ user.name }}: {{ plain_pass }}"
|
||||
msg: "Generated password for {{item}}: {{lookup('password', 'cred.' + item + '.pass chars=ascii_letters,digits,hexdigitsi length=15')}}"
|
||||
with_items: "{{userlist}}"
|
||||
|
||||
- name: Remove password files created by ansible
|
||||
file:
|
||||
path: cred.{{item}}.pass
|
||||
state: absent
|
||||
with_items: "{{userlist}}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user