List all variables/facts that are used in a playbook?

Hi all,

I am looking for a way to list all variables referenced by a playbook without executing any tasks. Ideally, I would also be able to spit out the values of those variables for each host matched in the play.

My use case for this is for when I inherit a complex playbook or role from a colleague that is not well documented.

I know that I can do this:
ansible -m debug -a “var=hostvars[inventory_hostname]”
to spit out the variables set for each host in inventory. This works fine, but lists every variable defined for those hosts.

I’m only interested in the variables that are used by a given playbook or role. Is there a built-in way to do this?

I know, of course, that I could just read through the playbook/role to pick out the variables, maybe there will be a defaults/main.yml, etc. I also know that I could just execute the playbook and wait until it complains about a missing value. But I’d love a one-stop solution showing me what variables are expected (and, ideally, their values when given an inventory).

If there’s not a built-in way to do all of this, is there another built-in way to get part of the way there?

We’re on Ansible 1.9.4 still, but will be moving to Ansible 2 soon, so help on either is appreciated.

Thanks,
Kevin

Kevin,
That sounds really useful. I am not aware of any simple way to do that, but I am following this conversation because I might learn something useful.

Thanks for asking!
Joanna