Defining vars in a file and looping over them

52 views
Skip to first unread message

Wayne Pascoe

unread,
Feb 14, 2016, 11:26:38 AM2/14/16
to Ansible Project
Hi all,

I'm trying to work with vars in a vars file inside a role, and I'm unable to make it work. I'm working from http://docs.ansible.com/ansible/playbooks_loops.html#standard-loops. Any pointers on what I'm doing wrong would be much appreciated.

I'm using 2.1.0 from Git on Debian.


If I have the following task in my role, it works as expected:

---
- name: Add groups
 
group: name={{ item.name }} gid={{ item.gid }} state=present
  with_items
:
   
- { name: 'g1', gid: '1010' }
   
- { name: 'g2', gid: '1011' }


However, if I try and use the vars in roles/rolename/vars/mail.yml and modify my role, I get the following error:

fatal: [myhost]: FAILED! => {"failed": true, "msg": "'unicode object' has no attribute 'gid'"}

If I remove the gid={{{ item.gid }} part of my task, then the message changes to 
fatal: [myhost]: FAILED! => {"failed": true, "msg": "'unicode object' has no attribute 'name'"}


tasks/groups.yml
---
- name: Add groups
 
group: name={{ item.name }} gid={{ item.gid }} state=present
  with_items
: "{{groups}}"


vars/main.yml
groups:
   
- { name: 'g1', gid: '1010' }
   
- { name: 'g2', gid: '1011' }


Thanks!

Wayne Pascoe

unread,
Feb 14, 2016, 11:28:38 AM2/14/16
to Ansible Project
Ah - that was simple... groups appears to be a reserved name. Changing to unixgroups works a treat.
Sorry for the noise...

Reply all
Reply to author
Forward
0 new messages