Skip to content

Commit

Permalink
[PR #6968/f6714eda backport][stable-7] cmd_runner module utils: fix b…
Browse files Browse the repository at this point in the history
…ug when argument spec has implicit type (#6978)

cmd_runner module utils: fix bug when argument spec has implicit type (#6968)

* cmd_runner module utils: fix bug when argument spec has implicit type

* add changelog frag

(cherry picked from commit f6714ed)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
  • Loading branch information
patchback[bot] and russoz authored Jul 20, 2023
1 parent 0f5f00f commit 7bf1552
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/6968-cmdrunner-implicit-type.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- cmd_runner module utils - when a parameter in ``argument_spec`` has no type, meaning it is implicitly a ``str``, ``CmdRunner`` would fail trying to find the ``type`` key in that dictionary (https://github.com/ansible-collections/community.general/pull/6968).
2 changes: 1 addition & 1 deletion plugins/module_utils/cmd_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def __init__(self, module, command, arg_formats=None, default_args_order=(),

for mod_param_name, spec in iteritems(module.argument_spec):
if mod_param_name not in self.arg_formats:
self.arg_formats[mod_param_name] = _Format.as_default_type(spec['type'], mod_param_name)
self.arg_formats[mod_param_name] = _Format.as_default_type(spec.get('type', 'str'), mod_param_name)

def __call__(self, args_order=None, output_process=None, ignore_value_none=True, check_mode_skip=False, check_mode_return=None, **kwargs):
if output_process is None:
Expand Down
1 change: 1 addition & 0 deletions tests/integration/targets/cmd_runner/library/cmd_echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def main():
arg_values=dict(type="dict", default={}),
check_mode_skip=dict(type="bool", default=False),
aa=dict(type="raw"),
tt=dict(),
),
supports_check_mode=True,
)
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/targets/cmd_runner/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,20 @@ cmd_echo_tests:
- test_result.rc == None
- test_result.out == None
- test_result.err == None

- name: set aa and tt value
arg_formats:
aa:
func: as_opt_eq_val
args: [--answer]
tt:
func: as_opt_val
args: [--tt-arg]
arg_order: 'aa tt'
arg_values:
tt: potatoes
aa: 11
assertions:
- test_result.rc == 0
- test_result.out == "-- --answer=11 --tt-arg potatoes\n"
- test_result.err == ""

0 comments on commit 7bf1552

Please sign in to comment.