summaryrefslogtreecommitdiffstats
path: root/playbooks/adhoc/zabbix_setup/clean_zabbix.yml
blob: 955f990b7b54382d911a15ed6a2a110bb8cc2ccb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
- hosts: localhost
  gather_facts: no
  connection: local
  become: no
  vars:
    g_server: http://localhost:8080/zabbix/api_jsonrpc.php
    g_user: ''
    g_password: ''

  roles:
  - lib_zabbix

  post_tasks:
  - name: CLEAN List template for heartbeat
    zbx_template:
      zbx_server: "{{ g_server }}"
      zbx_user: "{{ g_user }}"
      zbx_password: "{{ g_password }}"
      state: list
      name: 'Template Heartbeat'
    register: templ_heartbeat

  - name: CLEAN List template app zabbix server
    zbx_template:
      zbx_server: "{{ g_server }}"
      zbx_user: "{{ g_user }}"
      zbx_password: "{{ g_password }}"
      state: list
      name: 'Template App Zabbix Server'
    register: templ_zabbix_server

  - name: CLEAN List template app zabbix server
    zbx_template:
      zbx_server: "{{ g_server }}"
      zbx_user: "{{ g_user }}"
      zbx_password: "{{ g_password }}"
      state: list
      name: 'Template App Zabbix Agent'
    register: templ_zabbix_agent

  - name: CLEAN List all templates
    zbx_template:
      zbx_server: "{{ g_server }}"
      zbx_user: "{{ g_user }}"
      zbx_password: "{{ g_password }}"
      state: list
    register: templates

  - debug: var=templ_heartbeat.results

  - name: Remove templates if heartbeat template is missing
    zbx_template:
      zbx_server: "{{ g_server }}"
      zbx_user: "{{ g_user }}"
      zbx_password: "{{ g_password }}"
      name: "{{ item }}"
      state: absent
    with_items: "{{ templates.results | difference(templ_zabbix_agent.results) | difference(templ_zabbix_server.results) | oo_collect('host') }}"
    when: templ_heartbeat.results | length == 0