Initial Commit

This commit is contained in:
2020-10-13 16:33:32 +13:00
commit d646952ef5
23 changed files with 429 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
- name: Register with CheckMK Update Server
shell: |
cmk-update-agent register -H $(hostname -s) --user {{ cmk_username }} \
--secret {{ cmk_secret }}

34
tasks/RedHat.yml Normal file
View File

@@ -0,0 +1,34 @@
---
# Tasks for installation on RedHat Family
- name: Ensure xinetd installed
yum:
name: xinetd
state: installed
notify: restart xinetd
- name: Gather facts of packages
package_facts:
manager: "auto"
- name: Install check-mk-agent
block:
- name: Download the agent from Server
get_url:
url: "{{ cmk_rpm_agent }}{{ cmk_auth }}"
dest: /tmp/check-mk-agent.rpm
- name: Ensure check_mk_agent installed
yum:
name: /tmp/check-mk-agent.rpm
state: installed
notify:
- restart xinetd
- cmk fresh install
- name: Remove agent Download
file:
path: /tmp/check-mk-agent.rpm
state: absent
when: "'check-mk-agent' not in ansible_facts.packages"
tags:
- check_mk_agent

View File

@@ -0,0 +1,5 @@
- name: Register with CheckMK Update Server
win_shell: |
C:\ProgramData\checkmk\agent\plugins\cmk-update-agent.exe register -H $env:computername `
--user {{ cmk_username }} `
--secret {{ cmk_secret }}

26
tasks/Windows.yml Normal file
View File

@@ -0,0 +1,26 @@
---
- name: Ensure temp dir exists
win_file:
path: "c:/temp/"
state: directory
- name: Retrieve copy of agent
win_get_url:
url: "{{ cmk_msi_agent }}{{ cmk_auth }}"
dest: "c:/temp/check-mk-agent.msi"
changed_when: false
- name: Ensure agent is installed
win_package:
path: "c:/temp/check-mk-agent.msi"
ignore_errors: yes
- name: Firewall rule to allow check_mk_agent on TCP port 6556
win_firewall_rule:
name: check_mk_agent
enabled: yes
state: present
localport: 6556
action: allow
direction: in
protocol: tcp

52
tasks/host-management.yml Normal file
View File

@@ -0,0 +1,52 @@
---
- 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

9
tasks/main.yml Normal file
View File

@@ -0,0 +1,9 @@
---
# tasks file for ansible-role-cmk-agent
- include_tasks: "{{ ansible_os_family }}.yml"
- meta: flush_handlers
- include_tasks: host-management.yml
when: cmk_fresh_install
- include_tasks: "{{ ansible_os_family }}-register.yml"
when: cmk_fresh_install