Skip to content

Fix ansible.playbooks extra_vars quoting#68787

Merged
dwoz merged 3 commits into
saltstack:masterfrom
vzhestkov:fix-ansible-extra-vars-quoting
Mar 30, 2026
Merged

Fix ansible.playbooks extra_vars quoting#68787
dwoz merged 3 commits into
saltstack:masterfrom
vzhestkov:fix-ansible-extra-vars-quoting

Conversation

@vzhestkov
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes the quoting issue on passing complex variables to the playbook execution which could cause issues on passing --extgra-vars on running ansible-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-playbook in 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

Comment on lines +368 to +370
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)}")
Copy link
Copy Markdown
Contributor

@bdrx312 bdrx312 Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't necessarily work for windows.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dwoz dwoz added the test:full Run the full test suite label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants