Ansible 1.9 set_fact and multiple vars?

579 views
Skip to first unread message

jvann...@gmail.com

unread,
Jul 12, 2016, 11:26:30 AM7/12/16
to Ansible Project
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.

jvann...@gmail.com

unread,
Jul 14, 2016, 9:39:22 AM7/14/16
to Ansible Project
I'll reply to my own query; it can't be done. The first fact isn't available until the end of the task so the second fact cannot refer to it.

Me
Reply all
Reply to author
Forward
0 new messages