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 }}"
From the docs of user module:
update_password (added in 1.3)
always/on_create
alwayswill update passwords if they differ.on_createwill only set the password for newly created users.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With