So I'm trying to combine magic variables and jinja. Unfortnately I'm running into issues. So This is the jinja script
{% for host in groups['all'] %}
{{ hostvars[host]['ansible_facts']['devices']['sda']['partitions']['sda1']['size'] }}
{% endfor %}
I run into this error
"AnsibleUndefinedVariable: 'dict object' has no attribute 'devices'" }
This works when I target a group with one managed host but not one with multiple managedhosts. I have tried with hostvars['host'] and no luck...
Thank you all the issue came to be I needed to use ansible_devices instead of devices. I appreciate all the help!
I could be wrong but I believe that values nested at the second level and more cannot be accessed directly.
That is, you can invoke the top-level values (such as the hostname, the inventory name, etc.) but only the setup module can access the values that it returns.
You can also double check to make sure that devices is in the ansible_facts hash
Hello,
add a new first play to your playbook where you gather the facts of the hosts which you need or use a fact cache.
Greetings
Andreas
Thank you all the issue came to be I needed to use ansible_devices instead of devices. I appreciate all the help!
Glad to hear that you solved the issue @dennishart
I like to work with JSON clients - my favorite on Mac is "Jayson" - I then use the debug module and browse the output to make sure I can access a value in a hash.
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.