mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
The `ansiblegate
` module now correctly passes keyword arguments to Ansible module calls
Fixes #59792
This commit is contained in:
parent
cedc24249c
commit
d83dd0319f
3 changed files with 26 additions and 5 deletions
1
changelog/59792.fixed
Normal file
1
changelog/59792.fixed
Normal file
|
@ -0,0 +1 @@
|
|||
The ``ansiblegate`` module now correctly passes keyword arguments to Ansible module calls
|
|
@ -226,11 +226,12 @@ def _set_callables(modules):
|
|||
Call an Ansible module as a function from the Salt.
|
||||
"""
|
||||
kwargs = {}
|
||||
if kw.get("__pub_arg"):
|
||||
for _kw in kw.get("__pub_arg", []):
|
||||
if isinstance(_kw, dict):
|
||||
kwargs = _kw
|
||||
break
|
||||
for _kw in kw.get("__pub_arg", []):
|
||||
if isinstance(_kw, dict):
|
||||
kwargs = _kw
|
||||
break
|
||||
else:
|
||||
kwargs = {k: v for (k, v) in kw.items() if not k.statsrtwith("__pub")}
|
||||
|
||||
return _caller.call(cmd_name, *args, **kwargs)
|
||||
|
||||
|
|
|
@ -23,3 +23,22 @@ def test_ansible_functions_loaded(modules):
|
|||
|
||||
ret.pop("timeout", None)
|
||||
assert ret == {"ping": "pong"}
|
||||
|
||||
|
||||
def test_passing_data_to_ansible_modules(modules):
|
||||
"""
|
||||
Test that the ansible functions are actually loaded
|
||||
"""
|
||||
expected = "foobar"
|
||||
if "ansible.system.ping" in modules:
|
||||
# we need to go by getattr() because salt's loader will try to find "system" in the dictionary and fail
|
||||
# The ansible hack injects, in this case, "system.ping" as an attribute to the loaded module
|
||||
ret = getattr(modules.ansible, "system.ping")(data=expected)
|
||||
elif "ansible.ping" in modules:
|
||||
# Ansible >= 2.10
|
||||
ret = modules.ansible.ping(data=expected)
|
||||
else:
|
||||
pytest.fail("Where is the ping function these days in Ansible?!")
|
||||
|
||||
ret.pop("timeout", None)
|
||||
assert ret == {"ping": expected}
|
||||
|
|
Loading…
Add table
Reference in a new issue