Ansible检查用户是否刚刚创建并读取强制更改其密码的权限,如果已经存在则不执行任何操作
- name: add users
user:
name: "{{ item.name }}"
groups: "{{ item.groups }}"
system: yes
# append: yes
with_items: "{{ users }}"
register: listing
notify:
- set passwd in the first login
handlers:
- name: set passwd in the first login
shell: echo -e "{{ item.name }}\n{{ item.name }}" | passwd {{ item.name }} --stdin
shell: chage -d 0 {{ item.name}}
with_items: "{{ users }}"