Skip to content

inventory: update the default ignored extensions for inventory directories - #4077

Open
fjvbn2003 wants to merge 2 commits into
ansible:develfrom
fjvbn2003:inventory-ignore-extensions
Open

fjvbn2003 wants to merge 2 commits into
ansible:develfrom
fjvbn2003:inventory-ignore-extensions

Conversation

@fjvbn2003

Copy link
Copy Markdown
SUMMARY

The "Using inventory directories and multiple inventory sources" section of the dynamic inventory guide lists the file extensions that Ansible ignores in an inventory directory:

~, .orig, .bak, .ini, .cfg, .retry, .pyc, .pyo

This list is out of date:

  • ansible-core 2.19 removed .ini from the default INVENTORY_IGNORE_EXTS (changelog: "INVENTORY_IGNORE_EXTS config, removed ini from the default list ..."). The default in lib/ansible/config/base.yml is now REJECT_EXTS + ['.orig', '.cfg', '.retry'].
  • The list leaves out the other entries that come from REJECT_EXTS (.swp, .rpm, .md, .txt, .rst).

This PR:

  • replaces the list with the current default and links to the INVENTORY_IGNORE_EXTS entry in the configuration reference;
  • adds a note about the .ini change. Before 2.19, inventory/hosts.ini was skipped without any warning when the directory was passed with -i. Since 2.19 it is read, and a non-inventory .ini file in the directory (for example the configuration file of an inventory script) is now parsed and produces warnings. The note also says that setting inventory_ignore_extensions replaces the default list instead of adding to it.
ISSUE TYPE
  • Docs Pull Request
COMPONENT NAME

docs/docsite/rst/inventory_guide/intro_dynamic_inventory.rst

ADDITIONAL INFORMATION

I checked the behavior with ansible-core 2.16.3 (Ubuntu 24.04 package) and with ansible-core 2.21.5 (run from the v2.21.5 tag), Python 3.12, using the same directory:

inventory/
  hosts.ini   # [web] web1
  db          # [db] db1
  cache.yml   # cache group with cache1
# ansible-core 2.16.3
$ ansible-inventory -i inventory --graph
@all:
  |--@ungrouped:
  |--@cache:
  |  |--cache1
  |--@db:
  |  |--db1
$ ansible-config dump | grep INVENTORY_IGNORE_EXTS
INVENTORY_IGNORE_EXTS(default) = ('.pyc', '.pyo', '.swp', '.bak', '~', '.rpm', '.md', '.txt', '.rst', '.orig', '.ini', '.cfg', '.retry')

# ansible-core 2.21.5
$ ansible-inventory -i inventory --graph
@all:
  |--@ungrouped:
  |--@cache:
  |  |--cache1
  |--@db:
  |  |--db1
  |--@web:
  |  |--web1
$ ansible-config dump | grep INVENTORY_IGNORE_EXTS
INVENTORY_IGNORE_EXTS(default) = ['.pyc', '.pyo', '.swp', '.bak', '~', '.rpm', '.md', '.txt', '.rst', '.orig', '.cfg', '.retry']

With 2.16.3 the web group is missing and nothing is printed about hosts.ini.

An inventory script next to its own .ini configuration file (myinv.py + myinv.ini containing [myinv] and regions = us-east-1) is silent with 2.16.3. With 2.21.5 it prints Failed to parse inventory with 'ini' plugin ... Expected key=value host variable assignment, got: us-east-1 and Unable to parse .../myinv.ini as an inventory source, and adds an empty myinv group.

With ANSIBLE_INVENTORY_IGNORE=.ini on 2.21.5, hosts.ini is skipped but a notes.txt file in the same directory is parsed, so the setting replaces the default list. That is why the note says "the list above plus .ini".

I could not build the docs locally. The new :ref: target, INVENTORY_IGNORE_EXTS, is already used in intro_inventory.rst.

If you prefer, I can also add a short entry about this change to the ansible-core 2.19 porting guide, which does not mention it.

This change was drafted with AI assistance and reviewed by me.

🤖 Generated with Claude Code

…ories

ansible-core 2.19 removed .ini from the default INVENTORY_IGNORE_EXTS
list, but the "Using inventory directories and multiple inventory
sources" section still lists .ini as ignored. The list also misses the
other default entries (.swp, .rpm, .md, .txt, .rst).

Show the current default list, link to the configuration reference,
and add a note about the .ini change: older versions skip hosts.ini in
an inventory directory without a warning, newer versions parse it. The
note also says that setting inventory_ignore_extensions replaces the
default list.

Assisted-by: Claude Opus 5.5
Signed-off-by: YoungjuKim <[email protected]>
@ansible-documentation-bot ansible-documentation-bot Bot added the new_contributor This PR is the first contribution by a new community member. label Oct 16, 2026
@ansible-documentation-bot

Copy link
Copy Markdown
Contributor

Thanks for your Ansible docs contribution! We talk about Ansible documentation on Matrix at #docs:ansible.im if you ever want to join us and chat about the docs! We meet on Matrix every Tuesday. See the Ansible calendar for meeting details. We welcome additions to our weekly agenda items too. You can add the dawgs-meeting tag to a forum topic to bring it up at the next meeting.


