ansible-ghetto-json
ansible-ghetto-json copied to clipboard
Ansible list workaround support
Ansible list workaround support
I get some sort of strange unicode issues with this.
Using
- ghetto_json:
path: /tmp/foo.json
bar:
- 'bat'
I get result
"bar": [
"u'bat'"
],
Python 2.7.12, ansible 2.4.1.0
To make things work, I replaced the meat of your if clause with target=eval(target)
. That'll be much more robust in the face of values containing [
, ]
, or "
, but it's eval. :)
It s working fine for me. did you notice the (jinja filter : to_json):
ghetto_json: path=/etc/sensu/config.json client.keepalive.handlers='{{managed_keepalive_handlers|to_json}}'
- python 2.7, Ansible 2.3
---
managed_keepalive_handlers:
- halive
- pagerduty
No, I missed that. to_json isn't as easy to use inline as it is with variables. But given that you're requiring json, how about using json.loads
instead of the string.replace hacks? Similar idea to my eval, just not dangerous. :)
Yeah. Pretty much simpler and efficient. Please go ahead and commit the changes.
Please see https://github.com/FauxFaux/ansible-ghetto-json/issues/6#issuecomment-594509703 for a solution to support multiple use-cases in a single call.