I have Linux servers that are using local accounts and I would like to find a way, with ansible, to maintain them.
My goal is to keep the same list of users on all servers and be able to efficiently delete or add a new user on all servers when there is a need for it. I would also like to push the playbook every now and then to correct anything that has been modified on a single server without ansible.
Here is what I got so far:
vars:
users:
- login: test1
group: group1
- login: test2
group: group1
tasks:
- name: Maintaining list of users
user: name={{ item.login }} group={{ item.group }} state=present
with_items:
- "{{ users }}"
This playbook works, but I need to add a step that would check if the user already exists and if it does not, then, create it and assign a temporary password.
Is there a way to tell ansible to create a user like in this playbook above, but also tell ansible to give the user a password if the it did not exist?
Thank you. Thierry.