pyinfra.api.inventory module

class pyinfra.api.inventory.Inventory(names_data, ssh_user=None, ssh_port=None, ssh_key=None, ssh_key_password=None, ssh_password=None, winrm_username=None, winrm_password=None, winrm_port=None, **groups)

Bases: object

Represents a collection of target hosts. Stores and provides access to group data, host data and default data for these hosts.

  • names_data – tuple of (names, data)
  • ssh_user – override SSH user
  • ssh_port – override SSH port
  • ssh_key – override SSH key filename
  • ssh_key_password – override password for the SSH key
  • ssh_password – override SSH password
  • winrm_username – override WINRM username
  • winrm_password – override WINRM pasword
  • winrm_port – override WINRM port
  • **groups – map of group names -> (names, data)

Get the base/all data attached to this inventory.


Gets any default data attached to the current deploy, if any.

get_group(name, default=<class 'pyinfra.api.exceptions.NoGroupError'>)

Get a list of hosts belonging to a group.


Get data for a single group in this inventory.


Gets aggregated data from a list of groups. Vars are collected in order so, for any groups which define the same var twice, the last group’s value will hold.

get_host(name, default=<class 'pyinfra.api.exceptions.NoHostError'>)

Get a single host by name.


Get data for a single host in this inventory.


Get override data for this inventory.


Iterates over all inventory hosts, active or not.


Returns the number of hosts in the inventory, active or not.

make_hosts_and_groups(names, groups)
state = None