Hi,
This looks like the right place for posting questions- but please point me in the right direction if not.
I’m using the “extra variables” box on the awx web front-end to provide key-value pairs to a shell script in my playbook. The problem I’m having is how I can use those variables in my shell script, as they all appear as {u’key’: u’value’} when I print them from within my shell script. This means that they don’t conform to the standard JSON format (which uses double-quotes) and also as these are unicode strings I’m having other issues trying to pull out the information I want. What I would like is to easily put these key-value pairs into an associative array so I can access the values when they’re required. Is there a good way to do this? At the moment I’m having to use sed to substitute out the bits I don’t want (the single quotes have to be converted to double quotes and I have to remove the “u” character and then pass this to a package called jq to read the string as a JSON object). This feels like the wrong approach, so I’m look for some advice or examples of whether this can be done more elegantly?
Hi Conor, sounds like you’re probably doing this (untested pseudocode):
- shell: “/path/to/script {{ var }}”
vars:
var:
some_key: some_data
Instead, you need to do something like this (untested pseudocode):
- shell: “/path/to/script {% for item in var|dict2items %}{{ item.key }}={{ item.value }}{% endfor %}”
vars:
var:
some_key: some_data
If not, if you can post some example script, that might help…
All the best,