Associative array in Ansible playbook

ansible

I'm trying to add users to my servers using Ansible. Each user have a different encrypted password.

I have something like that:

vars:
  users:
    - myuser1
    - myuser2
  password: encryptedpasswordhere

tasks:
  - name: Creating users
    user: name={{ item }} password={{ password }} groups=sudo,adm shell=/bin/bash
    with_items: users

This work great, but all users have the same password.

I'm looking to make an associative array. In PHP I would do that:

$users = array('user'=>'myuser1', 'password'=>'encryptedpass1',
               'user'=>'myuser2', 'password'=>'encryptedpass2',
               );

There is a way to do that in an Ansible playbook?

Best Answer

http://docs.ansible.com/playbooks_loops.html#looping-over-hashes

---
users:
  alice:
    name: Alice Appleworth
    telephone: 123-456-7890
  bob:
    name: Bob Bananarama
    telephone: 987-654-3210

and

tasks:
  - name: Print phone records
    debug: msg="User {{ item.key }} is {{ item.value.name }} ({{ item.value.telephone }})"
    with_dict: users