nginx/tasks/create-webcheck-zabbix.yml

111 lines
2.8 KiB
YAML

---
- name: Requesting API authentification token
uri:
url: "{{zabbix_url}}"
return_content: yes
method: POST
body: "{{lookup('template','templates/zabbix/auth.j2')}}"
body_format: json
headers:
Content-Type: "application/json-rpc"
register: z_authquery
tags:
- zabbix
- name: Parsing the authentification request to extract the token
set_fact: "z_authtoken={{z_authquery.json.result}}"
tags:
- zabbix
- name: Listing web scenarios flaggued as absent in ansible
set_fact: "absent_scenarios={{nginx_vhost|selectattr('state','equalto','absent')|list}}"
tags:
- resign
- zabbix
- name: Getting IDs of all web scenarios to delete (via Zabbix API)
uri:
url: "{{zabbix_url}}"
return_content: yes
body: "{{lookup('template','templates/zabbix/get_site.j2')}}"
body_format: json
headers:
Content-Type: "application/json-rpc"
with_items: "{{absent_scenarios}}"
register: to_delete
tags:
- resign
- zabbix
- name: Deleting the supposed absent web scenarios in Zabbix
uri:
url: "{{zabbix_url}}"
return_content: yes
method: POST
body: "{{lookup('template','templates/zabbix/del_site.j2')}}"
body_format: json
headers:
Content-Type: "application/json-rpc"
with_items : "{{to_delete.results}}"
tags:
- resign
- zabbix
- name: Getting the hostid of the default http poller (via Zabbix API)
uri:
url: "{{zabbix_url}}"
return_content: yes
body: "{{lookup('template','templates/zabbix/get_host.j2')}}"
body_format: json
headers:
Content-Type: "application/json-rpc"
register: hostidquery
tags:
- zabbix
- name: Parsing the get_site request to extract the hostid
set_fact: "z_hostid={{hostidquery.json.result.0.hostid}}"
tags:
- zabbix
- name: Adding web scenarios (zabbix API handles the indepotency)
uri:
url: "{{zabbix_url}}"
return_content: yes
method: POST
body: "{{lookup('template','templates/zabbix/add_web.j2')}}"
body_format: json
headers:
Content-Type: "application/json-rpc"
with_items: "{{nginx_vhost}}"
when: "item.state == 'present'"
tags:
- zabbix
- name: Adding associated triggers (zabbix API handles the indepotency)
uri:
url: "{{zabbix_url}}"
return_content: yes
method: POST
body: "{{lookup('template','templates/zabbix/add_trigger.j2')}}"
body_format: json
headers:
Content-Type: "application/json-rpc"
with_items: "{{nginx_vhost}}"
when: "item.state == 'present'"
tags:
- vhost
- zabbix
- name: Logging out from Zabbix API
uri:
url: "{{zabbix_url}}"
return_content: yes
method: POST
body: "{{lookup('template','templates/zabbix/logout.j2')}}"
body_format: json
headers:
Content-Type: "application/json-rpc"
tags:
- zabbix