well it does return content already, all the stdout and such.
I see – but I don’t see how to usefully use that in subsequent tasks (beyond debug).
I can do:
`
register: result=std_out|to_json
`
Or some such?
I think what you are saying is that have a flag that if the output of the command is already JSON and you requested this behavior, return the JSON datastructure in an element called “json”?
Yes. That’s my specific problem.
More generally, it raises the question: how can I operate on the results of an action (in code I write in playbooks and tasks vs modules)? The scope of what’s possible isn’t clear to me from the docs. Can I say, filter a list of results (e.g. from ec2_describe) and store the results in another list with an named value?
I’m somewhat open to it, but also think that because it’s possible to do the “from_json” stuff with set fact, we have a bit of a solution, and it might be used in such a minority set of use cases skimming over the option for most might cause greater confusion.
I don’t know.
To be clear, I’m suggesting this:
- set_fact:
foo: “{{ x | from_json }}”
Doesn’t this only assign a fact to the target host?
In many cases, that’s not the desired behavior. Suppose I want to collect a list of RDS instances ids by tag and perform simple operations on them over and over?
Being able to:
- add variables
- trigger conditions
- filter output, join lists… etc…
would be tremendously useful. I guess something like:
`
- hosts: localhost
- name: Describe instances
hosts: localhost
gather_facts: false # Prevents immediately logging in to hosts
tasks:
- command: aws ec2 describe-instances
after: >
some python code to filter the results
some python code to register 5 groups
some python code to register 2 variables (register)
`
isn’t possible?
This is just an example, I’m already using ec2.py for much of this. But more fined-grained controlled is required (such as having tasks conditionally execute or wait on ec2_instance states which may change in response to prior tasks).