Inventories
An inventory is either an inventory module file like inventory.py
, or an ad-hoc url like example.com
or root@localhost
. Usually an inventory is defined as a module.
All special attributes that can be defined by an inventory are documented in InventoryWrapper
. For all means and purposes, you can regard your inventory module as an "instance" of this wrapper class. You can override the documented attributes and functions to modify it to your needs.
The two main inventory attributes are hosts
and groups
which are used to declare the hosts and groups that belong to the inventory.
Declaring hosts
Hosts are declared by defining the hosts
variable.
Hosts can be declared by just specifying the connection url. If this url is given without an connection schema, ssh://
will be used as the default.
Declaring groups
Groups are declared by defining the groups
variable. If you omit this definition, a list of groups is automatically gathered from the group names used in your hosts
.
Inspecting an inventory
To see whether your inventory behaves as expected, you can use
This will show a summary of all declared hosts and groups. For each host, it additionally lists the origin and effective value of all defined variables.
Setting global variables from the inventory
Especially when managing several inventories (for example staging and production), you may want to set global variables (like API keys) from your inventory definition. You can do this simply by defining a global variable or method that isn't a special inventory variable. To keep variables private to your inventory, use a leading underscore like _variable
.
Overwriting other behavior
You may overwrite any public method defined in the InventoryWrapper
to further customize the behavior of the inventory.
Last updated