diff --git a/docs/docsite/rst/reference_appendices/faq.rst b/docs/docsite/rst/reference_appendices/faq.rst index 33f309d1b25..2358db1d668 100644 --- a/docs/docsite/rst/reference_appendices/faq.rst +++ b/docs/docsite/rst/reference_appendices/faq.rst @@ -379,9 +379,15 @@ via a role parameter or other input. Variable names can be built by adding stri {{ hostvars[inventory_hostname]['ansible_' + which_interface]['ipv4']['address'] }} -The trick about going through hostvars is necessary because it's a dictionary of the entire namespace of variables. 'inventory_hostname' +The trick about going through hostvars is necessary because it's a dictionary of the entire namespace of variables. ``inventory_hostname`` is a magic variable that indicates the current host you are looping over in the host loop. +In the example above, if your interface names have dashes, you must replace them with underscores: + +.. code-block:: jinja + + {{ hostvars[inventory_hostname]['ansible_' + which_interface | replace('_', '-') ]['ipv4']['address'] }} + Also see dynamic_variables_.