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

Proposal ansible-playbook --list-tags parser #438

Open
sebhoss opened this issue Jul 23, 2023 · 4 comments
Open

Proposal ansible-playbook --list-tags parser #438

sebhoss opened this issue Jul 23, 2023 · 4 comments

Comments

@sebhoss
Copy link

sebhoss commented Jul 23, 2023

It would be great to have the output ansible-playbook --list-tags ... as JSON. Calling that command with two example playbooks outputs this:

$ ansible-playbook --list-tags playbook.yaml debug.yml
playbook: playbook.yaml

  play #1 (all:!this): all:!this	TAGS: [some, tag]
      TASK TAGS: [first, second, third]

  play #2 (all,!this,&that): some name here	TAGS: []
      TASK TAGS: [some, other]

  play #3 (this): this	TAGS: []
      TASK TAGS: [first, second, third]

  play #4 (that): that	TAGS: [that]
      TASK TAGS: [that]

  play #5 (this:&that): this:&that	TAGS: []
      TASK TAGS: []

playbook: debug.yml

  play #1 (all): dump all vars	TAGS: [debug]
      TASK TAGS: []

I would love to have something like the following as the parser result after calling ansible-playbook --list-tags playbook.yaml debug.yml | jc --ansible-playbook-list-tags:

[
  {
    "playbook": "playbook.yaml",
    "plays": [
      {
        "number": 1,
        "hosts": ["all", "!this"],
        "name": "all:!this",
        "tags": ["some", "tag"],
        "task_tags": ["first", "second", "third"]
      },
      {
        "number": 2,
        "hosts": ["all", "!this", "&that"],
        "name": "some name here",
        "tags": [],
        "task_tags": ["some", "other"]
      },
      {
        "number": 3,
        "hosts": ["this"],
        "name": "this",
        "tags": [],
        "task_tags": ["first", "second", "third"]
      },
      {
        "number": 4,
        "hosts": ["that"],
        "name": "that",
        "tags": ["that"],
        "task_tags": ["that"]
      },
      {
        "number": 5,
        "hosts": ["this", "&that"],
        "name": "this:&that",
        "tags": [],
        "task_tags": []
      }
    ]
  },
  {
    "playbook": "debug.yml",
    "plays": [
      {
        "number": 1,
        "hosts": ["all"],
        "name": "dump all vars",
        "tags": ["debug"],
        "task_tags": []
      }
    ]
  }
]
@kellyjonbrazil
Copy link
Owner

Hi there! I'm not an expert in Ansible, but I thought you could get JSON output via the JSON callback for STDOUT? Something like:

ANSIBLE_CALLBACK_WHITELIST=json ANSIBLE_STDOUT_CALLBACK=json ansible-playbook ...

https://devops.stackexchange.com/questions/12213/how-do-i-make-ansible-playbook-log-its-output-in-a-machine-readable-format-like

@sebhoss
Copy link
Author

sebhoss commented Jul 24, 2023

Yeah that does not seem to be working for --list-tags. I've tried with

  • ANSIBLE_CALLBACK_WHITELIST=json ANSIBLE_STDOUT_CALLBACK=json ...
  • ANSIBLE_CALLBACK_WHITELIST=ansible.posix.json ANSIBLE_STDOUT_CALLBACK=ansible.posix.json ...
  • ANSIBLE_CALLBACKS_ENABLED=json ANSIBLE_STDOUT_CALLBACK=json ...
  • ANSIBLE_CALLBACKS_ENABLED=ansible.posix.json ANSIBLE_STDOUT_CALLBACK=ansible.posix.json ...

Additionally I've tried the following settings in ansible.cfg:

[defaults]
callbacks_enabled = json
stdout_callback = json

and the fully qualified variant as well:

[defaults]
callbacks_enabled = ansible.posix.json
stdout_callback = ansible.posix.json

Sadly none of that returns JSON output for --list-tags, however it returns JSON for just running ansible-playbook so I'm guessing that this might be a missing feature in ansible and not a problem with my local setup.

@kellyjonbrazil
Copy link
Owner

Gotcha. Could you open an issue with the Community.General project to get this supported?

https://github.com/ansible-collections/community.general/issues

This might be a quick fix on their side. If not, then it may make sense to create a jc parser for this.

@sebhoss
Copy link
Author

sebhoss commented Jul 26, 2023

Ok I've created ansible-collections/ansible.posix#485

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

No branches or pull requests

2 participants