# How to use a gathered fact to get item from a dictionary?

**URL:** <https://forum.ansible.com/t/how-to-use-a-gathered-fact-to-get-item-from-a-dictionary/22774>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [October 11, 2016, 11:31pm UTC](https://forum.ansible.com/t/how-to-use-a-gathered-fact-to-get-item-from-a-dictionary/22774 "2016-10-11T23:31:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [October 11, 2016, 11:31pm UTC](https://forum.ansible.com/t/how-to-use-a-gathered-fact-to-get-item-from-a-dictionary/22774/1 "2016-10-11T23:31:37Z")

</div>

I have a dictionary that defines AWS mounts based on IP address

`  
aws\_efs\_mount:

- 10.22.100.1: aws\_mount\_10\_22\_100\_1
- 10.22.100.2: aws\_mount\_10\_22\_100\_2  
`

Now I want a task that creates an entry in /etc/fstab

`

# The idea is the src value resolves to src=aws\_mount\_10\_22\_100\_1 for a IP of 10.22.100.1

- name: Add entry in /etc/fstab  
mount: name=/mt/mount\_path src=“{{ aws\_efs\_mount.{{ ansible\_default\_ipv4.address }} }}”  
`

I get

`TASK [elasticsearch-elk : Add entry in /etc/fstab ***** fatal: [10.22.x.x]: FAILED! => {"failed": true, "msg": "plate error while templating string: expected name or number. String: {{ aws_efs_mount.{{ ansible_default_ipv4.address }} }}"}`

How can I achieve this? I can’t use a template since there are values in the /etc/fstab file.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 12, 2016, 2:27pm UTC](https://forum.ansible.com/t/how-to-use-a-gathered-fact-to-get-item-from-a-dictionary/22774/2 "2016-10-12T14:27:19Z")

</div>

> I have a dictionary that defines AWS mounts based on IP address
> 
> aws\_efs\_mount:  
> - 10.22.100.1: aws\_mount\_10\_22\_100\_1  
> - 10.22.100.2: aws\_mount\_10\_22\_100\_2

You don't have a dictionary, you have a list with dictionaries.

> Now I want a task that creates an entry in /etc/fstab
> 
> # The idea is the src value resolves to src=aws\_mount\_10\_22\_100\_1 for a IP  
> of 10.22.100.1  
> - name: Add entry in /etc/fstab  
> &nbsp;&nbsp;mount: name=/mt/mount\_path src="{{ aws\_efs\_mount.{{  
> ansible\_default\_ipv4.address }} }}"
> 
> I get
> 
> TASK [elasticsearch-elk : Add entry in /etc/fstab \*\*\*\*\*  
> fatal: [10.22.x.x]: FAILED! =\> {"failed": true, "msg": "plate error while  
> templating string: expected name or number. String: {{ aws\_efs\_mount.{{  
> ansible\_default\_ipv4.address }} }}"}
> 
> How can I achieve this? I can't use a template since there are values in  
> the /etc/fstab file.

You can't use curly brackets inside curly bracket.

To make it work you need to change aws\_efs\_mount to  
&nbsp;&nbsp;&nbsp;aws\_efs\_mount:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10.22.100.1: aws\_mount\_10\_22\_100\_1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10.22.100.2: aws\_mount\_10\_22\_100\_2

And the src in mount to  
&nbsp;&nbsp;&nbsp;src={{ aws\_efs\_mount[hostvars[inventory\_hostname].ansible\_default\_ipv4.address] }}
