Hello,
I need to programmatically access variables defined with a role ( via myrole/vars/main.yaml)
I tried using the trick described in the Ansible FAQ - {{ hostvars[ inventory_hostname ][ myvar ] }} but it appears variables defined within the role are not included in this hostvars namespace.
Would love to figure out a way to access my role variables programmatically.
Thanks in advance,
–Ed
I noticed there is a difference in how Ansible 1.5.5 handles this vs. Ansible 1.6 Git May 1, 2014.
Ansible 1.6 Git is now including role variables in the hostvars scope. I have one remaining issue
in 1.6 which is if the variable being referenced itself references another variable, the ultimate value
is not being properly assembled.
slack_mir: ‘rsync://slackware.cs.utah.edu’
slack_dir: ‘slackware/slackware64-{{ slack_ver }}’
slack_url: ‘{{ slack_mir }}/{{ slack_dir }}’
alpine_sb_url: ‘{{ slack_url }}/source/n/alpine’
pkg: ‘alpine’
When I reference as below, the final variable is not being properly assembled
as seen in the Ansible 1.6 error message below.
{{ hostvars[inventory_hostname][pkg + ‘_sb_url’] }}
Ansible 1.5.5
Does your task have an explicit name in the playbook?
(Can we see the playbook?)