I'm using the icinga2-ansible-add-hosts role, which creates config files for each host.
My playbook starts like this:
---
- hosts: all
gather_facts: True
- hosts: "{{ hosts | default('monitoring_servers') }}"
- strategy: debug
- role: icinga2-ansible-add-hosts
Inside the add-hosts role is the following task:
--
- name: Copy Host Definitions
template: src=hosts_template.j2
dest={{ icinga2_hosts_dir }}/{{ hostvars[item]['ansible_fqdn'] }}.conf
owner=root
group=root
mode=0644
with_items: "{{ groups['all'] }}"
notify:
- restart icinga2
When I run `ansible-playbook -i inventory/ --limit <GROUP> icinga2.yml -vvv` I notice that gather_facts is only done on the hosts in <GROUP>, but the template tries to generate config files for all of my hosts, because "{{ groups['all'] }}" contains all of the hosts in the inventory directory, not just those in <GROUP>.
Checking Google and IRC it seems like there is no way to programmatically get the list of machines specified by --limit. Is that correct? Is there a way to iterate over a list of hosts that were specified on the command line?