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

707 views
Skip to first unread message

i iordanov

unread,
Mar 1, 2014, 7:13:01 PM3/1/14
to ansible...@googlegroups.com
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

David Karban

unread,
Mar 2, 2014, 2:16:21 AM3/2/14
to ansible...@googlegroups.com
Hi,

which version of ansible are you using?

David


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0a616444-1a15-451d-8543-5b8afce56ec2%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
David Karban
Specialista na správu linuxových serverů
www.karban.eu

i iordanov

unread,
Mar 2, 2014, 2:28:41 PM3/2/14
to ansible...@googlegroups.com
Hi David,

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

Thanks!
iordan
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/-voEAQDGNzI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAOBFM96p%3D4CaMpsQQAcfO7%2B2sSPzhUrYKtvEfie77e_F-hQh1A%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/groups/opt_out.



--
The conscious mind has only one thread of execution.

Michael DeHaan

unread,
Mar 2, 2014, 2:36:59 PM3/2/14
to ansible...@googlegroups.com
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
--

i iordanov

unread,
Mar 2, 2014, 2:48:51 PM3/2/14
to ansible...@googlegroups.com
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:

---
- hosts: ec2hosts
gather_facts: True
connection: local
vars:
ec2_access_key: --DELETED--
ec2_secret_key: --DELETED--
region: "us-east-1"
tasks:
- name: destroy all instances
ec2: state='absent'
aws_access_key={{ ec2_access_key }}
aws_secret_key={{ ec2_secret_key }}
region={{ region }}
instance_ids=${instance-id}
wait=true

3) If I change the line that contains ${ansible_ec2_instance-id} above to:

instance_ids={{ instance-id }}

I get this error:

TASK: [destroy all instances] *************************************************
fatal: [10.130.0.123] => unable to look up a name or access an
attribute in template string

FATAL: all hosts have already failed -- aborting


Thank you very much!
iordan
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/-voEAQDGNzI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/-3900642294177465073%40unknownmsgid.
>
> For more options, visit https://groups.google.com/groups/opt_out.



Petros Moisiadis

unread,
Mar 2, 2014, 5:01:50 PM3/2/14
to ansible...@googlegroups.com

For more options, visit https://groups.google.com/groups/opt_out.

'instance-id' seems to be an invalid identifier for jinja because of the dash ('-') character.
Take a look at: http://jinja.pocoo.org/docs/api/#identifier-naming

Try to rename your variable to 'instance_id' (replace dash '-' with underscore '_').

Michael DeHaan

unread,
Mar 2, 2014, 5:08:46 PM3/2/14
to ansible...@googlegroups.com
Yep, that would be it, good catch :)




i iordanov

unread,
Mar 2, 2014, 5:19:41 PM3/2/14
to ansible...@googlegroups.com
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
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/-voEAQDGNzI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAEVJ8QOvXAZ3X5z7exLmHydXFcaJ__HVH9nGATzsC-TvonnDxA%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/groups/opt_out.



--
Reply all
Reply to author
Forward
0 new messages