Hi AnsiPeeps,
I have a nested structure in vars as so:
data_bricks:
ovirt-node-01:
- gluster_brick2
- gluster_brick4
ovirt-node-02: - gluster_brick1
- gluster_brick3
ovirt-node-03: - gluster_brick2
- gluster_brick4
(the number of items in the 2nd-level node now is two, but may be higher if necessary…)
So in the associated playbook, I need to do something akin to:
“mkdir -p /{{ item }}/data_brick”
For each item under the second-level item, which happens to be the {{ ansible_hostname }} of the server that I need the commands to be run on - so for instance on “ovirt-node-01” I’d need to run the commands:
“mkdir -p /gluster_brick2/data_brick”
“mkdir -p /gluster_brick4/data_brick”
In the playbook I want to use the above in, I have written a test debug task as so:
- name: Figure out how to use nested vars
debug: msg=“brick name is {{ item }}”
with_subelements: - engine_bricks.{{ ansible_hostname }}
tags: tryme
Which must be horribly wrong, because when I run it against the group of servers having the server names on the second level of the nested vars, it blows up with this error:
TASK: [ist-ovirt-gluster | Figure out how to use nested vars] *****************
fatal: [ovirt-node-02] => subelements lookup expects a list of two items, first a dict or a list, and second a string
fatal: [ovirt-node-01] => subelements lookup expects a list of two items, first a dict or a list, and second a string
fatal: [ovirt-node-03] => subelements lookup expects a list of two items, first a dict or a list, and second a string
I’ve read over http://docs.ansible.com/ansible/playbooks_loops.html a few times, thought i’d want “with_subelements”, but maybe not? Can anyone give me a pointer how to achieve what I’m trying to do?
TIA,
Will