Highlighted
Mission Specialist
Mission Specialist
  • 1,300 Views

Issues with an jinja and magic variables script please help

Jump to solution

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...

Labels (1)
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Mission Specialist
Mission Specialist
  • 1,273 Views

Re: Issues with an jinja and magic variables script please help

Jump to solution

Thank you all the issue came to be I needed to use ansible_devices instead of devices. I appreciate all the help!

View solution in original post

Reply
Loading...
4 Replies
Highlighted
Flight Engineer Flight Engineer
Flight Engineer
  • 1,289 Views

Re: Issues with an jinja and magic variables script please help

Jump to solution

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

Reply
Loading...
Highlighted
Flight Engineer Flight Engineer
Flight Engineer
  • 1,276 Views

Re: Issues with an jinja and magic variables script please help

Jump to solution

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

Reply
Loading...
Highlighted
Mission Specialist
Mission Specialist
  • 1,274 Views

Re: Issues with an jinja and magic variables script please help

Jump to solution

Thank you all the issue came to be I needed to use ansible_devices instead of devices. I appreciate all the help!

View solution in original post

Reply
Loading...
Highlighted
Flight Engineer Flight Engineer
Flight Engineer
  • 1,264 Views

Re: Issues with an jinja and magic variables script please help

Jump to solution

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.

0 Kudos
Reply
Loading...
Join the discussion
You must log in to join this conversation.