I have a playbook that sets up the application configuration on a
server in a cluster. This configuration is based on other servers in
the cluster and uses hostvars to great effect in the templated
configuration. I'm really happy at how easy ansible make that. To make
that work so that the facts about the other hosts are gathered I have
an empty play at the top of these playbooks that looks something like
this:
# just gather facts from these groups
- hosts: group1:group2:group3
tasks:
# now do the real work
- hosts: group4
tasks:
# lots of tasks
This seems a little weird that there's not an explicit way to gather
facts (it just a side effect, but it works fine so no biggie.
That's the preamble... The awkward part is when I want to add a new
server to this cluster and I want to run a playbook against just one
host of the group (the new server). Normally I could just use a
--limit server8 or something, but then this skips the fact gathering
step implicit in the empty tasks at the beginning of the playbook. So
instead I have to do something like:
--limit server8:group1:group2:group3
Or (slightly shorter but more opaque)
--limit '!group4&server8'
I'm trying to train myself to remember to do one of these, but I have
to train my team too. It would be nice if my playbook had a way of
explicitly gathering facts that wasn't skipped by a --limit arg (more
control in the playbook and less need for command line args) and then
I could just do the more intuitive
--limit server8
Am I doing it wrong? Or is this a pain others feel?