loopsansible

Ansible - Hide values loop account creation


I try to create local account with a loop on ansible.

passwords are in group_vars vaulted

- name: "Add users"
  user:
    name: "{{item.name}}"
    uid: "{{item.uid}}"
    password: "{{ item.name | string | password_hash('sha512') }}"
    group: toto
    update_password: always
    comment: toto
    shell: /bin/bash
    password_expire_max: 365
  loop:
    - { uid: 12000, name: 'toto', password: "{{ toto  | string | password_hash('sha512') }}" } 

When i launch my playbook, password is printed in SHA in the loop

ok: [192.168.113.199] => (item={u'password': u' password in sha ', u'uid': 12000, u'name': u'toto'})

Does somebody know how hide the password ? Thank's by advance


Solution

  • When I launch my playbook, password is printed in SHA in the loop

    You may have a look into Adding controls to loops, Limiting loop output with label and use just additionally

      loop_control:
        label: "{{ item.name }}"
    

    This will limit the console output to the username key and value only. Also Extended loop variables can provide advantage.