3 Commits
1.0.0 ... 1.0.2

Author SHA1 Message Date
fbac11b098 Add protocol fror host-management 2020-10-14 22:57:15 +13:00
396d711be9 Added option force install/reinstall on RHEL 2020-10-14 15:01:34 +13:00
9d974bdf0c Fix linting issues 2020-10-13 23:40:02 +13:00
8 changed files with 25 additions and 18 deletions

3
.ansible-lint Normal file
View File

@@ -0,0 +1,3 @@
# .ansible-lint │
warn_list: # or 'skip_list' to silence them completely │
- '106' # Role name {} does not match ``^[a-z][a-z0-9_]+$`` pattern

View File

@@ -1,5 +1,6 @@
--- ---
cmk_add_host: false # Should be true/false whether we should automatically add host for monitoring. cmk_add_host: false # Should be true/false whether we should automatically add host for monitoring.
cmk_omd_protocol: http # Should be http or https
cmk_omd_host: your-checkmk-hostname cmk_omd_host: your-checkmk-hostname
cmk_omd_site: your-checkmk-site # e.g the first piece after the / following your hostname cmk_omd_site: your-checkmk-site # e.g the first piece after the / following your hostname
# If you have created a folder in WATO already you want hosts to be put in when registered # If you have created a folder in WATO already you want hosts to be put in when registered
@@ -23,3 +24,8 @@ cmk_auth: "&_username={{ cmk_username }}&_secret={{ cmk_secret }}"
# This variable is used to detect whether this is a fresh install # This variable is used to detect whether this is a fresh install
# Is changed to true if check-mk-agent gets installed # Is changed to true if check-mk-agent gets installed
cmk_fresh_install: false cmk_fresh_install: false
# This variable if set to true will force installation to run regardless of whether
# CheckMK is already installed.
# Breaks idempotence but allows role to be used to force upgrade agents.
cmk_force_install: false

View File

@@ -34,4 +34,3 @@ galaxy_info:
# Maximum 20 tags per role. # Maximum 20 tags per role.
dependencies: [] dependencies: []

View File

@@ -2,3 +2,4 @@
shell: | shell: |
cmk-update-agent register -H $(hostname -s) --user {{ cmk_username }} \ cmk-update-agent register -H $(hostname -s) --user {{ cmk_username }} \
--secret {{ cmk_secret }} --secret {{ cmk_secret }}
changed_when: false

View File

@@ -29,6 +29,6 @@
file: file:
path: /tmp/check-mk-agent.rpm path: /tmp/check-mk-agent.rpm
state: absent state: absent
when: "'check-mk-agent' not in ansible_facts.packages" when: "'check-mk-agent' not in ansible_facts.packages or cmk_force_install"
tags: tags:
- check_mk_agent - check_mk_agent

View File

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

View File

@@ -2,7 +2,7 @@
- name: add host to omd - name: add host to omd
uri: uri:
method: POST method: POST
url: "http://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=add_host{{ cmk_auth }}" url: "{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=add_host{{ cmk_auth }}"
body: | body: |
request={ request={
"attributes": { "attributes": {
@@ -20,18 +20,15 @@
delegate_to: localhost delegate_to: localhost
when: cmk_add_host when: cmk_add_host
- set_fact: - name: Parse result
set_fact:
output: "{{ res.content | from_json }}" output: "{{ res.content | from_json }}"
when: cmk_add_host when: cmk_add_host
# - debug:
# msg: "{{ output }}"
# when: cmk_add_host
- name: cmk_discovery - name: cmk_discovery
uri: uri:
method: POST method: POST
url: http://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=discover_services&mode=refresh{{ cmk_auth }} url: "{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=discover_services&mode=refresh{{ cmk_auth }}"
body: 'request={"hostname":"{{ inventory_hostname }}"}' body: 'request={"hostname":"{{ inventory_hostname }}"}'
body_format: raw body_format: raw
status_code: 200 status_code: 200
@@ -42,7 +39,7 @@
- name: cmk_apply - name: cmk_apply
uri: uri:
method: POST method: POST
url: http://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=activate_changes&mode=specific{{ cmk_auth }} url: "{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=activate_changes&mode=specific{{ cmk_auth }}"
body: 'request={"sites":["{{ cmk_omd_site }}"]}' body: 'request={"sites":["{{ cmk_omd_site }}"]}'
body_format: raw body_format: raw
status_code: 200 status_code: 200