~, .orig, .bak, .ini, .cfg, .retry, .pyc, .pyo
.pyc, .pyo, .swp, .bak, ~, .rpm, .md, .txt, .rst, .orig, .cfg, .retry

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
In an inventory directory, executable files are treated as dynamic inventory sources and most other files as static sources. Files which end with any of the extensions in the `reject_exts <https://github.com/ansible/ansible/blob/d33bedc48fdd933b5abd65a77c081876298e2f07/lib/ansible/constants.py#L63>`_ list, along with ``.orig``, ``.cfg``, and ``.retry`` are ignored.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, applied in 47aca39. The suggestion was attached to the blank line 137 only, so committing it from the UI would have kept the old sentence and the code block. I replaced lines 132-137 with your sentence instead. I made two small edits: a comma after .retry to close the "along with" clause, and REJECT_EXTS as the link text to match the constant name in constants.py. Pinning the commit makes sense, since the constant is on L62 on devel now.

.pyc, .pyo, .swp, .bak, ~, .rpm, .md, .txt, .rst, .orig, .cfg, .retry

You can replace this list with your own selection by configuring an ``inventory_ignore_extensions`` list in ``ansible.cfg``, or setting the :envvar:`ANSIBLE_INVENTORY_IGNORE` environment variable. The value in either case must be a comma-separated list of patterns, as shown above.
You can replace this list with your own selection by configuring an ``inventory_ignore_extensions`` list in ``ansible.cfg``, or setting the :envvar:`ANSIBLE_INVENTORY_IGNORE` environment variable. The value in either case must be a comma-separated list of patterns, as shown above. See :ref:`INVENTORY_IGNORE_EXTS` in the configuration reference.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
You can replace this list with your own selection by configuring an ``inventory_ignore_extensions`` list in ``ansible.cfg``, or setting the :envvar:`ANSIBLE_INVENTORY_IGNORE` environment variable. The value in either case must be a comma-separated list of patterns, as shown above. See :ref:`INVENTORY_IGNORE_EXTS` in the configuration reference.
You can replace this list with your own selection by configuring an ``inventory_ignore_extensions`` list in ``ansible.cfg``, or setting the :envvar:`ANSIBLE_INVENTORY_IGNORE` environment variable. The value in either case must be a comma-separated list of patterns. See :ref:`INVENTORY_IGNORE_EXTS` in the configuration reference.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Applied in 47aca39.


.. note::

Before ``ansible-core`` 2.19, ``.ini`` was also in the default list, so a file such as ``inventory/hosts.ini`` was skipped without a warning when you passed the directory with ``-i``. Starting with ``ansible-core`` 2.19, ``.ini`` files in an inventory directory are parsed as inventory sources. If the directory also holds ``.ini`` files that are not inventory, for example the configuration file of an inventory script, Ansible now tries to parse them as inventory, which can produce ``Unable to parse ... as an inventory source`` warnings. To skip them, set ``inventory_ignore_extensions`` to the list above plus ``.ini``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Before ``ansible-core`` 2.19, ``.ini`` was also in the default list, so a file such as ``inventory/hosts.ini`` was skipped without a warning when you passed the directory with ``-i``. Starting with ``ansible-core`` 2.19, ``.ini`` files in an inventory directory are parsed as inventory sources. If the directory also holds ``.ini`` files that are not inventory, for example the configuration file of an inventory script, Ansible now tries to parse them as inventory, which can produce ``Unable to parse ... as an inventory source`` warnings. To skip them, set ``inventory_ignore_extensions`` to the list above plus ``.ini``.
Before ``ansible-core`` 2.19, ``.ini`` was also in the default list, so a file such as ``inventory/hosts.ini`` was skipped without a warning when you passed the directory with ``-i``. Starting with ``ansible-core`` 2.19, ``.ini`` files in an inventory directory are parsed as inventory sources. If the directory also holds ``.ini`` files that are not inventory, for example the configuration file of an inventory script, Ansible now tries to parse them as inventory, which can produce ``Unable to parse ... as an inventory source`` warnings. To skip them, set ``inventory_ignore_extensions`` to the default list plus ``.ini``.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Applied in 47aca39.

Address review feedback: describe the default ignored extensions as the
REJECT_EXTS list plus .orig, .cfg and .retry, with a link to the source,
instead of copying the list. Drop "as shown above" now that the list is
gone, and say "the default list" in the note about .ini.

Assisted-by: Claude Opus 5.5
Signed-off-by: YoungjuKim <[email protected]>
@fjvbn2003

Copy link
Copy Markdown
Author

@Akasurde I've applied all three suggestions in 47aca39. Could you take another look when you have time? Thanks!

I also checked the note against real behavior, with a directory containing hosts.ini, db and cache.yml passed with -i:

  • ansible-core 2.18.19: the web group from hosts.ini is missing, and even -vvv prints nothing about hosts.ini; the default INVENTORY_IGNORE_EXTS includes .ini.
  • ansible-core 2.19.14: hosts.ini is parsed by the ini plugin; .ini is no longer in the default list.
  • 2.19.14 with ANSIBLE_INVENTORY_IGNORE=.ini: hosts.ini is skipped again, as the new paragraph describes.

Assisted-by: Claude

This branch was previously deployed

1 inactive deployment
github-bot — 47aca398 Deployed Nov 4, 2026 by fjvbn2003 via Label Issue/PR #6344
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new_contributor This PR is the first contribution by a new community member.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants