42 Commits

Author SHA1 Message Date
b2190da07c Add test for http_direct dl 2024-01-07 22:31:51 +13:00
dfb2254d2b Don't do this unless samba 2023-10-03 12:06:16 +13:00
Mann Badal
8035c87efe Added yum and dnf condition when check_mk_agent 2023-10-03 09:52:27 +13:00
1c29992d07 vars/Redhat.yml edited online with Bitbucket 2022-08-10 19:43:58 +00:00
841bfc2eec Proper role testing 2022-08-11 00:07:24 +12:00
1efc90e172 Add environment helper 2022-08-11 00:04:41 +12:00
00d4100a3c Back to free-form include 2022-08-10 13:56:38 +12:00
fba7559a02 Fix formatting 2022-08-10 13:18:34 +12:00
a4588f6e62 Updated format for include vars 2022-08-10 12:38:33 +12:00
42a461001f Remove vars prefix 2022-08-10 12:23:04 +12:00
67b6952ba8 Removed doc from top of file 2022-08-10 12:19:55 +12:00
fcb04bcfae Corrected lookup of vars 2022-08-09 23:44:49 +00:00
23c945b9b8 Add note regards to CMK Folders and case 2022-08-09 09:09:34 +12:00
342fec8955 Update register of host 2022-08-09 07:42:02 +12:00
3d39f3e231 Add samba dl tasks 2022-08-09 07:41:10 +12:00
c41c2dc447 Samba supporting vars 2022-08-09 07:40:44 +12:00
602656dde5 Debian support 2022-08-09 07:40:13 +12:00
c449ae2435 Reslash ansible filter. (Reverse Slash) 2022-08-09 07:39:47 +12:00
ba1ae0a121 Add samba download option 2022-08-09 07:39:06 +12:00
965a6aa99f Ignore __pycache__ 2022-08-09 07:32:23 +12:00
b647ff7d9b Remove erroneus line 2021-10-19 16:31:38 +13:00
718f31bd59 Fix deprecation warning 2021-10-19 16:30:22 +13:00
ed0fc10161 Don't fail if firewalld not active 2021-10-19 16:28:47 +13:00
d899964718 Updated module name 2021-10-19 16:17:06 +13:00
2e719ccc9b Add ability to disable auth required for download 2021-10-19 16:07:10 +13:00
99af4c4a86 Add SELinux module install to role 2021-10-19 15:55:21 +13:00
2ae40a30a9 separate add host and discover. stop error 2021-10-05 13:55:06 +13:00
59d43f8112 Remove package if forcing removal 2021-10-05 11:30:16 +13:00
f4809d2ed7 Incorrect module name :( 2021-06-04 13:32:17 +12:00
14cb3f66e3 Check if installer already present 2021-06-04 13:06:44 +12:00
0b3eeddaf9 Relabel default var 2021-05-08 06:20:16 +12:00
957795b4fe Allow override of IP address 2021-05-08 05:58:43 +12:00
294df3f441 tagged - cmk_register 2021-05-07 20:34:34 +12:00
067b64947c allow instance_name and inventory_hostname 2021-05-07 20:12:43 +12:00
094cce6b01 Turn off cert validation 2021-05-07 16:45:10 +12:00
02daa0b30c Fallback to get_url 2021-05-07 16:37:37 +12:00
b56c03a3c3 Use wget instead of Ansible Builtin 2021-05-07 15:52:53 +12:00
2de6c9efad Make cert validation work 2021-05-07 15:33:22 +12:00
5ed5818aff Updating allowing for https:// 2021-05-07 11:00:14 +12:00
08a725ed68 Use yum command direct 2020-11-27 00:07:33 +13:00
438962933f Linting fixes 2020-11-26 23:12:45 +13:00
61a0209ece Revert back to temp download 2020-11-26 15:37:47 +13:00
29 changed files with 573 additions and 50 deletions

View File

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

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
__pycache__

View File

@@ -7,12 +7,30 @@ cmk_omd_site: your-checkmk-site # e.g the first piece after the / following your
# If you have created a folder in WATO already you want hosts to be put in when registered
# uncomment cmk_folder below and specify the folder to use. Otherwise the role creates and
# adds new hosts by default to Unsorted folder
# p.s: Folders created in the CMK UI are all lower case even if you enter them in capitals :(
# cmk_folder: your_folder_in_WATO
# Copy paste the link address for rpm agent from CheckMK
cmk_rpm_agent: http://url-from-your-agent-bakery-in-checkmk.rpm
# Copy paste the link address for MSI (Windows) agent from CheckMK
cmk_msi_agent: http://url-from-your-agent-bakery-in-checkmk.msi
cmk_download_mode: samba
cmk_smb_password: ~
cmk_smb_username: ~
# If using direct download (http) from CMK set below
# # Copy paste the link address for rpm agent from CheckMK
# cmk_rpm_agent_x86_64: http://url-from-your-agent-bakery-in-checkmk.rpm
# # Copy paste the link address for MSI (Windows) agent from CheckMK
# cmk_msi_agent_x86_64: http://url-from-your-agent-bakery-in-checkmk.msi
# # Copy paste from cmk server
# cmk_deb_agent_x86_64: http://url-from-your-agent-bakery-in-checkmk.deb
# # Copy paste from cmk server
# cmk_rpm_agent_aarch64: http://url-from-your-agent-bakery-in-checkmk.rpm
# # Copy paste from cmk server
# cmk_deb_agent_aarch64: http://url-from-your-agent-bakery-in-checkmk.deb
# Want to use Samba to download the pre-prepared agents
cmk_download_path: \\fileserver\Software\checkmk-agents\{{ cmk_os_family }}\{{ansible_architecture}}\
cmk_rpm_agent: check-mk-agent-2.0.0p11.noarch.rpm
cmk_deb_agent: check-mk-agent-2.0.0p11_all.deb
cmk_msi_agent: check-mk-agent-2.0.0p11.msi
# Check_MK GPG Key
# Copy paste the link address from Signature Keys for Signing Agents page
@@ -39,3 +57,9 @@ cmk_fresh_install: false
# CheckMK is already installed.
# Breaks idempotence but allows role to be used to force upgrade agents.
cmk_force_install: false
cmk_host_ip: "{{ ansible_host }}"
cmk_dl_needs_auth: true
cmk_debug: True

Binary file not shown.

11
filter_plugins/reslash.py Normal file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env python
def filter_reslash(val):
return val.replace('\\', '/')
class FilterModule(object):
filter_map = {
'reslash': filter_reslash
}
def filters(self):
return self.filter_map

View File

@@ -10,9 +10,29 @@
set_fact:
cmk_fresh_install: True
- name: ensure firewall open
- name: ensure firewall open (rhel)
firewalld:
port: 6556/tcp
state: enabled
permanent: yes
immediate: yes
immediate: yes
ignore_errors: true
when: ansible_os_family == "RedHat"
- name: ensure firewall open (debian)
ufw:
rule: allow
port: 6556
proto: tcp
ignore_errors: true
when: ansible_os_family == "Debian"
- name: remove agent
file:
path: /tmp/check-mk-agent.rpm
state: absent
- name: remove selinux policy file
file:
path: /tmp/checkmk-agent-autoupgrade.pp
state: absent

0
lint Normal file
View File

View File

@@ -1,7 +1,8 @@
galaxy_info:
author: Aaron Guise
description: Install checkmk agent with Enterprise Baked Agent
role_name: check_mk_agent
namespace: cybercinch
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

View File

@@ -14,17 +14,17 @@
- name: Delete Host
uri:
method: POST
url: http://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=delete_host{{ cmk_auth }}
url: https://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=delete_host{{ cmk_auth }}
body: 'request={"hostname":"{{ item.name }}"}'
body_format: raw
status_code: 200
no_log: true
no_log: False
with_items: "{{ molecule_yml.platforms }}"
- 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 }}
url: https://{{ 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

View File

@@ -8,7 +8,11 @@
cmk_omd_site: "{{ lookup('env', 'CMK_OMD_SITE') }}"
cmk_username: "{{ lookup('env', 'CMK_USERNAME') }}"
cmk_secret: "{{ lookup('env', 'CMK_SECRET') }}"
cmk_download_mode: "{{ lookup('env', 'CMK_DOWNLOAD_MODE') }}"
cmk_download_path: "{{ lookup('env', 'CMK_DOWNLOAD_PATH') }}"
cmk_smb_username: "{{ lookup('env', 'CMK_SMB_USERNAME') }}"
cmk_smb_password: "{{ lookup('env', 'CMK_SMB_PASSWORD') }}"
tasks:
- name: "Include ansible-role-cmk-agent"
include_role:
name: "ansible-role-cmk-agent"
name: "ansi-ansible-role-check-mk-agent"

View File

@@ -5,27 +5,30 @@ driver:
name: docker
platforms:
- name: rhel8
image: guisea/centos8-ansible:latest
#dockerfile: Centos8-Dockerfile
image: docker.io/cybercinch/docker-almalinux8-ansible
# dockerfile: Centos8-Dockerfile
privileged: True
volume_mounts:
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
command: "/usr/sbin/init"
command: ${MOLECULE_DOCKER_COMMAND:-"/usr/sbin/init"}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
pre_build_image: true
- name: rhel7
image: guisea/centos7-ansible:latest
# dockerfile: Centos7-Dockerfile
privileged: True
volume_mounts:
volumes:
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
command: "/usr/sbin/init"
pre_build_image: true
provisioner:
name: ansible
log: True
options:
vvv: True
verifier:
name: ansible
lint: |
set -e
yamllint .
ansible-lint
flake8
# lint: |
# set -e
# yamllint .
# ansible-lint
# flake8

View File

@@ -0,0 +1,12 @@
---
- name: Converge
hosts: all
vars:
cmk_rpm_agent: "https://checkmk.ultrafast.co.nz/checkmk-agent/linux/check-mk-agent-2.0.0p12.noarch.rpm"
cmk_dl_needs_auth: false
cmk_add_host: false
cmk_download_mode: "inline"
tasks:
- name: "Include ansible-role-cmk-agent"
include_role:
name: "ansi-ansible-role-check-mk-agent"

View File

@@ -0,0 +1,33 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: rhel8
image: docker.io/tuatahifibre/docker-almalinux8-ansible
privileged: True
command: ${MOLECULE_DOCKER_COMMAND:-"/usr/sbin/init"}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
pre_build_image: true
# - name: rhel7
# image: guisea/centos7-ansible:latest
# # dockerfile: Centos7-Dockerfile
# privileged: True
# volumes:
# - "/sys/fs/cgroup:/sys/fs/cgroup:rw"
# command: "/usr/sbin/init"
# pre_build_image: true
provisioner:
name: ansible
log: True
options:
vvv: True
verifier:
name: ansible
# lint: |
# set -e
# yamllint .
# ansible-lint
# flake8

View File

@@ -0,0 +1,10 @@
---
# This is an example playbook to execute Ansible tests.
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Example assertion
ansible.builtin.assert:
that: true

4
setenv.sh Normal file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Export env vars
export $(grep -v '^#' .env | xargs)

53
tasks/Debian-register.yml Normal file
View File

@@ -0,0 +1,53 @@
- block:
- name: Register with CheckMK Update Server
shell: |
cmk-update-agent register -H {{ instance_name | default(inventory_hostname) }} \
--user {{ cmk_username }} \
--secret {{ cmk_secret }}
changed_when: false
notify: remove agent
tags: cmk_register
- name: Check-In with server
shell: |
cmk-update-agent -v
changed_when: false
notify: remove agent
tags: cmk_register
rescue:
- name: Gather facts of packages
package_facts:
manager: "auto"
tags: cmk_register
- name: Ensure check_mk_agent installed (again)
package:
deb: /tmp/check-mk-agent.deb
state: present
allow_unauthenticated: true
notify:
- restart xinetd
- ensure firewall open
when: "'check-mk-agent' not in ansible_facts.packages"
tags: cmk_register
- name: Gather facts of packages (again)
package_facts:
manager: "auto"
tags: cmk_register
- name: Register with CheckMK Update Server (retry)
shell: |
cmk-update-agent register -H {{ instance_name | default(inventory_hostname) }} --user {{ cmk_username }} \
--secret {{ cmk_secret }}
changed_when: false
when: "'check-mk-agent' in ansible_facts.packages"
notify: remove agent
tags: cmk_register
- name: Check-In with server
shell: |
cmk-update-agent -v
changed_when: false
notify: remove agent
tags: cmk_register

92
tasks/Debian.yml Normal file
View File

@@ -0,0 +1,92 @@
---
# Tasks for installation on RedHat Family
- name: Ensure xinetd installed
package:
name: xinetd
state: present
notify: restart xinetd
- name: Ensure python openssl available
package:
name: python3-openssl,python3-requests
state: present
- name: Fix SeLinux Auto-Updates
block:
- name: list installed selinux modules
command: /usr/sbin/semodule -l
register: installed_mods
- name: check_mk_mod_installed
set_fact:
cmk_mod_installed: True
when: '"checkmk-agent-autoupgrade" in installed_mods.stdout'
- name: copy file
copy:
src: files/checkmk-agent-autoupgrade.pp
dest: /tmp/checkmk-agent-autoupgrade.pp
when: cmk_mod_installed is not defined
- name: install the module
command: /usr/sbin/semodule -i /tmp/checkmk-agent-autoupgrade.pp
when: cmk_mod_installed is not defined
notify: remove selinux policy file
when: ansible_selinux|bool
tags: selinux-pre
- name: Gather facts of packages
package_facts:
manager: "auto"
- name: Remove check-mk if force install
package:
name: check-mk-agent
state: absent
when: "cmk_force_install and 'check-mk-agent' in ansible_facts.packages"
- name: Re-check check-mk-agent status
package_facts:
manager: "auto"
when: cmk_force_install
# Download agent by samba share
- include_tasks: downloads/samba/main.yml
when: cmk_download_mode == 'samba'
- name: Copy installer to node
copy:
src: /tmp/dls/{{ cmk_installer }}
dest: /tmp/check-mk-agent.deb
- name: Install check-mk-agent
block:
- name: Check if check-mk-agent is present on server
stat:
path: /tmp/check-mk-agent.deb
register: cmkdeb
- name: Download the agent from Server
get_url:
url: "{{ cmk_deb_agent }}{{ cmk_auth }}"
dest: /tmp/check-mk-agent.deb
validate_certs: false
when: not cmkdeb.stat.exists and cmk_dl_needs_auth|bool
- name: Download the agent from Server
get_url:
url: "{{ cmk_deb_agent }}"
dest: /tmp/check-mk-agent.deb
validate_certs: false
when: not cmkdeb.stat.exists and not cmk_dl_needs_auth|bool
- name: Ensure check_mk_agent installed
package:
deb: /tmp/check-mk-agent.deb
state: present
allow_unauthenticated: true # Not gpg signed so bypass the check
notify:
- restart xinetd
- cmk fresh install
- ensure firewall open (debian)
when: "'check-mk-agent' not in ansible_facts.packages or cmk_force_install"
tags:
- check_mk_agent

View File

@@ -1,31 +1,74 @@
- block:
- name: Register with CheckMK Update Server
shell: |
cmk-update-agent register -H $(hostname -s) --user {{ cmk_username }} \
cmk-update-agent register -H {{ instance_name | default(inventory_hostname) }} \
--user {{ cmk_username }} \
--secret {{ cmk_secret }}
changed_when: false
notify: remove agent
tags: cmk_register
- name: Check-In with server
shell: |
cmk-update-agent -v
changed_when: false
notify: remove agent
tags: cmk_register
when: cmk_add_host
rescue:
- name: Gather facts of packages
package_facts:
manager: "auto"
tags: cmk_register
- name: Check if dnf package manager is installed
command: which dnf
register: dnf_check
ignore_errors: true
- name: Ensure check_mk_agent installed (again)
package:
name: "{{ cmk_rpm_agent }}{{ cmk_auth }}"
- name: Ensure check_mk_agent installed (again) with dnf
package:
name: /tmp/check-mk-agent.rpm
state: latest
disable_gpg_check: true
notify:
- restart xinetd
- ensure firewall open
when: "'check-mk-agent' not in ansible_facts.packages"
when:
- "'check-mk-agent' not in ansible_facts.packages"
- dnf_check.rc == 0
tags: cmk_register
- name: Ensure check_mk_agent installed (again) with yum
package:
name: /tmp/check-mk-agent.rpm
state: latest
skip_gpg_check: true
notify:
- restart xinetd
- ensure firewall open
when:
- "'check-mk-agent' not in ansible_facts.packages"
- dnf_check.rc != 0
tags: cmk_register
- name: Gather facts of packages (again)
package_facts:
manager: "auto"
tags: cmk_register
- name: Register with CheckMK Update Server (retry)
shell: |
cmk-update-agent register -H $(hostname -s) --user {{ cmk_username }} \
cmk-update-agent register -H {{ instance_name | default(inventory_hostname) }} --user {{ cmk_username }} \
--secret {{ cmk_secret }}
changed_when: false
when: "'check-mk-agent' in ansible_facts.packages"
notify: remove agent
tags: cmk_register
- name: Check-In with server
shell: |
cmk-update-agent -v
changed_when: false
notify: remove agent
tags: cmk_register

View File

@@ -6,21 +6,88 @@
state: present
notify: restart xinetd
- name: Start xinetd
service:
name: xinetd
state: started
- name: Fix SeLinux Auto-Updates
block:
- name: list installed selinux modules
command: /usr/sbin/semodule -l
register: installed_mods
- name: check_mk_mod_installed
set_fact:
cmk_mod_installed: True
when: '"checkmk-agent-autoupgrade" in installed_mods.stdout'
- name: copy file
copy:
src: files/checkmk-agent-autoupgrade.pp
dest: /tmp/checkmk-agent-autoupgrade.pp
when: cmk_mod_installed is not defined
- name: install the module
command: /usr/sbin/semodule -i /tmp/checkmk-agent-autoupgrade.pp
when: cmk_mod_installed is not defined
notify: remove selinux policy file
when: ansible_selinux|bool
tags: selinux-pre
- name: Gather facts of packages
package_facts:
manager: "auto"
- name: Remove check-mk if force install
package:
name: check-mk-agent
state: absent
when: "cmk_force_install and 'check-mk-agent' in ansible_facts.packages"
- name: Re-check check-mk-agent status
package_facts:
manager: "auto"
when: cmk_force_install
# Download agent by samba share
- include_tasks: downloads/samba/main.yml
when: cmk_download_mode == 'samba'
- name: Copy installer to node
copy:
src: /tmp/dls/{{ cmk_installer }}
dest: /tmp/check-mk-agent.rpm
when: cmk_download_mode == 'samba'
- name: Install check-mk-agent
block:
- name: Ensure check_mk_agent installed
block:
- name: Check if check-mk-agent is present on server
stat:
path: /tmp/check-mk-agent.rpm
register: cmkrpm
- name: Download the agent from Server
get_url:
url: "{{ cmk_rpm_agent }}{{ cmk_auth }}"
dest: /tmp/check-mk-agent.rpm
validate_certs: false
when: not cmkrpm.stat.exists and cmk_dl_needs_auth|bool
- name: Download the agent from Server
get_url:
url: "{{ cmk_rpm_agent }}"
dest: /tmp/check-mk-agent.rpm
validate_certs: false
when: not cmkrpm.stat.exists and not cmk_dl_needs_auth|bool
- name: Ensure check_mk_agent installed
package:
name: "{{ cmk_rpm_agent }}{{ cmk_auth }}"
name: /tmp/check-mk-agent.rpm
state: latest
disable_gpg_check: true
disable_gpg_check: true # Not gpg signed so bypass the check
notify:
- restart xinetd
- cmk fresh install
- ensure firewall open
- ensure firewall open (rhel)
when: "'check-mk-agent' not in ansible_facts.packages or cmk_force_install"
tags:
- check_mk_agent

View File

@@ -3,4 +3,5 @@
C:\ProgramData\checkmk\agent\plugins\cmk-update-agent.exe register `
-H $env:computername `
--user {{ cmk_username }} `
--secret {{ cmk_secret }}
--secret {{ cmk_secret }}
tags: cmk_register

View File

@@ -4,11 +4,17 @@
path: "c:/temp/"
state: directory
- name: Obtain information about a file
win_stat:
path: "c:/temp/check-mk-agent.msi"
register: cmkmsi
- name: Retrieve copy of agent
win_get_url:
url: "{{ cmk_msi_agent }}{{ cmk_auth }}"
dest: "c:/temp/check-mk-agent.msi"
changed_when: false
when: not cmkmsi.stat.exists
- name: Ensure agent is installed
win_package:

View File

View File

@@ -0,0 +1,62 @@
---
# These tasks will ensure the control node has the correct packages
# for talking Samba. And then download the required package files.
# Note: This is only to pull them to the control node.
#
# Still needs to be pushed to the guest
- name: Ensure Samba-related packages are installed.
package:
name: "{{ item }}"
state: present
become: True
with_items:
- samba-client
- cifs-utils
delegate_to: localhost
- name: Ensure download path is present
file:
path: /tmp/dls
state: directory
delegate_to: localhost
- name: Set Facts
set_fact:
cmk_download_new: "{{ ( cmk_download_path + '/' + cmk_installer ) | reslash }}"
- name: Some Vars for debuggery
vars:
msg: |
CMK Download Path: {{ cmk_download_path }}
CMK Download Full: '{{ cmk_download_new }}'
CMK Installer: {{ cmk_installer }}
Username: {{ cmk_smb_username }}
Password: {{ cmk_smb_password }}
debug:
msg: "{{ msg.split('\n') }}"
when: cmk_debug
- name: Copy archive from samba_share. (No-Log)
command: >
smbget 'smb:{{ ( cmk_download_path + '/' + cmk_installer ) | reslash }}'
-U '{{ cmk_smb_username }}%{{ cmk_smb_password }}'
args:
chdir: /tmp/dls
creates: /tmp/dls/{{ cmk_installer }}
warn: false # Don't warn of other modules. I want to use smbget ;)
no_log: true # Turn off logging due to password exposure
when: not cmk_debug | bool
delegate_to: localhost
- name: Copy archive from samba_share. (Debug)
command: >
smbget 'smb:{{ ( cmk_download_path + '/' + cmk_installer ) | reslash }}'
-U '{{ cmk_smb_username | trim }}%{{ cmk_smb_password | trim }}'
args:
chdir: /tmp/dls
creates: /tmp/dls/{{ cmk_installer }}
warn: false # Don't warn of other modules. I want to use smbget ;)
no_log: false # Turn off logging due to password exposure
when: cmk_debug | bool
delegate_to: localhost

63
tasks/host-configure.yml Normal file
View File

@@ -0,0 +1,63 @@
---
- name: cmk_discovery
uri:
method: POST
url: "{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=discover_services&mode=refresh{{ cmk_auth }}"
body: 'request={"hostname":"{{ instance_name | default(inventory_hostname) }}"}'
body_format: raw
status_code: 200
validate_certs: no
follow_redirects: yes
become: no
when: "cmk_add_host and output.result_code == 0"
delegate_to: localhost
tags: cmk_register
- name: cmk_apply
uri:
method: POST
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_format: raw
status_code: 200
validate_certs: no
follow_redirects: yes
become: no
run_once: true
when: "cmk_add_host and output.result_code == 0"
delegate_to: localhost
tags: cmk_register
- name: Wait some time
pause:
seconds: 10
- name: cmk_discovery x 2
uri:
method: POST
url: "{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=discover_services&mode=refresh{{ cmk_auth }}"
body: 'request={"hostname":"{{ instance_name | default(inventory_hostname) }}"}'
body_format: raw
status_code: 200
validate_certs: no
follow_redirects: yes
become: no
when: "cmk_add_host and output.result_code == 0"
delegate_to: localhost
tags: cmk_register
- name: cmk_apply
uri:
method: POST
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_format: raw
status_code: 200
validate_certs: no
follow_redirects: yes
become: no
run_once: true
when: "cmk_add_host and output.result_code == 0"
delegate_to: localhost
tags: cmk_register

View File

@@ -8,33 +8,26 @@
"attributes": {
"tag_criticality": "prod",
"tag_agent": "cmk-agent",
"ipaddress": "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
"ipaddress": "{{ cmk_host_ip }}"
},
"folder": "{{ cmk_folder | default('Unsorted') }}",
"hostname": "{{ inventory_hostname }}"
"hostname": "{{ instance_name | default(inventory_hostname) }}"
}
body_format: raw
return_content: yes
validate_certs: no
follow_redirects: yes
register: res
become: no
delegate_to: localhost
when: cmk_add_host
tags: cmk_register
- name: Parse result
set_fact:
output: "{{ res.content | from_json }}"
when: cmk_add_host
- name: cmk_discovery
uri:
method: POST
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_format: raw
status_code: 200
become: no
when: "cmk_add_host and output.result_code == 0"
delegate_to: localhost
tags: cmk_register
- name: cmk_apply
uri:
@@ -43,7 +36,10 @@
body: 'request={"sites":["{{ cmk_omd_site }}"]}'
body_format: raw
status_code: 200
validate_certs: no
follow_redirects: yes
become: no
run_once: true
when: "cmk_add_host and output.result_code == 0"
delegate_to: localhost
tags: cmk_register

View File

@@ -1,9 +1,18 @@
---
# tasks file for ansible-role-cmk-agent
# Include OS Variables
- include_vars: "{{ ansible_os_family }}.yml"
- include_tasks: "{{ ansible_os_family }}.yml"
- meta: flush_handlers
# Add host to checkmk
- include_tasks: host-management.yml
when: cmk_fresh_install
# Register for automatic agent updates
- include_tasks: "{{ ansible_os_family }}-register.yml"
when: cmk_fresh_install
# Finalize things and collect all available services
- include_tasks: host-configure.yml
when: cmk_fresh_install

2
vars/Debian.yml Normal file
View File

@@ -0,0 +1,2 @@
cmk_os_family: linux
cmk_installer: "{{ cmk_deb_agent }}"

2
vars/RedHat.yml Normal file
View File

@@ -0,0 +1,2 @@
cmk_os_family: linux
cmk_installer: "{{ cmk_rpm_agent }}"

2
vars/Windows.yml Normal file
View File

@@ -0,0 +1,2 @@
cmk_os_family: windows
cmk_installer: "{{ cmk_msi_agent }}"