I am trying to use ansible and ansible-vault to provision users. This is my current directory structure:
|-- ansible-test.out
|-- group_vars
|-- inventory
|-- roles
| |-- bsd_sudoers
| | |-- tasks
| | |-- templates
| | | `-- cde-admins
| | `-- vars
| `-- bsd_users
| |-- files
| |-- tasks
| | `-- main.yml
| |-- templates
| `-- vars
| `-- all.yml
|-- site.retry
|-- site.yml
`-- vars
`-- all.yml
This is what I have for my playbook so far:
---
- name: Creating Users
user:
name: "{{ item.name }}"
system : "{{ item.sudoer }}"
shell: /bin/bash
password: "{{ item.password }}"
uid: "{{ item.uid }}"
home: "{{ item.home }}"
with_items: users
Here is a sample of what I have in ansible vault:
---
vars:
users:
- name: 'foo'
home: '/home/foo'
key: 'ssh-rsa ....'
password: '!!'
bash: '/bin/bash'
sudoer: yes
uid: "2049"
guid: '2049'
group: admin
When I run the playbook, this error message is always generated:
fatal: [ansible-test]: FAILED! => {"failed": true, "msg": "The task includes an option with an undefined variable. The error was: 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'uid'\n\nThe error appears to have been in '/Users/ansible/playbooks/roles/bsd_users/tasks/main.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Creating Users\n ^ here\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'uid'"}
to retry, use: --limit @/Users/ansible/playbooks/site.retry
Why is this always happening? I was under the impression that Ansible would naturally pass the encrypted variables to my playbook but this does not seem to be the case.