clean_zabbix.yml 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ---
  2. - hosts: localhost
  3. gather_facts: no
  4. connection: local
  5. become: no
  6. vars:
  7. g_server: http://localhost:8080/zabbix/api_jsonrpc.php
  8. g_user: ''
  9. g_password: ''
  10. roles:
  11. - lib_zabbix
  12. post_tasks:
  13. - name: CLEAN List template for heartbeat
  14. zbx_template:
  15. zbx_server: "{{ g_server }}"
  16. zbx_user: "{{ g_user }}"
  17. zbx_password: "{{ g_password }}"
  18. state: list
  19. name: 'Template Heartbeat'
  20. register: templ_heartbeat
  21. - name: CLEAN List template app zabbix server
  22. zbx_template:
  23. zbx_server: "{{ g_server }}"
  24. zbx_user: "{{ g_user }}"
  25. zbx_password: "{{ g_password }}"
  26. state: list
  27. name: 'Template App Zabbix Server'
  28. register: templ_zabbix_server
  29. - name: CLEAN List template app zabbix server
  30. zbx_template:
  31. zbx_server: "{{ g_server }}"
  32. zbx_user: "{{ g_user }}"
  33. zbx_password: "{{ g_password }}"
  34. state: list
  35. name: 'Template App Zabbix Agent'
  36. register: templ_zabbix_agent
  37. - name: CLEAN List all templates
  38. zbx_template:
  39. zbx_server: "{{ g_server }}"
  40. zbx_user: "{{ g_user }}"
  41. zbx_password: "{{ g_password }}"
  42. state: list
  43. register: templates
  44. - debug: var=templ_heartbeat.results
  45. - name: Remove templates if heartbeat template is missing
  46. zbx_template:
  47. zbx_server: "{{ g_server }}"
  48. zbx_user: "{{ g_user }}"
  49. zbx_password: "{{ g_password }}"
  50. name: "{{ item }}"
  51. state: absent
  52. with_items: "{{ templates.results | difference(templ_zabbix_agent.results) | difference(templ_zabbix_server.results) | oo_collect('host') }}"
  53. when: templ_heartbeat.results | length == 0