Fix ansible.playbooks extra_vars quoting#68787
Conversation
| command.append(f"--extra-vars={shlex.quote(json.dumps(extra_vars))}") | ||
| elif isinstance(extra_vars, str) and extra_vars.startswith("@"): | ||
| command.append(f"--extra-vars={extra_vars}") | ||
| command.append(f"--extra-vars={shlex.quote(extra_vars)}") |
There was a problem hiding this comment.
This won't necessarily work for windows.
There was a problem hiding this comment.
PowerShell supports single quotes for literals, but its escaping is not POSIX:
Embedded single quotes are escaped by doubling: 'Bob''s', not '"'"'.
PowerShell’s escape character is backtick `, not backslash.
There was a problem hiding this comment.
As far as I know this module never stated to be supported on windows. Even it's testing part contains:
pytestmark = [
pytest.mark.skip_on_windows(reason="Not supported on Windows"),
]
We still have almost 0 feedback on this module and this particular issue was found while testing very specific complex variables passing to the module, not sure if anyone will try to do the same with windows.
There was a problem hiding this comment.
and the module itself saying it, btw:
https://github.com/saltstack/salt/blob/master/salt/modules/ansiblegate.py#L86-L88
What does this PR do?
Fixes the quoting issue on passing complex variables to the playbook execution which could cause issues on passing
--extgra-varson runningansible-playbook.What issues does this PR fix or reference?
Tracks: https://github.com/SUSE/spacewalk/issues/29592
Previous Behavior
Causing wrong args passing ot
ansible-playbookin case of using unbalanced quoting and single quotes in general.New Behavior
Using proper quoting to pass the args, so no issues.
Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
Commits signed with GPG?
Yes/No