From 001db69fe01bfda582785ca42e93d328ae4a154a Mon Sep 17 00:00:00 2001 From: abrown38 Date: Wed, 4 Dec 2024 10:05:31 +0000 Subject: [PATCH] reworked to register hosts for TLS with the server --- ansible/playbooks/checkmk.yml | 114 ++++++++++++++++++++++------------ 1 file changed, 76 insertions(+), 38 deletions(-) diff --git a/ansible/playbooks/checkmk.yml b/ansible/playbooks/checkmk.yml index f315106..8d4bb18 100644 --- a/ansible/playbooks/checkmk.yml +++ b/ansible/playbooks/checkmk.yml @@ -1,4 +1,72 @@ --- +- name: CheckMK Hosts + hosts: "meta-win_project_{{ win_project }}:&meta-os_windows" + gather_facts: false + vars_files: + - ../vars/checkmk.yml + - ../vars/common.yml + tasks: + - name: "Create folder for eidf project" + checkmk.general.folder: + server_url: "{{ checkmk_agent_protocol }}://{{ checkmk_server }}:80/" + site: "{{ checkmk_agent_site }}" + automation_user: "{{ checkmk_agent_user }}" + automation_secret: "{{ checkmk_password }}" + path: "/{{ os_project }}-{{ win_project }}" + name: "{{ os_project }}-{{ win_project }}" + state: "{{ state }}" # might need to create hosts them move so teardown works??? or leave folder after teardown or add only teardown task after + run_once: true + delegate_to: "localhost" + tags: + - checkmk_host + - checkmk_all + + - name: Add Windows host into check + checkmk.general.host: + server_url: "{{ checkmk_agent_protocol }}://{{ checkmk_server }}:80/" + site: "{{ checkmk_agent_site }}" + validate_certs: "true" + automation_user: "{{ checkmk_agent_user }}" + automation_secret: "{{ checkmk_password }}" + folder: "/{{ os_project }}-{{ win_project }}" + name: "{{ inventory_hostname }}" + attributes: + ipaddress: "{{ hostvars[inventory_hostname].ansible_host }}" + state: "{{ state }}" + delegate_to: "localhost" + notify: "activate changes" + tags: + - checkmk_host + - checkmk_all + + - name: "Create folder for eidf project" + checkmk.general.folder: + server_url: "{{ checkmk_agent_protocol }}://{{ checkmk_server }}:80/" + site: "{{ checkmk_agent_site }}" + automation_user: "{{ checkmk_agent_user }}" + automation_secret: "{{ checkmk_password }}" + path: "/{{ os_project }}-{{ win_project }}" + name: "{{ os_project }}-{{ win_project }}" + state: "{{ state }}" # might need to create hosts them move so teardown works??? or leave folder after teardown or add only teardown task after + run_once: true + notify: "activate changes" + delegate_to: "localhost" + tags: + - teardown + + handlers: + - name: "Activate Changes" + listen: activate changes + checkmk.general.activation: + server_url: "{{ checkmk_agent_protocol }}://{{ checkmk_server }}:80/" + site: "{{ checkmk_agent_site }}" + automation_user: "{{ checkmk_agent_user }}" + automation_secret: "{{ checkmk_password }}" + force_foreign_changes: "false" + validate_certs: "true" + delegate_to: "localhost" + run_once: true + - name: CheckMK Agent hosts: "meta-win_project_{{ win_project }}:&meta-os_windows" gather_facts: false @@ -24,41 +92,11 @@ - checkmk_all - checkmk_agent -- name: CheckMK Hosts - hosts: "meta-win_project_{{ win_project }}:&meta-os_windows" - gather_facts: false - vars_files: - - ../vars/checkmk.yml - - ../vars/common.yml - tasks: - - name: Add Windows host into check - checkmk.general.host: - server_url: "{{ checkmk_agent_protocol }}://{{ checkmk_server }}:80/" - site: "{{ checkmk_agent_site }}" - validate_certs: "true" - automation_user: "{{ checkmk_agent_user }}" - automation_secret: "{{ checkmk_password }}" - folder: "/" - name: "{{ inventory_hostname }}" - attributes: - ipaddress: "{{ hostvars[inventory_hostname].ansible_host }}" - state: "{{ state }}" - delegate_to: "localhost" - notify: "activate changes" - tags: - - checkmk_host - - checkmk_all - - teardown - - handlers: - - name: "Activate Changes" - listen: activate changes - checkmk.general.activation: - server_url: "{{ checkmk_agent_protocol }}://{{ checkmk_server }}:80/" - site: "{{ checkmk_agent_site }}" - automation_user: "{{ checkmk_agent_user }}" - automation_secret: "{{ checkmk_password }}" - force_foreign_changes: "false" - validate_certs: "true" - delegate_to: "localhost" - run_once: true \ No newline at end of file + - name: register for TLS + win_shell: | + sl 'C:\Program Files (x86)\checkmk\service' + .\cmk-agent-ctl register --hostname {{ inventory_hostname }} --server {{ checkmk_server }} --site {{ checkmk_agent_site }} --user {{ checkmk_agent_user }} --password '{{ checkmk_password }}' --trust-cert + tags: + - checkmk_host + - checkmk_tls + - checkmk_all \ No newline at end of file