enh: replaced with loop

This commit is contained in:
xpk
2019-05-03 20:06:23 +08:00
parent 1ee5043781
commit 104a275369
+4 -4
View File
@@ -9,7 +9,7 @@
shell: /bin/bash shell: /bin/bash
groups: "{{ group }},ssh_access" groups: "{{ group }},ssh_access"
password: "{{lookup('password', 'cred.' + item + '.pass chars=ascii_letters,digits,hexdigitsi length=15') | password_hash('sha512')}}" password: "{{lookup('password', 'cred.' + item + '.pass chars=ascii_letters,digits,hexdigitsi length=15') | password_hash('sha512')}}"
with_items: "{{userlist}}" loop: "{{userlist}}"
- name: Add user to sudoers - name: Add user to sudoers
lineinfile: lineinfile:
@@ -18,16 +18,16 @@
line: "{{ item }} ALL=(ALL) NOPASSWD: ALL" line: "{{ item }} ALL=(ALL) NOPASSWD: ALL"
mode: 0440 mode: 0440
when: sudoers when: sudoers
with_items: "{{userlist}}" loop: "{{userlist}}"
- name: Display generated password - name: Display generated password
debug: debug:
msg: "Generated password for {{item}}: {{lookup('password', 'cred.' + item + '.pass chars=ascii_letters,digits,hexdigitsi length=15')}}" msg: "Generated password for {{item}}: {{lookup('password', 'cred.' + item + '.pass chars=ascii_letters,digits,hexdigitsi length=15')}}"
with_items: "{{userlist}}" loop: "{{userlist}}"
- name: Remove password files created by ansible - name: Remove password files created by ansible
file: file:
path: cred.{{item}}.pass path: cred.{{item}}.pass
state: absent state: absent
with_items: "{{userlist}}" loop: "{{userlist}}"