1

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?

2
  • 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? Commented Oct 9, 2017 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. Commented Oct 10, 2017 at 15:51

1 Answer 1

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.