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.

Parameters
  • 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_data()

Get the base/all data attached to this inventory.

get_deploy_data()

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_group_data(group)

Get data for a single group in this inventory.

get_groups_data(groups)

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_host_data(hostname)

Get data for a single host in this inventory.

get_override_data()

Get override data for this inventory.

iter_all_hosts()

Iterates over all inventory hosts, active or not.

len_all_hosts()

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

make_hosts_and_groups(names, groups)
state = None
pyinfra.api.inventory.extract_name_data(names)