Hi, I’m attempting to define a variable for use with set_fact and then refer to it again when defining another variable. Is this possible/supported? Eg.
- name: Attempt to store host name in a temporary dictionary
set_fact:
host_name: “{{ host_prefix }}{{ (host_offset+item.0)|int }}-{{ host_suffix }}”
name_map: “{{ name_map | default({}) | merge({ item.1.id: host_name }) }}”
with_indexed_items: ec2.instances
I can see that ‘host_name’ gets build correctly but the dictionary just gets ‘Undefined’ If I remove the host_name definition above name_map, how do I then nest all of that as the argument to the dictionary entry? It looks darn ugly for starters but I can’t even figure out the string concatenation (with an integer throw in) inside the moustaches!
Any guidance appreciated.
Jim
PS? The merge function is defined in filter_plugins/ - it’s not part of Ansible, though a standard addition.