Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ansible-config: default to checking all plugin configs - #87212

Merged
bcoca merged 6 commits into
ansible:develfrom
apoorvdarshan:fix-86398-config-validate-default
Jul 17, 2026
Merged

ansible-config: default to checking all plugin configs#87212
bcoca merged 6 commits into
ansible:develfrom
apoorvdarshan:fix-86398-config-validate-default

Conversation

@apoorvdarshan

@apoorvdarshan apoorvdarshan commented Jul 2, 2026

Copy link
Copy Markdown
Contributor
SUMMARY

ansible-config defaulted to -t base, so plugin-owned configuration was omitted unless users explicitly selected all or a plugin type. For validate, this meant a configuration file using a section such as [ssh_connection] was reported as unknown, while keys inside plugin-owned sections were not validated:

$ ansible-config validate
[ERROR]: Found unknown section 'ssh_connection' in '.../ansible.cfg.

Following the issue discussion and review feedback, this changes the --type default to all consistently for every ansible-config action:

  • list, dump, view, init, and validate now resolve an omitted -t to all.
  • -t base preserves the previous base-only behavior as a compatibility override.
  • Any specific plugin type still narrows the operation as before.
  • The shared option help documents both the new default and the compatibility override.

The ansible-config integration target now checks every action's documented default and exercises real init, validate, and dump behavior without an explicit type. The full target and all sanity checks for the changed files pass locally.

The changelog records the new default under Breaking Changes / Porting Guide and identifies -t base as the migration path for users who need the previous behavior.

Fixes #86398

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

ansible-config

ADDITIONAL INFORMATION

Developed with assistance from AI tools (Claude Code and OpenAI Codex); the approach, diff, and test results were reviewed and are owned by me. I'll respond to review feedback personally.

ansible-config validate defaulted to -t base, so any configuration file
using a section owned by a plugin (e.g. [ssh_connection]) was reported
as an unknown section, and keys inside such sections were never
validated at all - a stock, perfectly valid ansible.cfg failed
validation out of the box.

Default the validate action to -t all so installed plugin configuration
is taken into account. An explicit -t still narrows validation, and the
other ansible-config actions keep their base default (the -t default is
now resolved per action in post_process_args, since the shared parent
parser action object cannot carry per-subcommand defaults).

Fixes ansible#86398

Signed-off-by: Apoorv Darshan <[email protected]>
@ansibot ansibot added bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. has_issue labels Jul 2, 2026
@felixfontein

Copy link
Copy Markdown
Contributor

I would move -t to two new shared parsers, one per possible default value (probably created by a factory function), and adding these to the subcommands that use common now. That makes --help more precise per subcommand.

Per review: instead of a None sentinel resolved in post_process_args,
provide two small shared parent parsers for -t (one with default
'base', one with default 'all', built by a factory) so each
subcommand's --help states its actual default.

Signed-off-by: Apoorv Darshan <[email protected]>
@apoorvdarshan

Copy link
Copy Markdown
Contributor Author

Thanks @felixfontein — reworked as suggested: -t now lives in two small shared parent parsers built by a factory (one per default), added alongside common on each subcommand. ansible-config validate --help now says "Defaults to 'all'" and the other actions say "Defaults to 'base'". Verified the full behavior matrix again (default/-t base/-t all/dump/error cases) plus the unit tests.

@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Jul 3, 2026
Comment thread test/units/cli/test_config.py Outdated
assert parse_args(['validate', '-t', 'base']).type == 'base'


def test_other_actions_default_to_base():

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.

Most of these are the same test with different params. Use @pytest.mark.parametrize with IDs to deduplicate them but still let them show up separately in the test run report.

@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. pending_ci labels Jul 3, 2026
Comment thread test/units/cli/test_config.py Outdated
cli = ConfigCLI(args=['ansible-config', *args])
cli.init_parser()
options = cli.parser.parse_args(cli.args[1:])
return cli.post_process_args(options)

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.

Why can't this return type right away instead of accessing it in every test?

Suggested change
return cli.post_process_args(options)
return cli.post_process_args(options).type

Comment thread test/units/cli/test_config.py Outdated


def parse_args(args: list[str]):
# parse with the CLI's parser without initializing the global (write-once)

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.

Did you mean for a part of this to be a docstring?

Comment thread test/units/cli/test_config.py Outdated
return cli.post_process_args(options)


def test_validate_defaults_to_all():

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.

Missing return type?

Comment thread test/units/cli/test_config.py Outdated
from ansible.cli.config import ConfigCLI


def parse_args(args: list[str]):

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.

Set the return type plz.

@ansibot ansibot removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. pending_ci labels Jul 3, 2026
Deduplicate the three near-identical tests into a single
@pytest.mark.parametrize with descriptive IDs, return the resolved type
directly from the helper, add return-type annotations, and turn the
helper's leading comment into a docstring.
@apoorvdarshan

Copy link
Copy Markdown
Contributor Author

Thanks @webknjaz — addressed all of these:

  • Parametrized the three near-identical cases into a single test with descriptive IDs (validate-defaults-to-all, validate-narrows-with-type, other-actions-default-to-base), so they still show separately in the report.
  • parse_type() now returns the resolved type directly.
  • Added the missing return-type annotations (-> str on the helper, -> None on the test).
  • Turned the helper's leading comment into a docstring.

@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Jul 14, 2026
@bcoca

bcoca commented Jul 14, 2026

Copy link
Copy Markdown
Member

I would change the scope of these changes, just make all the default for the option in all cases, not just this narrow one. Also probably add a toggle in case it breaks backwards compatiblity for someone.

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jul 14, 2026
Broaden the new default as requested in review, while keeping -t base as the compatibility override for users who need the previous behavior. Cover every action and both explicit override paths in the parser tests.

Assisted-by: OpenAI Codex
Signed-off-by: Apoorv Darshan <[email protected]>
@apoorvdarshan apoorvdarshan changed the title ansible-config: default validate to checking all plugin configs ansible-config: default to checking all plugin configs Jul 14, 2026
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Jul 14, 2026
Comment thread changelogs/fragments/86398-ansible-config-validate-default-all.yml Outdated
Comment thread test/units/cli/test_config.py Outdated
@@ -0,0 +1,38 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

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.

An integration test would be preferable in this case

Exercise the public CLI across every action and run existing init, validate, and dump scenarios without an explicit type. Remove the parser-only unit test and use translation-friendly changelog wording.

Assisted-by: OpenAI Codex
Signed-off-by: Apoorv Darshan <[email protected]>
@ansibot ansibot added the stale_review Updates were made after the last review and the last review is more than 7 days old. label Jul 14, 2026
Comment thread changelogs/fragments/86398-ansible-config-validate-default-all.yml Outdated
Move the entry into the generated porting-guide section and document the -t base compatibility override.

Assisted-by: OpenAI Codex
Signed-off-by: Apoorv Darshan <[email protected]>
@ansibot ansibot added the feature This issue/PR relates to a feature request. label Jul 15, 2026
@ansibot ansibot removed the stale_review Updates were made after the last review and the last review is more than 7 days old. label Jul 15, 2026
@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. pending_ci and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. pending_ci labels Jul 16, 2026
@bcoca
bcoca merged commit 5149f7c into ansible:devel Jul 17, 2026
85 checks passed
@ansible ansible locked as resolved and limited conversation to collaborators Aug 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug This issue/PR relates to a bug. feature This issue/PR relates to a feature request. has_issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ansible-config validate says valid section is invalid

7 participants