Variables in Playbooks

Hello,

I have a couple of questions about variables in playbooks.

  1. Is there a way to get to ansible variables in a playbook? Trying to get to the IPv4 address, neither {{ ansible_eth0.ipv4.address }} nor $ansible_eth0.ipv4.address work. The {{}} syntax yields the MAC address. The $ syntax gets passed through to the command unchanged (did not match anything at all).
  2. StuddlyCaps don’t seem to work but I don’t see anything in the vars section of the docs about acceptable variable names. E.g., I can use “customer_email” but not “customerEmail”. The latter gets passed through to the command as $customerEmail instead of having the value substituted.

Thanks,
– Art Z.

Which version of Ansible?

Hi Art,

Is there a way to get to ansible variables in a playbook? Trying to get to
the IPv4 address, neither {{ ansible_eth0.ipv4.address }} nor
$ansible_eth0.ipv4.address work. The {{}} syntax yields the MAC address. The
$ syntax gets passed through to the command unchanged (did not match
anything at all).

The correct syntax is:
'''
  tasks:
  - action: shell echo ${ansible_eth0.ipv4.address}
'''

That example works all right for me on devel.

StuddlyCaps don't seem to work but I don't see anything in the vars section
of the docs about acceptable variable names. E.g., I can use
"customer_email" but not "customerEmail". The latter gets passed through to
the command as $customerEmail instead of having the value substituted.

There is an explicit .lower() on the variable name. It was there in
the original commit. Do you know why, Michael or Seth?
https://github.com/ansible/ansible/commit/5ed2b894d9344ae10ecea37f1376dae00b3d15e3

Greetings,

Jeroen

Michael: devel, pulled yesterday morning (sorry for forgetting to mention it)

Jeroen: thanks. I’ll use that syntax.

– Art Z.

Yes, there was an email about not calling Jinja2 everywhere I think yesterday.

{{ }} etc

It’s only valid in templates now.

There is an explicit .lower() on the variable name. It was there in
the original commit. Do you know why, Michael or Seth?
https://github.com/ansible/ansible/commit/5ed2b894d9344ae10ecea37f1376dae00b3d15e3

I’m fine with removing it, I bet it came over from the yum function.

I don’t think we need it.