# Ansible 1.9 set\_fact and multiple vars?

**URL:** <https://forum.ansible.com/t/ansible-1-9-set-fact-and-multiple-vars/21993>\
**Category:** Ansible Project\
**Created:** [July 12, 2016, 11:26am UTC](https://forum.ansible.com/t/ansible-1-9-set-fact-and-multiple-vars/21993 "2016-07-12T11:26:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jvanns.ilm](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@jvanns.ilm](https://forum.ansible.com/u/jvanns.ilm)\
**Post date:** [July 12, 2016, 11:26am UTC](https://forum.ansible.com/t/ansible-1-9-set-fact-and-multiple-vars/21993/1 "2016-07-12T11:26:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jvanns.ilm](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@jvanns.ilm](https://forum.ansible.com/u/jvanns.ilm)\
**Post date:** [July 14, 2016, 1:39pm UTC](https://forum.ansible.com/t/ansible-1-9-set-fact-and-multiple-vars/21993/2 "2016-07-14T13:39:22Z")

</div>

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
