You've already forked role-check-mk-agent
53 lines
1.4 KiB
YAML
53 lines
1.4 KiB
YAML
|
|
---
|
||
|
|
- name: add host to omd
|
||
|
|
uri:
|
||
|
|
method: POST
|
||
|
|
url: "http://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=add_host{{ cmk_auth }}"
|
||
|
|
body: |
|
||
|
|
request={
|
||
|
|
"attributes": {
|
||
|
|
"tag_criticality": "prod",
|
||
|
|
"tag_agent": "cmk-agent",
|
||
|
|
"ipaddress": "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
|
||
|
|
},
|
||
|
|
"folder": "{{ cmk_folder | default('Unsorted') }}",
|
||
|
|
"hostname": "{{inventory_hostname}}"
|
||
|
|
}
|
||
|
|
body_format: raw
|
||
|
|
return_content: yes
|
||
|
|
register: res
|
||
|
|
become: no
|
||
|
|
delegate_to: localhost
|
||
|
|
when: cmk_add_host
|
||
|
|
|
||
|
|
- set_fact:
|
||
|
|
output: "{{ res.content | from_json }}"
|
||
|
|
when: cmk_add_host
|
||
|
|
|
||
|
|
# - debug:
|
||
|
|
# msg: "{{ output }}"
|
||
|
|
# when: cmk_add_host
|
||
|
|
|
||
|
|
- name: cmk_discovery
|
||
|
|
uri:
|
||
|
|
method: POST
|
||
|
|
url: http://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=discover_services&mode=refresh{{ cmk_auth }}
|
||
|
|
body: 'request={"hostname":"{{ inventory_hostname }}"}'
|
||
|
|
body_format: raw
|
||
|
|
status_code: 200
|
||
|
|
become: no
|
||
|
|
when: "cmk_add_host and output.result_code == 0"
|
||
|
|
delegate_to: localhost
|
||
|
|
|
||
|
|
- name: cmk_apply
|
||
|
|
uri:
|
||
|
|
method: POST
|
||
|
|
url: http://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=activate_changes&mode=specific{{ cmk_auth }}
|
||
|
|
body: 'request={"sites":["{{ cmk_omd_site }}"]}'
|
||
|
|
body_format: raw
|
||
|
|
status_code: 200
|
||
|
|
become: no
|
||
|
|
run_once: true
|
||
|
|
when: "cmk_add_host and output.result_code == 0"
|
||
|
|
delegate_to: localhost
|