You've already forked role-check-mk-agent
Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b2190da07c | |||
| dfb2254d2b | |||
|
|
8035c87efe | ||
| 1c29992d07 | |||
| 841bfc2eec | |||
| 1efc90e172 | |||
| 00d4100a3c | |||
| fba7559a02 | |||
| a4588f6e62 | |||
| 42a461001f | |||
| 67b6952ba8 | |||
| fcb04bcfae | |||
| 23c945b9b8 | |||
| 342fec8955 | |||
| 3d39f3e231 | |||
| c41c2dc447 | |||
| 602656dde5 | |||
| c449ae2435 | |||
| ba1ae0a121 | |||
| 965a6aa99f | |||
| b647ff7d9b | |||
| 718f31bd59 | |||
| ed0fc10161 | |||
| d899964718 | |||
| 2e719ccc9b | |||
| 99af4c4a86 | |||
| 2ae40a30a9 | |||
| 59d43f8112 | |||
| f4809d2ed7 | |||
| 14cb3f66e3 | |||
| 0b3eeddaf9 | |||
| 957795b4fe | |||
| 294df3f441 | |||
| 067b64947c | |||
| 094cce6b01 | |||
| 02daa0b30c | |||
| b56c03a3c3 | |||
| 2de6c9efad | |||
| 5ed5818aff | |||
| 08a725ed68 | |||
| 438962933f | |||
| 61a0209ece | |||
| 7530f82e62 | |||
| a71bcb9638 | |||
| 04a23c4976 | |||
| 445642b193 | |||
| 92386dbd09 | |||
| a67d4af041 | |||
| 396fdf006b |
@@ -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
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
__pycache__
|
||||
@@ -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
|
||||
|
||||
BIN
files/checkmk-agent-autoupgrade.pp
Normal file
BIN
files/checkmk-agent-autoupgrade.pp
Normal file
Binary file not shown.
11
filter_plugins/reslash.py
Normal file
11
filter_plugins/reslash.py
Normal 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
|
||||
@@ -10,12 +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
|
||||
ignore_errors: true
|
||||
when: ansible_os_family == "RedHat"
|
||||
|
||||
- name: ensure firewall reloaded
|
||||
command: firewall-cmd --reload
|
||||
changed_when: false
|
||||
- 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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
12
molecule/http_direct/converge.yml
Normal file
12
molecule/http_direct/converge.yml
Normal 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"
|
||||
33
molecule/http_direct/molecule.yml
Normal file
33
molecule/http_direct/molecule.yml
Normal 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
|
||||
10
molecule/http_direct/verify.yml
Normal file
10
molecule/http_direct/verify.yml
Normal 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
4
setenv.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Export env vars
|
||||
export $(grep -v '^#' .env | xargs)
|
||||
53
tasks/Debian-register.yml
Normal file
53
tasks/Debian-register.yml
Normal 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
92
tasks/Debian.yml
Normal 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
|
||||
@@ -1,5 +1,74 @@
|
||||
- name: Register with CheckMK Update Server
|
||||
shell: |
|
||||
cmk-update-agent register -H $(hostname -s) --user {{ cmk_username }} \
|
||||
--secret {{ cmk_secret }}
|
||||
changed_when: false
|
||||
- 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
|
||||
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) 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"
|
||||
- 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 {{ 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
|
||||
@@ -1,36 +1,93 @@
|
||||
---
|
||||
# Tasks for installation on RedHat Family
|
||||
- name: Ensure xinetd installed
|
||||
yum:
|
||||
package:
|
||||
name: xinetd
|
||||
state: installed
|
||||
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: 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
|
||||
yum:
|
||||
package:
|
||||
name: /tmp/check-mk-agent.rpm
|
||||
state: installed
|
||||
disable_gpg_check: true
|
||||
state: latest
|
||||
disable_gpg_check: true # Not gpg signed so bypass the check
|
||||
notify:
|
||||
- restart xinetd
|
||||
- cmk fresh install
|
||||
- ensure firewall open
|
||||
|
||||
- name: Remove agent Download
|
||||
file:
|
||||
path: /tmp/check-mk-agent.rpm
|
||||
state: absent
|
||||
- ensure firewall open (rhel)
|
||||
when: "'check-mk-agent' not in ansible_facts.packages or cmk_force_install"
|
||||
tags:
|
||||
- check_mk_agent
|
||||
|
||||
@@ -4,3 +4,4 @@
|
||||
-H $env:computername `
|
||||
--user {{ cmk_username }} `
|
||||
--secret {{ cmk_secret }}
|
||||
tags: cmk_register
|
||||
@@ -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:
|
||||
|
||||
0
tasks/downloads/http/.gitkeep
Normal file
0
tasks/downloads/http/.gitkeep
Normal file
62
tasks/downloads/samba/main.yml
Normal file
62
tasks/downloads/samba/main.yml
Normal 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
63
tasks/host-configure.yml
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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
2
vars/Debian.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
cmk_os_family: linux
|
||||
cmk_installer: "{{ cmk_deb_agent }}"
|
||||
2
vars/RedHat.yml
Normal file
2
vars/RedHat.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
cmk_os_family: linux
|
||||
cmk_installer: "{{ cmk_rpm_agent }}"
|
||||
2
vars/Windows.yml
Normal file
2
vars/Windows.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
cmk_os_family: windows
|
||||
cmk_installer: "{{ cmk_msi_agent }}"
|
||||
Reference in New Issue
Block a user