I have structures in group_vars files that looks roughly like the following:
Accounts1:
files:
- { src: ‘src_path/filename1’, dest: ‘dest_path/filename1’ }
- { src: ‘src_path/filename2’, dest: ‘dest_path/filename2’ }
app_groups: - { name: ‘group1’, gid: ‘1234’ }
- { name: ‘group2’, gid: ‘1235’ }
- { name: ‘group3’, gid: ‘1236’ }
app_accounts: - { name: ‘account1’, uid: ‘1234’, home: ‘/home/account1’, comment: ‘account1’ }
- { name: ‘account2’, uid: ‘1235’, home: ‘/home/account2’, comment: ‘account3’ }
- { name: ‘account3’, uid: ‘1236’, home: ‘/home/account3’, comment: ‘account3’ }
Accounts2:
files:
- { src: ‘src_path/filename3’, dest: ‘dest_path/filename3’ }
- { src: ‘src_path/filename4’, dest: ‘dest_path/filename4’ }
app_groups: - { name: ‘group4’, gid: ‘2234’ }
- { name: ‘group5’, gid: ‘2235’ }
- { name: ‘group6’, gid: ‘2236’ }
app_accounts: - { name: ‘account4’, uid: ‘2234’, home: ‘/home/account1’, comment: ‘account4’ }
- { name: ‘account5’, uid: ‘2235’, home: ‘/home/account2’, comment: ‘account5’ }
- { name: ‘account6’, uid: ‘2236’, home: ‘/home/account3’, comment: ‘account6’ }
And then I have a list that looks like this:
Accounts: [ ‘Accounts1’, ‘Accounts2’ ]
I want to be able to iterate over the Accounts list to refer to the members of the structures something like the following:
group: name=“{{item.app_groups.name}}” gid=“{{item.app_groups.gid}}”
with_items: Accounts
It isn’t quite working. What I am finding is that ‘item’ in the group task is being populated with the strings “Accounts1” and “Accounts2”, but what I really want in ‘item’ is the objects named Accounts1 and Accounts2. So is there some way make ‘item’ be a reference to an object instead of an object itself? I have tried ‘with_item’, ‘with_nested’, and ‘with_dict’, all to no avail.
Thanks,
-Mark