commit 85ce9e0d20ff483f86da0891efb39119a2088472 Author: lhahn Date: Sun Aug 20 11:13:04 2023 +0200 Git initial commit diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..2071b23 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100755 index 0000000..7c7d88f --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# cloud-checkmk + +Ansible role in order to setup a checkmk node for monitoring. \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100755 index 0000000..85f227c --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,28 @@ +--- +cloud_apps: /opt +cloud_storage: /opt/storage +cloud_stage: prod +cloud_update: false + +domain_external: my-domain.tld + + +checkmk_edition: free +checkmk_version: 2.0.0p22 + +checkmk_server_arch: _0.bullseye_amd64.deb +checkmk_server_source: "https://download.checkmk.com/checkmk/{{ checkmk_version }}/check-mk-{{ checkmk_edition }}-{{ checkmk_version }}{{ checkmk_server_arch }}" +checkmk_server_sites: + - monitoring +checkmk_server_host: "{{ domain_external }}" +checkmk_server_scheme: https +# allow requests only from that ip (server), otherwise +# metrics are available from the entire world +checkmk_server_ip: 12.34.56.78 + +checkmk_agent_arch: "-1_all.deb" +checkmk_agent_site: "{{ checkmk_server_sites[0] }}" +checkmk_agent_source: "{{ checkmk_server_scheme }}://{{ checkmk_server_host }}/{{ checkmk_agent_site }}/check_mk/agents/check-mk-agent_{{ checkmk_version }}{{ checkmk_agent_arch }}" + +checkmk_admin_pass: VeryStrongAdminPass +checkmk_is_server: false \ No newline at end of file diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100755 index 0000000..4ed2461 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,10 @@ +--- +- name: restart omd + systemd: + name: omd + state: restarted + +- name: restart xinetd + systemd: + name: xinetd + state: restarted \ No newline at end of file diff --git a/meta/main.yml b/meta/main.yml new file mode 100755 index 0000000..df20d00 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,16 @@ +--- +galaxy_info: + role_name: checkmk + namespace: hahn-cloud + author: Lars Hahn + company: OpenDevChain + license: MIT + description: Role to setup CheckMK as server or agent. + min_ansible_version: 2.7 + platforms: + - name: Debian + versions: + - 11 + galaxy_tags: + - checkmk +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100755 index 0000000..aa12cfa --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,29 @@ +--- +- name: install checkmk server + include_tasks: server.yml + when: checkmk_is_server | bool + +- name: install requirements for checkmk agents + apt: + update_cache: yes + state: "{% if cloud_update | bool %}latest{% else %}present{% endif %}" + install_recommends: yes + pkg: + - xinetd + +- name: install agent from monitoring server + apt: + deb: "{{ checkmk_agent_source }}" + state: "{% if cloud_update | bool %}latest{% else %}present{% endif %}" + install_recommends: yes + ignore_errors: yes + # if the monitoring server is not fast enough online... + +- name: restrict metrics access via xinetd only for montoring server + lineinfile: + path: "/etc/xinetd.d/check_mk" + regexp: '^\s*#?only_from\s*=' + line: "\tonly_from = {{ checkmk_server_ip }}" + ignore_errors: yes # if the monitoring server is not fast enough online... + notify: restart xinetd + diff --git a/tasks/server.yml b/tasks/server.yml new file mode 100755 index 0000000..a1a5741 --- /dev/null +++ b/tasks/server.yml @@ -0,0 +1,45 @@ +--- +- name: install requirements for checkmk + apt: + update_cache: yes + state: "{% if cloud_update | bool %}latest{% else %}present{% endif %}" + install_recommends: yes + pkg: + - python3-passlib + + +- name: install checkmk from deb file + apt: + deb: "{{ checkmk_server_source }}" + state: "{% if cloud_update | bool %}latest{% else %}present{% endif %}" + install_recommends: yes + +# apache2 is default installed via e.g. deb file +# in order to run e.g. nginx as webserver, we should disable it +- name: adjust apache2 systemd unit state + systemd: + name: apache2 + enabled: "{{ checkmk_system_apache2 | default('no') | bool }}" + daemon_reload: yes + +- name: generate checkmk sites + command: + cmd: "omd create {{ item }}" + creates: "/omd/sites/{{ item }}" + notify: restart omd + loop: "{{ checkmk_server_sites }}" + +- name: setup admin password for sites + htpasswd: + path: "/omd/sites/{{ cmk_site }}/etc/htpasswd" + name: "{{ checkmk_admin_user }}" + password: "{{ checkmk_admin_pass }}" + owner: "{{ cmk_site }}" + group: "{{ cmk_site }}" + mode: 0660 + become: yes + become_user: "{{ cmk_site }}" + loop: "{{ checkmk_server_sites }}" + loop_control: + loop_var: cmk_site + label: "site: {{ cmk_site }}" \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml new file mode 100755 index 0000000..3f4ca97 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +checkmk_admin_user: cmkadmin