Referencing host variables under the new List of Dicts schema #3024
-
Hi. I am trying to reference some host variables in a Jinja2 template. but am unsure of the correct/optimal way of doing it. In a multi DC config, I have the node types l2leaf, l3leaf and spine for each DC. For example a l3leaf pair in one:
Using the Ansible debugger I can see I can't just reference the
I need to search all lists and return just that hosts entry wherever it is. but I don't know what node_group the hosts parent is, I would need to iterate all groups and work out if the host was a member of the ones in this list. I could then get the groups list of nodes. For each host, I would need to iterate the node_types, each node_groups and nodes, to work out where the information is. To jump through those hoops every time seems like a lot of work and inefficient, so I am guessing/hoping that there is a more elegant way to do this that I am unaware of. If someone can please enlighten me, I would be very grateful. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hi Rich, if you are running this as part of an AVD playbook, you can leverage some of our internal {{ hostvars.lyonwan1a.switch.mgmt_ip }} should have what you need here. You can find other vars here, but again your mileage may vary. Let us know which ones you need, so we can try to cover it. Also it would be good to know what you need them for, so we can provide a native feature instead. |
Beta Was this translation helpful? Give feedback.
-
Hi Claus. Thanks for the swift response. I knew there would be an easier way. In the current case I am extending the That page you linked is a wealth of information I hadn't yet discovered, so thanks for that. |
Beta Was this translation helpful? Give feedback.
-
It looks like I can run:
at the beginning of my DHCP provisioning playbook, and then just reference the list of devices in the var |
Beta Was this translation helpful? Give feedback.
Hi Rich, if you are running this as part of an AVD playbook, you can leverage some of our internal
switch.*
facts, but please note that these are subject to change without notice! We are working on defining a set of stable facts you can use for this in the future.should have what you need here.
You can find other vars here, but again your mileage may vary. Let us know which ones you need, so we can try to cover it. Also it would be good to know what you need them for, so we can provide a native feature instead.