I want to pass a huge nested dictionary as an extra_vars to an Ansible playbook. I want to use values from that dictionary in my playbook.
sample_dict = { 'student' : {'name' : 'coder', 'marks' : 100} }
I want to pass this dictionary as an extra_var I want to use the values from it. I am not able to access separate values from the dictionary using jinja templating.
Example:
If I want to use the value of marks in an ansible-playbook, how do I access it?
I am using python3.5 and ansible 2.8. I am using ansible-runner module to run the playbooks.
You can walk dictionaries in
jinjain two ways:json_queryfilterThe first one uses brackets
[]to travel through the dictionary. And,json_querytakes in a string with the path to key you want to read.Check this
playbookexample:Each task uses a different method to access the same variable.
I hope it helps.