13 Commits

8 changed files with 75 additions and 34 deletions

View File

@@ -1,2 +1,3 @@
FROM docker.io/pycontribs/centos:7
RUN yum install -y iproute
RUN yum install -y iproute firewalld python-firewall net-tools && \
systemctl enable firewalld

7
Centos8-Dockerfile Normal file
View File

@@ -0,0 +1,7 @@
# Centos8-Dockerfile
FROM docker.io/pycontribs/centos:8
RUN yum install -y iproute firewalld net-tools && \
sed -i 's/FirewallBackend=nftables/FirewallBackend=iptables/' /etc/firewalld/firewalld.conf && \
sed -i 's/IPv6_rpfilter=yes/IPv6_rpfilter=no/' /etc/firewalld/firewalld.conf && \
systemctl enable firewalld

View File

@@ -1,14 +1,24 @@
---
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_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
# uncomment cmk_folder below and specify the folder to use. Otherwise the role creates and
# adds new hosts by default to Unsorted folder
# 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
# Check_MK GPG Key
# Copy paste the link address from Signature Keys for Signing Agents page
cmk_gpg_key_id: 1
cmk_gpg_key_url: "{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/wato.py?key={{ cmk_gpg_key_id }}&mode=download_signature_key"
# Should be username of an automation user in checkmk
cmk_username: some-username
@@ -17,6 +27,7 @@ cmk_username: some-username
# I recommend encrypting this with ansible-vault.
# Example: ansible-vault encrypt_string somesecret_string --name cmk_secret
cmk_secret: some-secret
# Combined string required for unattended actions
cmk_auth: "&_username={{ cmk_username }}&_secret={{ cmk_secret }}"

View File

@@ -9,3 +9,10 @@
- name: cmk fresh install
set_fact:
cmk_fresh_install: True
- name: ensure firewall open
firewalld:
port: 6556/tcp
state: enabled
permanent: yes
immediate: yes

View File

@@ -5,20 +5,21 @@ driver:
name: docker
platforms:
- name: rhel8
image: docker.io/pycontribs/centos:8
image: guisea/centos8-ansible:latest
#dockerfile: Centos8-Dockerfile
privileged: True
volume_mounts:
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
command: "/usr/sbin/init"
pre_build_image: true
- name: rhel7
image: docker.io/pycontribs/centos:7
dockerfile: Centos7-Dockerfile
image: guisea/centos7-ansible:latest
# dockerfile: Centos7-Dockerfile
privileged: True
volume_mounts:
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
command: "/usr/sbin/init"
pre_build_image: false
pre_build_image: true
provisioner:
name: ansible
verifier:

View File

@@ -1,5 +1,31 @@
- name: Register with CheckMK Update Server
- block:
- name: Register with CheckMK Update Server
shell: |
cmk-update-agent register -H $(hostname -s) --user {{ cmk_username }} \
--secret {{ cmk_secret }}
changed_when: false
rescue:
- name: Gather facts of packages
package_facts:
manager: "auto"
- name: Ensure check_mk_agent installed (again)
package:
name: "{{ cmk_rpm_agent }}{{ cmk_auth }}"
state: latest
disable_gpg_check: true
notify:
- restart xinetd
- ensure firewall open
when: "'check-mk-agent' not in ansible_facts.packages"
- name: Gather facts of packages (again)
package_facts:
manager: "auto"
- name: Register with CheckMK Update Server (retry)
shell: |
cmk-update-agent register -H $(hostname -s) --user {{ cmk_username }} \
--secret {{ cmk_secret }}
changed_when: false
when: "'check-mk-agent' in ansible_facts.packages"

View File

@@ -1,9 +1,9 @@
---
# Tasks for installation on RedHat Family
- name: Ensure xinetd installed
yum:
package:
name: xinetd
state: installed
state: present
notify: restart xinetd
- name: Gather facts of packages
@@ -12,23 +12,15 @@
- 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
package:
name: "{{ cmk_rpm_agent }}{{ cmk_auth }}"
state: latest
disable_gpg_check: true
notify:
- restart xinetd
- cmk fresh install
- name: Remove agent Download
file:
path: /tmp/check-mk-agent.rpm
state: absent
- ensure firewall open
when: "'check-mk-agent' not in ansible_facts.packages or cmk_force_install"
tags:
- check_mk_agent

View File

@@ -2,7 +2,7 @@
- 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 }}"
url: "{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/webapi.py?action=add_host{{ cmk_auth }}"
body: |
request={
"attributes": {
@@ -25,14 +25,10 @@
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 }}
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
@@ -43,7 +39,7 @@
- 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: "{{ 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