# accessing a variable declared for host with {{ }} does not work

**URL:** <https://forum.ansible.com/t/accessing-a-variable-declared-for-host-with-does-not-work/14681>\
**Category:** Ansible Project\
**Created:** [March 2, 2014, 12:13am UTC](https://forum.ansible.com/t/accessing-a-variable-declared-for-host-with-does-not-work/14681 "2014-03-02T00:13:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![i\_iordanov](https://avatars.discourse-cdn.com/v4/letter/i/b3f665/32.png) [@i\_iordanov](https://forum.ansible.com/u/i_iordanov)\
**Post date:** [March 2, 2014, 12:13am UTC](https://forum.ansible.com/t/accessing-a-variable-declared-for-host-with-does-not-work/14681/1 "2014-03-02T00:13:01Z")

</div>

Hey guys,

If I have the following in an inventory file:

[somehostgroup]  
somehost somevariable=1234

I can access the variable with:  
${somevariable}

But I cannot access the variable with:  
{{ somevariable }}

as I would expect. Is this expected?

Many thanks!  
iordan

---

<div class="post-metadata">

**Author:** ![David\_Karban](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@David\_Karban](https://forum.ansible.com/u/David_Karban)\
**Post date:** [March 2, 2014, 7:16am UTC](https://forum.ansible.com/t/accessing-a-variable-declared-for-host-with-does-not-work/14681/2 "2014-03-02T07:16:21Z")

</div>

Hi,

which version of ansible are you using?

David

---

<div class="post-metadata">

**Author:** ![i\_iordanov](https://avatars.discourse-cdn.com/v4/letter/i/b3f665/32.png) [@i\_iordanov](https://forum.ansible.com/u/i_iordanov)\
**Post date:** [March 2, 2014, 7:28pm UTC](https://forum.ansible.com/t/accessing-a-variable-declared-for-host-with-does-not-work/14681/3 "2014-03-02T19:28:41Z")

</div>

Hi David,

I'm using a package built from the devel branch a couple of days ago.  
I.e. cutting edge.

Thanks!  
iordan

---

<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:** [March 2, 2014, 7:36pm UTC](https://forum.ansible.com/t/accessing-a-variable-declared-for-host-with-does-not-work/14681/4 "2014-03-02T19:36:59Z")

</div>

This should be impossible as there is no legacy variable support on devel, and it’s a pretty basic declaration.

Can we see the task, template, output, etc?

– Michael

---

<div class="post-metadata">

**Author:** ![i\_iordanov](https://avatars.discourse-cdn.com/v4/letter/i/b3f665/32.png) [@i\_iordanov](https://forum.ansible.com/u/i_iordanov)\
**Post date:** [March 2, 2014, 7:48pm UTC](https://forum.ansible.com/t/accessing-a-variable-declared-for-host-with-does-not-work/14681/5 "2014-03-02T19:48:51Z")

</div>

1) My inventory file:

[ec2hosts]  
10.130.0.123 instance-id=i-01234567

2) My yaml file, delete-instance.yml that \*works\*, adapted from an  
ansible example:

---

<div class="post-metadata">

**Author:** ![Ernest0x](https://avatars.discourse-cdn.com/v4/letter/e/ed655f/32.png) [@Ernest0x](https://forum.ansible.com/u/Ernest0x)\
**Post date:** [March 2, 2014, 10:01pm UTC](https://forum.ansible.com/t/accessing-a-variable-declared-for-host-with-does-not-work/14681/6 "2014-03-02T22:01:50Z")

</div>

‘instance-id’ seems to be an invalid identifier for jinja because of the dash (‘-’) character. Take a look at: Try to rename your variable to ‘instance\_id’ (replace dash ‘-’ with underscore ‘\_’).

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 2, 2014, 10:08pm UTC](https://forum.ansible.com/t/accessing-a-variable-declared-for-host-with-does-not-work/14681/7 "2014-03-02T22:08:46Z")

</div>

Yep, that would be it, good catch 🙂

---

<div class="post-metadata">

**Author:** ![i\_iordanov](https://avatars.discourse-cdn.com/v4/letter/i/b3f665/32.png) [@i\_iordanov](https://forum.ansible.com/u/i_iordanov)\
**Post date:** [March 2, 2014, 10:19pm UTC](https://forum.ansible.com/t/accessing-a-variable-declared-for-host-with-does-not-work/14681/8 "2014-03-02T22:19:41Z")

</div>

Hey,

Indeed, that does seem to be the case, thanks!

The not-so-important question of why it still worked with $() even  
though that support shouldn't be there, but I'm not concerned.

Many thanks!  
iordan
