# Host variables with dict value?

**URL:** <https://forum.ansible.com/t/host-variables-with-dict-value/13509>\
**Category:** Ansible Project\
**Created:** [September 19, 2013, 8:45pm UTC](https://forum.ansible.com/t/host-variables-with-dict-value/13509 "2013-09-19T20:45:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Shenton](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@Chris\_Shenton](https://forum.ansible.com/u/Chris_Shenton)\
**Post date:** [September 19, 2013, 8:45pm UTC](https://forum.ansible.com/t/host-variables-with-dict-value/13509/1 "2013-09-19T20:45:40Z")

</div>

In my playbook yaml file I had something like:

vars:  
vpc: {id: vpc-12345, net: 10.0.0.0/16}

and it worked when I referenced it:

- name: Launch instance  
local\_action:  
module: ec2  
vpc\_subnet\_id: ‘{{vpc.id}}’

I want to move these variables into dev- and prod-specific hosts file vars so I tried:

[local]  
vpc = {id: subnet-12345, net: 10.0.0.0/16}

and even variations like:

vpc = ‘{{ { id = subnet-12345, net = 10.0.0.0/16 } }}’

but in my play this is being seen as a string (or unicode, respectively) and generating errors: “‘str object’ has no attribute ‘id’”, or “‘unicode object’ has no attribute id”

Is there a way to set these host vars to dicts (or other objects) in these ini-style host files? Or am I limited to simple strings?

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 20, 2013, 1:17am UTC](https://forum.ansible.com/t/host-variables-with-dict-value/13509/2 "2013-09-20T01:17:48Z")

</div>

Hi Chris,

Look at the documentation for how to store files in group\_vars/foo and host\_vars/foo in YAML format.

You can’t store structured data directly in the INI file.

–Michael

---

<div class="post-metadata">

**Author:** ![Chris\_Shenton](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@Chris\_Shenton](https://forum.ansible.com/u/Chris_Shenton)\
**Post date:** [September 20, 2013, 5:06am UTC](https://forum.ansible.com/t/host-variables-with-dict-value/13509/3 "2013-09-20T05:06:25Z")

</div>

Looks good, thanks for the pointer, Michael.
