Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansible list workaround support #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hanynowsky
Copy link

Ansible list workaround support

@bryanlarsen
Copy link
Contributor

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. :)

@hanynowsky
Copy link
Author

hanynowsky commented Nov 1, 2017

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

@bryanlarsen
Copy link
Contributor

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. :)

@hanynowsky
Copy link
Author

Yeah. Pretty much simpler and efficient. Please go ahead and commit the changes.

@dagwieers
Copy link

Please see #6 (comment) for a solution to support multiple use-cases in a single call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants