Given a playbook
---
- hosts:
some_host_group
roles:
- foo
- bar
I'd like to get the list of all variables that the playbook needs to be defined. Something like:
# playbook-requires myplaybook.yml
For more elaborate (or just numerous) playbooks this might come handy. Before starting to write such utility, I'd like to make sure I'm not re-inventing the wheel.
A quick googling shows a lot of solutions for the opposite task (listing all defined variables). That's not what I'm looking for.
So, is anyone aware of such utility being available?
There is no tool like that, and I'm sure you need a complete Ansible-Yaml and Jinja-Parser. Maybe ansible-lint is a good starting point.
Because there could be vars used in the playbooks and roles and also in dependencies of that roles. Also roles will have templates and that could use vars. And then it is unlikely possible to have "constructed" var-keys in dictionaries or lists, which you can only see, when you completely run the script. There is a playbook dryrun - maybe it is possible to start there by examining all errors - but if it contains an if else condition only one block is interpreted.