Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some inventory plugin documentation #44727

Merged
merged 4 commits into from
Aug 30, 2018

Conversation

s-hertel
Copy link
Contributor

SUMMARY

Add some additional documentation about getting inventory plugins working for those moving from a script.

ISSUE TYPE
  • Docs Pull Request
COMPONENT NAME

docs/docsite/rst/plugins/inventory.rst

ANSIBLE VERSION
ansible 2.7.0.dev0

@s-hertel s-hertel requested review from bcoca and acozine August 27, 2018 17:58
@ansibot
Copy link
Contributor

ansibot commented Aug 27, 2018

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 docs This issue/PR relates to or includes documentation. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Aug 27, 2018
@s-hertel s-hertel removed the needs_triage Needs a first human triage before being processed. label Aug 27, 2018
@s-hertel s-hertel force-pushed the add_more_inventory_docs branch 3 times, most recently from ff27944 to 5dd5363 Compare August 27, 2018 18:20
@s-hertel s-hertel requested a review from samdoran August 27, 2018 18:24
@s-hertel s-hertel force-pushed the add_more_inventory_docs branch 3 times, most recently from e34186e to f4fcccf Compare August 27, 2018 18:41
@@ -39,6 +39,31 @@ The only requirement for using an inventory plugin after it is enabled is to pro
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.

To transition to using an inventory plugin with a YAML configuration source from an inventory script, first create a file with the accepted filename schema for the plugin in question (each plugin should document any naming restrictions). For example, the aws_ec2 inventory plugin takes a file in the format <user_given_name>.aws_ec2.<yml/yaml> and the openstack inventory plugin parses clouds.<yml/yaml> or openstack.<yml/yaml>. After creating the file add ``plugin: plugin_name`` (where plugin_name could be aws_ec2, for example) to the first line.

The 'auto' inventory plugin is enabled by default and works by using the first line of the configuration file to indicate the plugin that should attempt to parse it (which is aws_ec2 here). The whitelist is also configurable. After the plugin is enabled and any required options or credentials have been provided, the output of ``ansible-inventory -i demo.aws_ec2.yml --graph`` should be populated. To make a YAML configuration file accessible by default without specifying ``-i`` you can set the default inventory path (via ``inventory`` in the ansible.cfg [defaults] section or the :envvar:`ANSIBLE_HOSTS` environment variable) to your inventory source(s). Now running ``ansible-inventory --graph`` should yield the same output as when you passed your YAML configuration source(s) directly. Custom inventory plugins and the documentation required to parse sources may also be added in your plugin path to be used in the same way.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't need to be the first line, since yaml reads the whole doc anyways it just needs to be th plugin: field

The 'auto' inventory plugin is enabled by default and works by using the first line of the configuration file to indicate the plugin that should attempt to parse it (which is aws_ec2 here). The whitelist is also configurable. After the plugin is enabled and any required options or credentials have been provided, the output of ``ansible-inventory -i demo.aws_ec2.yml --graph`` should be populated. To make a YAML configuration file accessible by default without specifying ``-i`` you can set the default inventory path (via ``inventory`` in the ansible.cfg [defaults] section or the :envvar:`ANSIBLE_HOSTS` environment variable) to your inventory source(s). Now running ``ansible-inventory --graph`` should yield the same output as when you passed your YAML configuration source(s) directly. Custom inventory plugins and the documentation required to parse sources may also be added in your plugin path to be used in the same way.

The inventory source you provide may be a directory of inventory configuration files. The constructed inventory plugin only operates on those hosts already in inventory, so you may want the constructed inventory configuration parsed at a particular point (such as last). The directory is parsed recursively alphabetically and is not configurable so things should be named accordingly for it to work predictably with constructed. If an inventory plugin you are using supports constructed itself you can work around this by adding your constructed groups to those inventory plugin configuration files (as now it will not use constructed until it has added your hosts from that source). You may also want to reorder the precedence of which plugin attempts to parse a source first using the using the ansible.cfg ['inventory'] `enable_plugins` list.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you an also use command line to impose order with multiple -i source as they are processed in that order

Copy link
Contributor

@acozine acozine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for extending and improving the documentation on inventory plugins.

@s-hertel s-hertel merged commit 33e9d67 into ansible:devel Aug 30, 2018
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 docs This issue/PR relates to or includes documentation. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants