Pr 72292- Add context to inventory plugins (#78070)

* Add context to inventory plugins documentation

* Show how to add the inventory plugin to the `enable_plugins` configuration item - not just replace it.
* Show adding tags to `keyed_groups` without specifying the separator.
* Show adding more complex `groups` and `compose` statements, including using the ternary filter.
* As I added an additional group, I've updated the resulting `ansible-inventory` output accordingly.
pull/78183/head
Sandra McCann 4 years ago committed by GitHub
parent b56d73796e
commit a77fc2e822
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -23,13 +23,20 @@ In some circumstances, for example, if the inventory plugin does not use a YAML
[inventory]
enable_plugins = host_list, script, auto, yaml, ini, toml
If the plugin is in a collection, use the fully qualified name:
If the plugin is in a collection and is not being picked up by the `auto` statement, you can append the fully qualified name:
.. code-block:: ini
[inventory]
enable_plugins = namespace.collection_name.inventory_plugin_name
enable_plugins = host_list, script, auto, yaml, ini, toml, namespace.collection_name.inventory_plugin_name
Or, if it is a local plugin, perhaps stored in the path set by :ref:`DEFAULT_INVENTORY_PLUGIN_PATH`, you could reference it as follows:
.. code-block:: ini
[inventory]
enable_plugins = host_list, script, auto, yaml, ini, toml, my_plugin
If you use a plugin that supports a YAML configuration source, make sure that the name matches the name provided in the ``plugin`` entry of the inventory source file.
.. _using_inventory:
@ -80,12 +87,24 @@ You can create dynamic groups using host variables with the constructed ``keyed_
- key: tags.Name
prefix: tag_Name_
separator: ""
# If you have a tag called "Role" which has the value "Webserver", this will add the group
# role_Webserver and add any hosts that have that tag assigned to it.
- key: tags.Role
prefix: role
groups:
# add hosts to the group development if any of the dictionary's keys or values is the word 'devel'
development: "'devel' in (tags|list)"
# add hosts to the "private_only" group if the host doesn't have a public IP associated to it
private_only: "public_ip_address is not defined"
compose:
# set the ansible_host variable to connect with the private IP address without changing the hostname
ansible_host: private_ip_address
# use a private address where a public one isn't assigned
ansible_host: public_ip_address is defined | ternary(public_ip_address, private_ip_address)
# alternatively, set the ansible_host variable to connect with the private IP address without changing the hostname
# ansible_host: private_ip_address
# if you *must* set a string here (perhaps to identify the inventory source if you have multiple
# accounts you want to use as sources), you need to wrap this in two sets of quotes, either ' then "
# or " then '
some_inventory_wide_string: '"Yes, you need both types of quotes here"'
Now the output of ``ansible-inventory -i demo.aws_ec2.yml --graph``:
@ -99,6 +118,8 @@ Now the output of ``ansible-inventory -i demo.aws_ec2.yml --graph``:
|--@development:
| |--ec2-12-345-678-901.compute-1.amazonaws.com
| |--ec2-98-765-432-10.compute-1.amazonaws.com
|--@role_Webserver
| |--ec2-12-345-678-901.compute-1.amazonaws.com
|--@tag_Name_ECS_Instance:
| |--ec2-98-765-432-10.compute-1.amazonaws.com
|--@tag_Name_Test_Server:

Loading…
Cancel
Save