Ansible create user with password, dont change it if user exists

Viewed 6021

I have some servers which I want to administer with ansible. Currently I need to create user acounts on all of them. On some of them, some accounts are already present. I want to create the users with a default password, but if the user exist don't change his password.

Can someone help me with this condition ?

Here is my playbook :

---
- hosts: all
  become: yes
  vars:
    sudo_users:
       # password is generated through "mkpasswd" command from 'whois' package
      - login: user1
        password: hashed_password
      - login: user1
        password: hashed_password

  tasks:
    - name: Make sure we have a 'sudo' group
      group:
        name: sudo
        state: present

    - user:
        name: "{{ item.login }}"
        #password: "{{ item.password }}"
        shell: /bin/bash
        groups: "{{ item.login }},sudo"
        append: yes
      with_items: "{{ sudo_users }}"
1 Answers
Related