I'm trying to write a play that allows for me to only build certain
directories conditionally while using the with_nested.
Here's my variable dictionary:
routers:
router1:
hostname: adam
router2:
hostname: steve
Here's my play:
- name: create dirs for swiftmq
file:
state: directory
path: "{{app_path}}/{{item[1]}}/{{item[0]}}"
follow: yes
owner: inpho
group: inpho
mode: 0755
when:
- item[0].hostname == ansible_hostname
with_nested:
- "{{routers}}"
- [ 'config', 'deploy', 'jmsapp', 'log', 'store', 'trace' ]
So, my desired behavior is that it would only create the directories when
absible_hostname=adam or ansible_hostname=steve.
I get the following error:
fatal: [xxx]: FAILED! => {"failed": true, "msg": "The conditional check
'item[0].hostname == ansible_hostname' failed. The error was: error while
evaluating conditional (item[0].hostname == ansible_hostname): 'unicode object'
has no attribute 'hostname'\n\nThe error appears to have been in 'xxx': line
33, 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: create dirs for
xxx\n ^ here\n"}
Is it possible to use a when condition in conjunction with with_nested? If so,
how do I reference children of the items in the conditional? I've tried it a
bunch of ways & can't seem to figure it out.
Thanks in advance!
Adam
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/bb6fb40f-5955-48b4-98ba-a98044160a17%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.