0

I would like to add a dict variable when looping with with_items like this:

set_fact:
  item.template: "base"
  when: item.template is not defined
  with_items: vHosts

But it seems to write to an wrong dictionary, i have then {"ansible_facts": {"item.template": "base"}, "item": {...}}.

trying vHosts['item']['template'] doesn't work either.

allo
  • 3,955
  • 8
  • 40
  • 71
  • Possible duplicate of [Using set\_facts and with\_items together in Ansible](http://stackoverflow.com/questions/29399581/using-set-facts-and-with-items-together-in-ansible) – Bruce P Dec 13 '15 at 13:13
  • Seems so. Ansible has some rather strange semantics -.- – allo Dec 13 '15 at 14:07

1 Answers1

0

Seems like this behaviour is not (yet) possible, see https://stackoverflow.com/a/29419080/893159.

My current workaround is now just to run one loop when: item.template is not defined and one when item.template is defined in the next statements, using item.template in one and using "base" in another.

Community
  • 1
  • 1
allo
  • 3,955
  • 8
  • 40
  • 71