Hostvars and --limit

Hi,

When I run the ansible playbook with a --limit option (in order to restrict the nodes on which the install would happen), the hostvars object does not contain the variables for the hosts not specified in the --limit option. Some of my playbook templates use hostvars for all the hosts in the inventory, and as a result these template rules fail when I run with the --limit option. What is the best way to get around this problem?

Thanks,
Anubhav

I think the issue is Ansible doesn't gather facts from hosts that
aren't in the play.

We have a central log/graphite server that all hosts wired their
monitoring agents into,
and in our case just using an inventory hostname wasn't enough since
traffic needed to
flow over a dedicated instrumentation network, so we'd have to figure
out the IP of the
interface connected to that subnet.

This was a pretty big stack so when you changed something on a
specific group of servers,
a quick 'limit run' saved a few minutes and we constantly forgot to
add the monitoring
servers into the limit list.

Best workaround I found was to limit the amount of hostvars I used and
replace them with
inventory variables. These were physical servers so keeping specific
data in the inventory
was practical, that may be more difficult on e.g. AWS.

Another way would be to break your main playbook into smaller
sub-playbooks and explicitly
gather the required facts at the top of them.

in current devel you can use delegated fact gathering:

- serup:
  delegate_to: "{{item}}"
  with_items: "{{groups['all']}}"