Inventory Plugins
Inventory plugins allow users to point at data sources to compile the inventory of hosts that Ansible uses to target tasks, either via the -i /path/to/file
and/or -i 'host1, host2
command line parameters or from other configuration sources.
Enabling Inventory Plugins
Most inventory plugins shipped with Ansible are disabled by default and need to be whitelisted in your ansible.cfg file in order to function. This is how the default whitelist looks in the config file that ships with Ansible:
[inventory] enable_plugins = host_list, script, yaml, ini, auto
This list also establishes the order in which each plugin tries to parse an inventory source. Any plugins left out of the list will not be considered, so you can ‘optimize’ your inventory loading by minimizing it to what you actually use. For example:
[inventory] enable_plugins = advanced_host_list, constructed, yaml
Using Inventory Plugins
The only requirement for using an inventory plugin after it is enabled is to provide an inventory source to parse. Ansible will try to use the list of enabled inventory plugins, in order, against each inventory source provided. Once an inventory plugin succeeds at parsing a source, the any remaining inventory plugins will be skipped for that source.
Plugin List
You can use ansible-doc -t inventory -l
to see the list of available plugins. Use ansible-doc -t inventory <plugin name>
to see plugin-specific documentation and examples.
- advanced_host_list - Parses a ‘host list’ with ranges
- auto - Loads and executes an inventory plugin specified in a YAML config
- aws_ec2 - ec2 inventory source
- constructed - Uses Jinja2 to construct vars and groups based on existing inventory.
- host_list - Parses a ‘host list’ string
- ini - Uses an Ansible INI file as inventory source.
- k8s - Kubernetes (K8s) inventory source
- openshift - OpenShift inventory source
- openstack - OpenStack inventory source
- script - Executes an inventory script that returns JSON
- virtualbox - virtualbox inventory source
- yaml - Uses a specifically YAML file as inventory source.
See also
- About Playbooks
- An introduction to playbooks
- Callback Plugins
- Ansible callback plugins
- Connection Plugins
- Ansible connection plugins
- Filters
- Jinja2 filter plugins
- Tests
- Jinja2 test plugins
- Lookups
- Jinja2 lookup plugins
- Vars Plugins
- Ansible vars plugins
- User Mailing List
- Have a question? Stop by the google group!
- irc.freenode.net
- #ansible IRC chat channel
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.5/plugins/inventory.html