ansible-config: default to checking all plugin configs - #87212
Conversation
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]>
|
I would move |
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]>
|
Thanks @felixfontein — reworked as suggested: |
| assert parse_args(['validate', '-t', 'base']).type == 'base' | ||
|
|
||
|
|
||
| def test_other_actions_default_to_base(): |
There was a problem hiding this comment.
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.
| cli = ConfigCLI(args=['ansible-config', *args]) | ||
| cli.init_parser() | ||
| options = cli.parser.parse_args(cli.args[1:]) | ||
| return cli.post_process_args(options) |
There was a problem hiding this comment.
Why can't this return type right away instead of accessing it in every test?
| return cli.post_process_args(options) | |
| return cli.post_process_args(options).type |
|
|
||
|
|
||
| def parse_args(args: list[str]): | ||
| # parse with the CLI's parser without initializing the global (write-once) |
There was a problem hiding this comment.
Did you mean for a part of this to be a docstring?
| return cli.post_process_args(options) | ||
|
|
||
|
|
||
| def test_validate_defaults_to_all(): |
| from ansible.cli.config import ConfigCLI | ||
|
|
||
|
|
||
| def parse_args(args: list[str]): |
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.
|
Thanks @webknjaz — addressed all of these:
|
|
I would change the scope of these changes, just make |
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]>
| @@ -0,0 +1,38 @@ | |||
| # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | |||
There was a problem hiding this comment.
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]>
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]>
SUMMARY
ansible-configdefaulted to-t base, so plugin-owned configuration was omitted unless users explicitly selectedallor a plugin type. Forvalidate, 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:Following the issue discussion and review feedback, this changes the
--typedefault toallconsistently for everyansible-configaction:list,dump,view,init, andvalidatenow resolve an omitted-ttoall.-t basepreserves the previous base-only behavior as a compatibility override.The
ansible-configintegration target now checks every action's documented default and exercises realinit,validate, anddumpbehavior 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 baseas the migration path for users who need the previous behavior.Fixes #86398
ISSUE TYPE
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.