Seth Vidal has added a very nice --list-hosts to /usr/bin/ansible-playbook.
When using this, it will show what hosts ansible would have talked to in each play, without actually talking to them.
This is a great way to check your patterns before actually running commands.
Try it in the latest git version.
--Michael
If anyone wants to work on enhancing this - I'd love for it to take a playbooks path and look for any other playbook referencing this playbook and traversing those for hosts as well.
I just want to be able to have admins on the team I'm on be able to know what they are going to impact before running it.
-sv
If anyone wants to work on enhancing this - I'd love for it to take a
playbooks path and look for any other playbook referencing this playbook
and traversing those for hosts as well.
I actually don't think that should be in core that way, but could be another script on top that calls this as is, yeah.
You could list the playbook files in the git diff, find all the playbook files in the diff, and run ansible-playbook --list-hosts on all of them, I'd think.
You would want to make sure something was a playbook and not a task list or it might not work great though. This might need be a bit of a fuzzy match, unless you have the convention of putting all your tasks and handler file includes in a "tasks/" directory or something (which is a good idea anyway).
I just want to be able to have admins on the team I'm on be able to know
what they are going to impact before running it.
Totally.
If anyone wants to work on enhancing this - I'd love for it to take a
playbooks path and look for any other playbook referencing this playbook
and traversing those for hosts as well.
I actually don't think that should be in core that way, but could be another script on top that calls this as is, yeah.
I agree.
You could list the playbook files in the git diff, find all the playbook files in the diff, and run ansible-playbook --list-hosts on all of them, I'd think.
You would want to make sure something was a playbook and not a task list or it might not work great though. This might need be a bit of a fuzzy match, unless you have the convention of putting all your tasks and handler file includes in a "tasks/" directory or something (which is a good idea anyway).
I was thinking of parsing the playbook into 'plays' then saying 'if this play has no hosts: section then it is only included by other playbooks'
and then go looking for that filename in a tree of playbooks.
I think that would work.... not sure.
-sv
I was thinking of parsing the playbook into 'plays' then saying 'if this
play has no hosts: section then it is only included by other playbooks'
Yeah, sort of -- if a playbook A includes playbook B, each play in
playbook B must still define a "hosts:" section.
However, if there's no element in there with a "hosts:" line in the
YAML, it's not a playbook.