ansible when with_items – ignore one group

I’m setting up icinga & using https://github.com/Icinga/icinga2-ansible

However, it’s putting a config on the icinga server to monitor itself, which is causing

information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/pmlgra-03.domain.conf
information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/satellite.conf
information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/services.conf
information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/slave-6.domain.conf
information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/templates.conf
information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/timeperiods.conf
information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/users.conf
critical/config: Error: Object 'dmlici-02.domain' of type 'Host' re-defined: in /etc/icinga2/conf.d/hosts.conf: 18:1-18:20; previous definition: in /etc/icinga2/conf.d/dmlici-02.domain.conf: 2:1-2:35
Location: in /etc/icinga2/conf.d/hosts.conf: 18:1-18:20
/etc/icinga2/conf.d/hosts.conf(16):  */
/etc/icinga2/conf.d/hosts.conf(17): 

So this ansible with_items and when fixed it. Note: My icinga server is in a group called icinga

- name: Copy Host Definitions
  template: src=hosts_template.j2
            dest={{ icinga2_hosts_dir }}/{{ hostvars[item]['inventory_hostname'] }}.conf
            owner=root 
            group=root 
            mode=0644
  with_items: groups['all']
  when: "'icinga' not in hostvars[item]['group_names']"

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/hncom/public_html/sandlininc.com/wp-includes/formatting.php on line 4803
This entry was posted in Automation, Linux / Unix, Monitoring by james. Bookmark the permalink.