ansible.builtin.inventory_hostnames – list of inventory hosts matching a host pattern

Note

This module is part of ansible-core and included in all Ansible installations. In most cases, you can use the short module name inventory_hostnames even without specifying the collections: keyword. However, we recommend you use the FQCN for easy linking to the module documentation and to avoid conflicting with other collections that may have the same module name.

New in version 1.3: of ansible.builtin

Synopsis

  • This lookup understands ‘host patterns’ as used by the hosts: keyword in plays and can return a list of matching hosts from inventory

Notes

Note

  • this is only worth for ‘hostname patterns’ it is easier to loop over the group/group_names variables otherwise.

Examples

- name: show all the hosts matching the pattern, i.e. all but the group www
  debug:
    msg: "{{ item }}"
  with_inventory_hostnames:
    - all:!www

Return Values

Common return values are documented here, the following are the fields unique to this lookup:

Key Returned Description
_hostnames
list / elements=string
success
list of hostnames that matched the host pattern in inventory



Authors