Closed sebhoss closed 1 week ago
Don't you just convert YAML to JSON?
ansible -i localhost, -c local all -o -m debug -a var=out -e 'out={{(lookup("file","site.yml")|from_yaml|first).tasks|map(attribute="name")|to_json}}'|sed -ne 's/^localhost[^{]*{/{/p'|jq '.out|fromjson'
Yeah kinda but I need Ansible to provide me with all the tags of all tasks found in all referenced roles as well instead of just parsing a single YAML file. Your snippet is basically just doing yq '...' site.yml
but that does not consider the task YAML files of the various roles. ansible-playbook --list-tags
shows all these tasks with their tags.
As an example my site.yml
looks like this:
- hosts: control_plane
roles:
- { role: control-plane, tags: [control-plane] }
ansible-playbook --list-tags
provides me with this:
playbook: site.yml
play #1 (control_plane): control_plane TAGS: []
TASK TAGS: [lots, of, tags, are, listed, here, control-plane, and, even, more, after, the, break]
Your snippet gives me
[
{
"hosts": "control_plane",
"roles": [
{
"role": "control-plane",
"tags": [
"control-plane"
]
}
]
}
]
I want all the tags in the JSON structure as well.
Oh I just realised that I wrote --list-tasks
in the initial description but meant to write --list-tags
- sorry for the confusion!
the --list-X
are hardcoded in core, the callbacks do not have the ability to change this output.
This is a feature in my wish list to change it to callback handled output, in any case this should be a feature request in https://github.com/ansible/ansible.
I was working on this as part of https://github.com/ansible/ansible/pull/80637, but this is not planned and on the back-burner for now.
Closing as per the above comment.
SUMMARY
Using
ansible.posix.json
should work foransible-playbook --list-tags
as well in order to write the output of that call in JSON format to stdout.ISSUE TYPE
COMPONENT NAME
plugins/callback/json
ADDITIONAL INFORMATION
I'd like to have JSON output in order to build some scripting around
ansible-playbook --list-tags
.