0

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?

  • 3
    I doubt that it is possible. Look at something like this: {{ myvar2 if myvar1 is defined else myvar3 }}. What vars are required in this case? – Konstantin Suvorov Oct 9 '17 at 6:04
  • 1
    @Konstantin: (myvar2 and myvar1) or myvar3. I agree, it might get ugly, but browsing through the code containing some elaborate constructs won't be any prettier. In particular when you've got a set of playbooks and have to configure everything from scratch. – badbishop Oct 10 '17 at 15:51
0

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.