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

Added json flag to command, which will cause command to attempt to parse... #3122

Closed
wants to merge 1 commit into from
Closed

Added json flag to command, which will cause command to attempt to parse... #3122

wants to merge 1 commit into from

Conversation

zonk1024
Copy link
Contributor

@zonk1024 zonk1024 commented Jun 4, 2013

... stdout and expose it to register.

example:

tasks:

  • name: grab json
    local_action: command /home/ubuntu/i_output_json json=true
    register: ioj_output
  • name: debug ioj_output
    debug: msg='${item}'
    with_items: ${ioj_output.json}

@mpdehaan
Copy link
Contributor

mpdehaan commented Jun 5, 2013

This is past our 6/3 feature freeze for the 6/10 release, so I will look at reviewing/merging this shortly after the 6/10 release. Thanks!

@zonk1024
Copy link
Contributor Author

zonk1024 commented Jun 5, 2013

Thank you!

I've been playing with it a bit, and one handy thing I've found for my use case is the ability to import the data from the ec2.py inventory script... although you have to massage the data a little through a shell call.

  • name: grab massaged output
    local_action: "shell hosts/ec2.py | tr -s ' ' | tr -d '\n'"
    register: massaged
  • name: parse massaged
    local_action: "command echo '{{ massaged.stdout }}' json=true"
    register: ec2
  • name: debug ec2 data
    local_action: "debug msg='{{ ec2.json }}'"
  • name: debug ec2 SOME_TAG servers
    local_action: "debug msg='{{ ec2.json.tag_SOME_TAG_ }}'"

Good times. Hope someone else can use this.

@mpdehaan
Copy link
Contributor

Well, the inventory script should be used as an inventory script and it's all handled for you.... was that why you needed this?

Just curious, thanks!

@zonk1024
Copy link
Contributor Author

No. I wanted to be able to fire off python scripts that return json and use those values within Ansible. I just thought the ec2.py thing was kind of nifty, and I wanted to try to post an example of it doing something. Since everyone has the ec2.py script...

@mpdehaan
Copy link
Contributor

Noticed the exception raising in this needs to be module.fail_json(...) versus the general exception raising.

@mpdehaan
Copy link
Contributor

mpdehaan commented Aug 3, 2013

Not seeing any update on this one, so I'm going to close this. I think this might be better handled by the executable facts.d implementation in 1.3 in many cases.

@mpdehaan mpdehaan closed this Aug 3, 2013
robinro pushed a commit to robinro/ansible that referenced this pull request Dec 9, 2016
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 5, 2018
@ansible ansible locked and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature This issue/PR relates to a feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants