# How to reference variables

**URL:** <https://forum.ansible.com/t/how-to-reference-variables/11626>\
**Category:** Ansible Project\
**Created:** [June 27, 2012, 4:45pm UTC](https://forum.ansible.com/t/how-to-reference-variables/11626 "2012-06-27T16:45:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Feger](https://avatars.discourse-cdn.com/v4/letter/n/c0e974/32.png) [@Nathan\_Feger](https://forum.ansible.com/u/Nathan_Feger)\
**Post date:** [June 27, 2012, 4:45pm UTC](https://forum.ansible.com/t/how-to-reference-variables/11626/1 "2012-06-27T16:45:15Z")

</div>

If I have a yml vars file with:

category:  
stuff: a  
otherstuff: bar  
cat2:

- subcat1: true
- subcat2: false

How do I reference these variables in a playbook?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [June 27, 2012, 4:51pm UTC](https://forum.ansible.com/t/how-to-reference-variables/11626/2 "2012-06-27T16:51:43Z")

</div>

in 0.4 and onward:

${category.otherstuff}

or using Jinja2 syntax, allowed in playbooks in 0.3 and back in 0.5 and onward, and has always been allowed in templates:

{{ category[“otherstuff”] }}

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 5, 2012, 12:28pm UTC](https://forum.ansible.com/t/how-to-reference-variables/11626/3 "2012-07-05T12:28:48Z")

</div>

Try --extra-vars="user=foo".

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 5, 2012, 12:34pm UTC](https://forum.ansible.com/t/how-to-reference-variables/11626/4 "2012-07-05T12:34:31Z")

</div>

Also set:

user: $user

in the playbook
