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

Doc interplay between host_vars and group_vars dirs and inventory dirs #2386

Open
wants to merge 5 commits into
base: devel
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/docsite/rst/inventory_guide/intro_inventory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ You can target this inventory directory as follows:

You can also configure the inventory directory in your ``ansible.cfg`` file. See :ref:`intro_configuration` for more details.

Inventory files are also read from the sub-directories of a specified
inventory directory, but sub-directories are not searched for
``host_vars`` or ``group_vars`` :ref:`directories
<splitting_out_vars>`. Sub-directories with these names are ignored.

Copy link
Member

@bcoca bcoca Feb 12, 2025

Choose a reason for hiding this comment

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

This is partially incorrect and due to not distinguishing what inventory sources are from what vars plugins provide.

All vars plugins (host_group_vars vars plugin governs the inclusion of host_vars/group_vars dirs) use the 'inventory source' as a base, when that is a directory the multiple files/subdirs do not count as independent inventory sources, just the original directory does.

Those directories (and vars_plugins and others from configuration INVENTORY_IGNORE_PATTERNS and INVENTORY_IGNORE_EXTS) are ignored if present, if not they would not have the same function you seem to expect. They would be processed at as part of an inventory source and they are probed as containing inventory files, but not vars files, which would end up either with warnings, errors or worse, creating unexpected hosts and groups depending on enabled inventory plugins.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your review. I've pushed a patch in response.

The new docs do not include mention of INVENTORY_IGNORE_PATTERS, etc. That seems overkill here.

Copy link
Author

Choose a reason for hiding this comment

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

I added links to the ignore config settings, just to be through. Hopefully this is not confusing.

Copy link
Member

Choose a reason for hiding this comment

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

I found so many things that needed updating in this page that i ended up creating my own PR #2416

Managing inventory load order
-----------------------------

Expand Down Expand Up @@ -494,6 +499,14 @@ For example, if you group hosts in your inventory by datacenter, and each datace
ntp_server: acme.example.org
database_server: storage.example.org

When inventory is :ref:`assembled from a directory
<inventory_directory>`, variables declared in ``host_vars`` or
``group_vars`` directories are only seen when these directories are in
a specified inventory directory. Although sub-directories of
specified inventory directories are searched for inventory files,
having ``host_vars`` or ``group_vars`` directories in the same
directory as an inventory file is not sufficient.

You can also create *directories* named after your groups or hosts. Ansible will read all the files in these directories in lexicographical order. An example with the 'raleigh' group:

.. code-block:: bash
Expand Down