Programmatic access to variables defined inside a role not working

174 views
Skip to first unread message

edroz...@gmail.com

unread,
May 1, 2014, 1:31:13 PM5/1/14
to ansible...@googlegroups.com
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

edroz...@gmail.com

unread,
May 1, 2014, 1:47:36 PM5/1/14
to ansible...@googlegroups.com
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
==========
fatal: [work1] => One or more undefined variables: 'dict object' has no attribute 'alpine_sb_url'

FATAL: all hosts have already failed -- aborting


Ansible 1.6 GIT as of May 1, 2014
==========================
failed: [work1] => {"changed": true, "cmd": ["rsync", "-r", "{{slack_url}}/source/n/alpine/", "/usr/local/src/alpine"], "delta": "0:00:00.127109", "end": "2014-05-01 10:39:18.996855", "item": "", "rc": 23, "start": "2014-05-01 10:39:18.869746"}
stderr: rsync: change_dir "/root//{{slack_url}}/source/n/alpine" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1165) [sender=3.1.0]

FATAL: all hosts have already failed -- aborting

--------------

Michael DeHaan

unread,
May 1, 2014, 5:29:59 PM5/1/14
to ansible...@googlegroups.com

Does your task have an explicit name in the playbook?

(Can we see the playbook?)





--
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/04d3669e-450a-4063-badf-f196dee9adbe%40googlegroups.com.

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

Reply all
Reply to author
Forward
0 new messages