Add a documentation on how to loop over all inventory host

Related to #13343
This commit is contained in:
Michael Scherer 2015-12-02 00:21:10 +01:00
parent f873cc0fb5
commit 517b533d46

View file

@ -516,6 +516,34 @@ Subsequent loops over the registered variable to inspect the results may look li
.. _looping_over_the_inventory:
Looping over the inventory
``````````````````````````
If you wish to loop over the inventory, or just a subset of it, there is multiple ways.
One can use a regular ``with_items`` with the ``play_hosts`` or ``groups`` variables, like this::
# show all the hosts in the inventory
- debug: msg={{ item }}
with_items: "{{groups['all']}}"
# show all the hosts in the current play
- debug: msg={{ item }}
with_items: play_hosts
There is also a specific lookup plugin ``inventory_hostname`` that can be used like this::
# show all the hosts in the inventory
- debug: msg={{ item }}
with_inventory_hostname: all
# show all the hosts matching the pattern, ie all but the group www
- debug: msg={{ item }}
with_inventory_hostname: all:!www
More information on the patterns can be found on :doc:`intro_patterns`
.. _loops_and_includes:
Loops and Includes