Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
json-ify environment values #61295
If an environment value (of an env key) set on a task is a dict or a list then the actual env value may not be what's expected. This PR converts these values to a json to ensure consistency across shell plugins.
Using the following playbook as an example
Here is what happens before the PR
Here is what happens after the PR
We can see that before PowerShell is completely useless as the raw object being sent to the host is an actual dict/list and .NET is not helpful in their ToString implementations. On Python it is slightly more useful but the values aren't fully JSON compliant with their single quotes instead of double quotes. With this PR now both platforms align with each other and the JSON being set as the env var in Python uses double quotes.
An alternative is to set the key inside an actual string like;
But this causes the env var to be
Going by @bcoca's comments above and it looks like we would want to error out if the type is a sequence type instead of assuming the user wants JSON. The original issue is only a problem if we use this pattern;
Ansible's magic eval of values here is causing the string
Because there are options today I propose we change this PR to error out instead of converting to json is a sequence type is encountered. I'll talk about this at the public agenda a bit more.