From 26fa95374163fb68701f70cf44dccdde1647f2ef Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Thu, 20 Apr 2023 14:29:55 +0200 Subject: [PATCH 01/11] Add molecule tests for agent role. --- roles/agent/molecule/2.0.0/converge.yml | 37 ++++++++ roles/agent/molecule/2.0.0/group_vars/all.yml | 60 +++++++++++++ roles/agent/molecule/2.0.0/molecule.yml | 88 +++++++++++++++++++ roles/agent/molecule/2.0.0/verify.yml | 31 +++++++ roles/agent/molecule/2.1.0/converge.yml | 37 ++++++++ roles/agent/molecule/2.1.0/group_vars/all.yml | 60 +++++++++++++ roles/agent/molecule/2.1.0/molecule.yml | 88 +++++++++++++++++++ roles/agent/molecule/2.1.0/verify.yml | 31 +++++++ roles/agent/molecule/2.2.0/converge.yml | 37 ++++++++ roles/agent/molecule/2.2.0/group_vars/all.yml | 60 +++++++++++++ roles/agent/molecule/2.2.0/molecule.yml | 88 +++++++++++++++++++ roles/agent/molecule/2.2.0/verify.yml | 31 +++++++ 12 files changed, 648 insertions(+) create mode 100644 roles/agent/molecule/2.0.0/converge.yml create mode 100644 roles/agent/molecule/2.0.0/group_vars/all.yml create mode 100644 roles/agent/molecule/2.0.0/molecule.yml create mode 100644 roles/agent/molecule/2.0.0/verify.yml create mode 100644 roles/agent/molecule/2.1.0/converge.yml create mode 100644 roles/agent/molecule/2.1.0/group_vars/all.yml create mode 100644 roles/agent/molecule/2.1.0/molecule.yml create mode 100644 roles/agent/molecule/2.1.0/verify.yml create mode 100644 roles/agent/molecule/2.2.0/converge.yml create mode 100644 roles/agent/molecule/2.2.0/group_vars/all.yml create mode 100644 roles/agent/molecule/2.2.0/molecule.yml create mode 100644 roles/agent/molecule/2.2.0/verify.yml diff --git a/roles/agent/molecule/2.0.0/converge.yml b/roles/agent/molecule/2.0.0/converge.yml new file mode 100644 index 000000000..afae38a08 --- /dev/null +++ b/roles/agent/molecule/2.0.0/converge.yml @@ -0,0 +1,37 @@ +--- +- name: Converge + hosts: all + + pre_tasks: + + - name: "Update apt cache." + ansible.builtin.apt: + update_cache: true + cache_valid_time: 600 + when: ansible_os_family == 'Debian' + - name: Install prerequisites. + ansible.builtin.apt: + name: "{{ item }}" + state: present + loop: + - apt-utils + - man + when: ansible_os_family == 'Debian' + - name: Create '/usr/share/man/man8/' on Ubuntu. + ansible.builtin.file: + path: /usr/share/man/man8/ + state: directory + mode: "0755" + owner: root + group: root + when: ansible_distribution == 'Ubuntu' + + tasks: + + - name: "Run server role." + ansible.builtin.include_role: + name: server + + - name: "Run agent role." + ansible.builtin.include_role: + name: agent diff --git a/roles/agent/molecule/2.0.0/group_vars/all.yml b/roles/agent/molecule/2.0.0/group_vars/all.yml new file mode 100644 index 000000000..3a6d9cfa1 --- /dev/null +++ b/roles/agent/molecule/2.0.0/group_vars/all.yml @@ -0,0 +1,60 @@ +--- +# General +checkmk_version: "2.0.0p35" +checkmk_edition: "cre" +checkmk_site: "my_site" +automation_user: "cmkadmin" +automation_secret: "d7589df1-01db-4eda-9858-dbcff8d0c361" + +# Agent Role +checkmk_agent_version: "{{ checkmk_version }}" +checkmk_agent_edition: "{{ checkmk_edition }}" +checkmk_agent_protocol: http +checkmk_agent_server: localhost +checkmk_agent_site: "{{ checkmk_site }}" +checkmk_agent_registration_server: "{{ checkmk_agent_server }}" +checkmk_agent_registration_site: "{{ checkmk_agent_site }}" +checkmk_agent_server_validate_certs: 'false' +checkmk_agent_port: "{% if checkmk_agent_protocol == 'https' %}443{% else %}80{% endif %}" +checkmk_agent_user: "{{ automation_user | default('automation') }}" + +# Depending on which user you will be using, set the password or secret: +# checkmk_agent_pass: "{{ automation_secret }}" +checkmk_agent_secret: "{{ automation_secret }}" + +checkmk_agent_auto_activate: 'false' +checkmk_agent_add_host: 'false' +checkmk_agent_discover: 'false' +checkmk_agent_update: 'false' +checkmk_agent_tls: 'false' +checkmk_agent_configure_firewall: 'false' +checkmk_agent_force_install: 'false' +checkmk_agent_prep_legacy: 'false' +checkmk_agent_delegate_api_calls: localhost +checkmk_agent_delegate_download: "{{ inventory_hostname }}" +checkmk_agent_host_name: "{{ inventory_hostname }}" +checkmk_agent_folder: "{{ checkmk_folder_path | default('/') }}" +checkmk_agent_force_foreign_changes: 'false' +checkmk_agent_host_attributes: + ipaddress: 127.0.0.1 + +# If you trust your local hostnames, you could also use the following +# to use the local hostname instead of the inventory hostname: +# checkmk_agent_host_name: "{{ hostvars[inventory_hostname]['ansible_fqdn'] }}" +# Checkmk does not need an IP address, as long as the hostname is DNS-resolvable + +# If that does not apply to your environment, you can configure the IP address below: +# checkmk_agent_host_ip: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}" + +# Server Role + +checkmk_server_edition: "{{ checkmk_edition }}" +checkmk_server_version: "{{ checkmk_version }}" +checkmk_server_verify_setup: 'true' + +checkmk_server_sites: + - name: "{{ checkmk_site }}" + version: "{{ checkmk_version }}" + state: started + admin_pw: cmk + update_conflict_resolution: install diff --git a/roles/agent/molecule/2.0.0/molecule.yml b/roles/agent/molecule/2.0.0/molecule.yml new file mode 100644 index 000000000..19d9c24bf --- /dev/null +++ b/roles/agent/molecule/2.0.0/molecule.yml @@ -0,0 +1,88 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: ubuntu1804 + image: geerlingguy/docker-ubuntu1804-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: ubuntu2004 + image: geerlingguy/docker-ubuntu2004-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: ubuntu2204 + image: geerlingguy/docker-ubuntu2204-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: debian10 + image: geerlingguy/docker-debian10-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: debian11 + image: geerlingguy/docker-debian11-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: centos7 + image: geerlingguy/docker-centos7-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: centos8 + image: geerlingguy/docker-centos8-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true +provisioner: + name: ansible +verifier: + name: ansible +scenario: + test_sequence: + - dependency + - lint + - cleanup + - destroy + - syntax + - create + - prepare + - converge + # - idempotence # disable for now, as we have non-idempotent tasks + - side_effect + - verify + - cleanup + - destroy diff --git a/roles/agent/molecule/2.0.0/verify.yml b/roles/agent/molecule/2.0.0/verify.yml new file mode 100644 index 000000000..79fce6e30 --- /dev/null +++ b/roles/agent/molecule/2.0.0/verify.yml @@ -0,0 +1,31 @@ +--- +- name: Verify + hosts: all + gather_facts: false + tasks: + + - name: Populate service facts. + ansible.builtin.service_facts: + + - name: "Test Agent is present." + ansible.builtin.stat: + path: "/usr/bin/check_mk_agent" + register: checkmk_agent_file + + - name: "Verify Agent is present." + ansible.builtin.assert: + that: checkmk_agent_file.stat.exists | bool + + - name: "Test Agent Service is running." + ansible.builtin.assert: + that: "'check-mk-agent-async.service' in ansible_facts.services" + + - name: "Test that the Agent is listening on the default Port." + ansible.builtin.wait_for: + port: 6556 + connect_timeout: 30 + register: checkmk_agent_port + + - name: "Test Agent Service is listening on port 6556." + ansible.builtin.assert: + that: "(checkmk_agent_port.port == 6556) and (checkmk_agent_port.state == 'started')" diff --git a/roles/agent/molecule/2.1.0/converge.yml b/roles/agent/molecule/2.1.0/converge.yml new file mode 100644 index 000000000..afae38a08 --- /dev/null +++ b/roles/agent/molecule/2.1.0/converge.yml @@ -0,0 +1,37 @@ +--- +- name: Converge + hosts: all + + pre_tasks: + + - name: "Update apt cache." + ansible.builtin.apt: + update_cache: true + cache_valid_time: 600 + when: ansible_os_family == 'Debian' + - name: Install prerequisites. + ansible.builtin.apt: + name: "{{ item }}" + state: present + loop: + - apt-utils + - man + when: ansible_os_family == 'Debian' + - name: Create '/usr/share/man/man8/' on Ubuntu. + ansible.builtin.file: + path: /usr/share/man/man8/ + state: directory + mode: "0755" + owner: root + group: root + when: ansible_distribution == 'Ubuntu' + + tasks: + + - name: "Run server role." + ansible.builtin.include_role: + name: server + + - name: "Run agent role." + ansible.builtin.include_role: + name: agent diff --git a/roles/agent/molecule/2.1.0/group_vars/all.yml b/roles/agent/molecule/2.1.0/group_vars/all.yml new file mode 100644 index 000000000..4c18d64af --- /dev/null +++ b/roles/agent/molecule/2.1.0/group_vars/all.yml @@ -0,0 +1,60 @@ +--- +# General +checkmk_version: "2.1.0p26" +checkmk_edition: "cre" +checkmk_site: "my_site" +automation_user: "cmkadmin" +automation_secret: "d7589df1-01db-4eda-9858-dbcff8d0c361" + +# Agent Role +checkmk_agent_version: "{{ checkmk_version }}" +checkmk_agent_edition: "{{ checkmk_edition }}" +checkmk_agent_protocol: http +checkmk_agent_server: localhost +checkmk_agent_site: "{{ checkmk_site }}" +checkmk_agent_registration_server: "{{ checkmk_agent_server }}" +checkmk_agent_registration_site: "{{ checkmk_agent_site }}" +checkmk_agent_server_validate_certs: 'false' +checkmk_agent_port: "{% if checkmk_agent_protocol == 'https' %}443{% else %}80{% endif %}" +checkmk_agent_user: "{{ automation_user | default('automation') }}" + +# Depending on which user you will be using, set the password or secret: +# checkmk_agent_pass: "{{ automation_secret }}" +checkmk_agent_secret: "{{ automation_secret }}" + +checkmk_agent_auto_activate: 'false' +checkmk_agent_add_host: 'false' +checkmk_agent_discover: 'false' +checkmk_agent_update: 'false' +checkmk_agent_tls: 'false' +checkmk_agent_configure_firewall: 'false' +checkmk_agent_force_install: 'false' +checkmk_agent_prep_legacy: 'false' +checkmk_agent_delegate_api_calls: localhost +checkmk_agent_delegate_download: "{{ inventory_hostname }}" +checkmk_agent_host_name: "{{ inventory_hostname }}" +checkmk_agent_folder: "{{ checkmk_folder_path | default('/') }}" +checkmk_agent_force_foreign_changes: 'false' +checkmk_agent_host_attributes: + ipaddress: 127.0.0.1 + +# If you trust your local hostnames, you could also use the following +# to use the local hostname instead of the inventory hostname: +# checkmk_agent_host_name: "{{ hostvars[inventory_hostname]['ansible_fqdn'] }}" +# Checkmk does not need an IP address, as long as the hostname is DNS-resolvable + +# If that does not apply to your environment, you can configure the IP address below: +# checkmk_agent_host_ip: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}" + +# Server Role + +checkmk_server_edition: "{{ checkmk_edition }}" +checkmk_server_version: "{{ checkmk_version }}" +checkmk_server_verify_setup: 'true' + +checkmk_server_sites: + - name: "{{ checkmk_site }}" + version: "{{ checkmk_version }}" + state: started + admin_pw: cmk + update_conflict_resolution: install diff --git a/roles/agent/molecule/2.1.0/molecule.yml b/roles/agent/molecule/2.1.0/molecule.yml new file mode 100644 index 000000000..19d9c24bf --- /dev/null +++ b/roles/agent/molecule/2.1.0/molecule.yml @@ -0,0 +1,88 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: ubuntu1804 + image: geerlingguy/docker-ubuntu1804-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: ubuntu2004 + image: geerlingguy/docker-ubuntu2004-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: ubuntu2204 + image: geerlingguy/docker-ubuntu2204-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: debian10 + image: geerlingguy/docker-debian10-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: debian11 + image: geerlingguy/docker-debian11-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: centos7 + image: geerlingguy/docker-centos7-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: centos8 + image: geerlingguy/docker-centos8-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true +provisioner: + name: ansible +verifier: + name: ansible +scenario: + test_sequence: + - dependency + - lint + - cleanup + - destroy + - syntax + - create + - prepare + - converge + # - idempotence # disable for now, as we have non-idempotent tasks + - side_effect + - verify + - cleanup + - destroy diff --git a/roles/agent/molecule/2.1.0/verify.yml b/roles/agent/molecule/2.1.0/verify.yml new file mode 100644 index 000000000..79fce6e30 --- /dev/null +++ b/roles/agent/molecule/2.1.0/verify.yml @@ -0,0 +1,31 @@ +--- +- name: Verify + hosts: all + gather_facts: false + tasks: + + - name: Populate service facts. + ansible.builtin.service_facts: + + - name: "Test Agent is present." + ansible.builtin.stat: + path: "/usr/bin/check_mk_agent" + register: checkmk_agent_file + + - name: "Verify Agent is present." + ansible.builtin.assert: + that: checkmk_agent_file.stat.exists | bool + + - name: "Test Agent Service is running." + ansible.builtin.assert: + that: "'check-mk-agent-async.service' in ansible_facts.services" + + - name: "Test that the Agent is listening on the default Port." + ansible.builtin.wait_for: + port: 6556 + connect_timeout: 30 + register: checkmk_agent_port + + - name: "Test Agent Service is listening on port 6556." + ansible.builtin.assert: + that: "(checkmk_agent_port.port == 6556) and (checkmk_agent_port.state == 'started')" diff --git a/roles/agent/molecule/2.2.0/converge.yml b/roles/agent/molecule/2.2.0/converge.yml new file mode 100644 index 000000000..afae38a08 --- /dev/null +++ b/roles/agent/molecule/2.2.0/converge.yml @@ -0,0 +1,37 @@ +--- +- name: Converge + hosts: all + + pre_tasks: + + - name: "Update apt cache." + ansible.builtin.apt: + update_cache: true + cache_valid_time: 600 + when: ansible_os_family == 'Debian' + - name: Install prerequisites. + ansible.builtin.apt: + name: "{{ item }}" + state: present + loop: + - apt-utils + - man + when: ansible_os_family == 'Debian' + - name: Create '/usr/share/man/man8/' on Ubuntu. + ansible.builtin.file: + path: /usr/share/man/man8/ + state: directory + mode: "0755" + owner: root + group: root + when: ansible_distribution == 'Ubuntu' + + tasks: + + - name: "Run server role." + ansible.builtin.include_role: + name: server + + - name: "Run agent role." + ansible.builtin.include_role: + name: agent diff --git a/roles/agent/molecule/2.2.0/group_vars/all.yml b/roles/agent/molecule/2.2.0/group_vars/all.yml new file mode 100644 index 000000000..089885a55 --- /dev/null +++ b/roles/agent/molecule/2.2.0/group_vars/all.yml @@ -0,0 +1,60 @@ +--- +# General +checkmk_version: "2.2.0b4" +checkmk_edition: "cre" +checkmk_site: "my_site" +automation_user: "cmkadmin" +automation_secret: "d7589df1-01db-4eda-9858-dbcff8d0c361" + +# Agent Role +checkmk_agent_version: "{{ checkmk_version }}" +checkmk_agent_edition: "{{ checkmk_edition }}" +checkmk_agent_protocol: http +checkmk_agent_server: localhost +checkmk_agent_site: "{{ checkmk_site }}" +checkmk_agent_registration_server: "{{ checkmk_agent_server }}" +checkmk_agent_registration_site: "{{ checkmk_agent_site }}" +checkmk_agent_server_validate_certs: 'false' +checkmk_agent_port: "{% if checkmk_agent_protocol == 'https' %}443{% else %}80{% endif %}" +checkmk_agent_user: "{{ automation_user | default('automation') }}" + +# Depending on which user you will be using, set the password or secret: +# checkmk_agent_pass: "{{ automation_secret }}" +checkmk_agent_secret: "{{ automation_secret }}" + +checkmk_agent_auto_activate: 'false' +checkmk_agent_add_host: 'false' +checkmk_agent_discover: 'false' +checkmk_agent_update: 'false' +checkmk_agent_tls: 'false' +checkmk_agent_configure_firewall: 'false' +checkmk_agent_force_install: 'false' +checkmk_agent_prep_legacy: 'false' +checkmk_agent_delegate_api_calls: localhost +checkmk_agent_delegate_download: "{{ inventory_hostname }}" +checkmk_agent_host_name: "{{ inventory_hostname }}" +checkmk_agent_folder: "{{ checkmk_folder_path | default('/') }}" +checkmk_agent_force_foreign_changes: 'false' +checkmk_agent_host_attributes: + ipaddress: 127.0.0.1 + +# If you trust your local hostnames, you could also use the following +# to use the local hostname instead of the inventory hostname: +# checkmk_agent_host_name: "{{ hostvars[inventory_hostname]['ansible_fqdn'] }}" +# Checkmk does not need an IP address, as long as the hostname is DNS-resolvable + +# If that does not apply to your environment, you can configure the IP address below: +# checkmk_agent_host_ip: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}" + +# Server Role + +checkmk_server_edition: "{{ checkmk_edition }}" +checkmk_server_version: "{{ checkmk_version }}" +checkmk_server_verify_setup: 'true' + +checkmk_server_sites: + - name: "{{ checkmk_site }}" + version: "{{ checkmk_version }}" + state: started + admin_pw: cmk + update_conflict_resolution: install diff --git a/roles/agent/molecule/2.2.0/molecule.yml b/roles/agent/molecule/2.2.0/molecule.yml new file mode 100644 index 000000000..19d9c24bf --- /dev/null +++ b/roles/agent/molecule/2.2.0/molecule.yml @@ -0,0 +1,88 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: ubuntu1804 + image: geerlingguy/docker-ubuntu1804-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: ubuntu2004 + image: geerlingguy/docker-ubuntu2004-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: ubuntu2204 + image: geerlingguy/docker-ubuntu2204-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: debian10 + image: geerlingguy/docker-debian10-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: debian11 + image: geerlingguy/docker-debian11-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: centos7 + image: geerlingguy/docker-centos7-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true + - name: centos8 + image: geerlingguy/docker-centos8-ansible + command: ${MOLECULE_DOCKER_COMMAND:-""} + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true +provisioner: + name: ansible +verifier: + name: ansible +scenario: + test_sequence: + - dependency + - lint + - cleanup + - destroy + - syntax + - create + - prepare + - converge + # - idempotence # disable for now, as we have non-idempotent tasks + - side_effect + - verify + - cleanup + - destroy diff --git a/roles/agent/molecule/2.2.0/verify.yml b/roles/agent/molecule/2.2.0/verify.yml new file mode 100644 index 000000000..79fce6e30 --- /dev/null +++ b/roles/agent/molecule/2.2.0/verify.yml @@ -0,0 +1,31 @@ +--- +- name: Verify + hosts: all + gather_facts: false + tasks: + + - name: Populate service facts. + ansible.builtin.service_facts: + + - name: "Test Agent is present." + ansible.builtin.stat: + path: "/usr/bin/check_mk_agent" + register: checkmk_agent_file + + - name: "Verify Agent is present." + ansible.builtin.assert: + that: checkmk_agent_file.stat.exists | bool + + - name: "Test Agent Service is running." + ansible.builtin.assert: + that: "'check-mk-agent-async.service' in ansible_facts.services" + + - name: "Test that the Agent is listening on the default Port." + ansible.builtin.wait_for: + port: 6556 + connect_timeout: 30 + register: checkmk_agent_port + + - name: "Test Agent Service is listening on port 6556." + ansible.builtin.assert: + that: "(checkmk_agent_port.port == 6556) and (checkmk_agent_port.state == 'started')" From 77bf6646a61f77ea5a46d5218bbe7d8ce391641e Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Thu, 20 Apr 2023 14:42:01 +0200 Subject: [PATCH 02/11] Add workflow file. --- .github/workflows/molecule-role-agent.yaml | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/molecule-role-agent.yaml diff --git a/.github/workflows/molecule-role-agent.yaml b/.github/workflows/molecule-role-agent.yaml new file mode 100644 index 000000000..0676679ba --- /dev/null +++ b/.github/workflows/molecule-role-agent.yaml @@ -0,0 +1,66 @@ +# https://github.com/ansible-collections/collection_template/blob/main/.github/workflows/ansible-test.yml +# README FIRST +# 1. replace "NAMESPACE" and "COLLECTION_NAME" with the correct name in the env section (e.g. with 'community' and 'mycollection') +# 2. If you don't have unit tests remove that section +# 3. If your collection depends on other collections ensure they are installed, see "Install collection dependencies" +# If you need help please ask in #ansible-community on the Libera.chat IRC network + +name: Molecule Tests for Agent Role +on: + workflow_dispatch: + pull_request: + branches: + - main + - devel + paths: + - 'roles/agent/**' + push: + branches: + - main + - devel + paths: + - 'roles/agent/**' + +env: + NAMESPACE: tribe29 + COLLECTION_NAME: checkmk + +jobs: + build: + runs-on: ubuntu-20.04 + name: Checkmk ${{ matrix.checkmk }} + py${{ matrix.python }} + strategy: + fail-fast: false + matrix: + python: + - '3.8' + - '3.9' + - '3.10' + - '3.11' + checkmk: + - '2.0.0' + - '2.1.0' + - '2.2.0' + + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} + + - name: Set up Python ${{ matrix.python }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + python3 -m pip install -r requirements.txt + working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} + + - name: Test with molecule + run: | + cd roles/agent/ + molecule test -s ${{ matrix.checkmk }} + working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} From e5ed792e678b14fc83ee0b16b2b811351e8bb6bd Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Thu, 20 Apr 2023 15:45:54 +0200 Subject: [PATCH 03/11] Bugfix 2.0.0 verification. --- roles/agent/molecule/2.0.0/verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/agent/molecule/2.0.0/verify.yml b/roles/agent/molecule/2.0.0/verify.yml index 79fce6e30..868935aaa 100644 --- a/roles/agent/molecule/2.0.0/verify.yml +++ b/roles/agent/molecule/2.0.0/verify.yml @@ -18,7 +18,7 @@ - name: "Test Agent Service is running." ansible.builtin.assert: - that: "'check-mk-agent-async.service' in ansible_facts.services" + that: "'check_mk-async.service' in ansible_facts.services" - name: "Test that the Agent is listening on the default Port." ansible.builtin.wait_for: From 9c73777044c575c04e94b977255ab03ee8372fe4 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 2 May 2023 13:28:27 +0200 Subject: [PATCH 04/11] Switch to molecule-plugins. https://github.com/ansible-community/molecule-plugins --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index cbc6c78a7..cc2138d77 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,5 @@ antsibull-docs >= 1.5.0 ansible-lint >= 6.0.0 jinja2 >= 3.0.0 molecule >= 3.5.0 -molecule-docker >= 1.1.0 +molecule-plugins[docker] >= 23.0.0 yamllint >=1.0.0 \ No newline at end of file From 0bf9fe9149a34c40e3700eae25c4027927a2bd50 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 2 May 2023 13:57:03 +0200 Subject: [PATCH 05/11] Remove obsolete linting scenario. https://github.com/ansible-community/molecule/pull/3802 --- roles/agent/molecule/2.0.0/molecule.yml | 2 +- roles/agent/molecule/2.1.0/molecule.yml | 2 +- roles/agent/molecule/2.2.0/molecule.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/agent/molecule/2.0.0/molecule.yml b/roles/agent/molecule/2.0.0/molecule.yml index 19d9c24bf..c10867c19 100644 --- a/roles/agent/molecule/2.0.0/molecule.yml +++ b/roles/agent/molecule/2.0.0/molecule.yml @@ -74,7 +74,7 @@ verifier: scenario: test_sequence: - dependency - - lint + # - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 - cleanup - destroy - syntax diff --git a/roles/agent/molecule/2.1.0/molecule.yml b/roles/agent/molecule/2.1.0/molecule.yml index 19d9c24bf..c10867c19 100644 --- a/roles/agent/molecule/2.1.0/molecule.yml +++ b/roles/agent/molecule/2.1.0/molecule.yml @@ -74,7 +74,7 @@ verifier: scenario: test_sequence: - dependency - - lint + # - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 - cleanup - destroy - syntax diff --git a/roles/agent/molecule/2.2.0/molecule.yml b/roles/agent/molecule/2.2.0/molecule.yml index 19d9c24bf..c10867c19 100644 --- a/roles/agent/molecule/2.2.0/molecule.yml +++ b/roles/agent/molecule/2.2.0/molecule.yml @@ -74,7 +74,7 @@ verifier: scenario: test_sequence: - dependency - - lint + # - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 - cleanup - destroy - syntax From ff168e37740dd82fc63d4bd892502d63de9113f9 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 2 May 2023 14:18:56 +0200 Subject: [PATCH 06/11] Revert molecule-plugins and pin molecule to < 5. Apparently molecule 5 and molecule-plugins is not really stable yet. --- requirements.txt | 5 +++-- roles/agent/molecule/2.0.0/molecule.yml | 2 +- roles/agent/molecule/2.1.0/molecule.yml | 2 +- roles/agent/molecule/2.2.0/molecule.yml | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index cc2138d77..a9c3bc0aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ antsibull-changelog >= 0.16.0 antsibull-docs >= 1.5.0 ansible-lint >= 6.0.0 jinja2 >= 3.0.0 -molecule >= 3.5.0 -molecule-plugins[docker] >= 23.0.0 +molecule < 5.0.0 # Pin molecule until version 5 is stable enough. +molecule-docker >= 1.1.0 +# molecule-plugins[docker] >= 23.0.0 # This will be needed with Molecule 5. yamllint >=1.0.0 \ No newline at end of file diff --git a/roles/agent/molecule/2.0.0/molecule.yml b/roles/agent/molecule/2.0.0/molecule.yml index c10867c19..4b3259e3e 100644 --- a/roles/agent/molecule/2.0.0/molecule.yml +++ b/roles/agent/molecule/2.0.0/molecule.yml @@ -74,7 +74,7 @@ verifier: scenario: test_sequence: - dependency - # - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 + - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 - cleanup - destroy - syntax diff --git a/roles/agent/molecule/2.1.0/molecule.yml b/roles/agent/molecule/2.1.0/molecule.yml index c10867c19..4b3259e3e 100644 --- a/roles/agent/molecule/2.1.0/molecule.yml +++ b/roles/agent/molecule/2.1.0/molecule.yml @@ -74,7 +74,7 @@ verifier: scenario: test_sequence: - dependency - # - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 + - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 - cleanup - destroy - syntax diff --git a/roles/agent/molecule/2.2.0/molecule.yml b/roles/agent/molecule/2.2.0/molecule.yml index c10867c19..4b3259e3e 100644 --- a/roles/agent/molecule/2.2.0/molecule.yml +++ b/roles/agent/molecule/2.2.0/molecule.yml @@ -74,7 +74,7 @@ verifier: scenario: test_sequence: - dependency - # - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 + - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 - cleanup - destroy - syntax From 3436a54c639be642471294df0e3f978cf88dac38 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Thu, 4 May 2023 08:38:31 +0200 Subject: [PATCH 07/11] Bump molecule to a supposedly fixed version. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a9c3bc0aa..475d2471b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ antsibull-changelog >= 0.16.0 antsibull-docs >= 1.5.0 ansible-lint >= 6.0.0 jinja2 >= 3.0.0 -molecule < 5.0.0 # Pin molecule until version 5 is stable enough. +molecule >= 5.0.1 molecule-docker >= 1.1.0 # molecule-plugins[docker] >= 23.0.0 # This will be needed with Molecule 5. yamllint >=1.0.0 \ No newline at end of file From 89f9ddbdb50cb8bb6956ed4283ef70422552245d Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Thu, 4 May 2023 10:22:26 +0200 Subject: [PATCH 08/11] Disable linting again and fix molecule version. --- requirements.txt | 2 +- roles/agent/molecule/2.0.0/molecule.yml | 2 +- roles/agent/molecule/2.1.0/molecule.yml | 2 +- roles/agent/molecule/2.2.0/molecule.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 475d2471b..1a8bf26a2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ antsibull-changelog >= 0.16.0 antsibull-docs >= 1.5.0 ansible-lint >= 6.0.0 jinja2 >= 3.0.0 -molecule >= 5.0.1 +molecule >= 4.0.4 molecule-docker >= 1.1.0 # molecule-plugins[docker] >= 23.0.0 # This will be needed with Molecule 5. yamllint >=1.0.0 \ No newline at end of file diff --git a/roles/agent/molecule/2.0.0/molecule.yml b/roles/agent/molecule/2.0.0/molecule.yml index 4b3259e3e..c10867c19 100644 --- a/roles/agent/molecule/2.0.0/molecule.yml +++ b/roles/agent/molecule/2.0.0/molecule.yml @@ -74,7 +74,7 @@ verifier: scenario: test_sequence: - dependency - - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 + # - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 - cleanup - destroy - syntax diff --git a/roles/agent/molecule/2.1.0/molecule.yml b/roles/agent/molecule/2.1.0/molecule.yml index 4b3259e3e..c10867c19 100644 --- a/roles/agent/molecule/2.1.0/molecule.yml +++ b/roles/agent/molecule/2.1.0/molecule.yml @@ -74,7 +74,7 @@ verifier: scenario: test_sequence: - dependency - - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 + # - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 - cleanup - destroy - syntax diff --git a/roles/agent/molecule/2.2.0/molecule.yml b/roles/agent/molecule/2.2.0/molecule.yml index 4b3259e3e..c10867c19 100644 --- a/roles/agent/molecule/2.2.0/molecule.yml +++ b/roles/agent/molecule/2.2.0/molecule.yml @@ -74,7 +74,7 @@ verifier: scenario: test_sequence: - dependency - - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 + # - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 - cleanup - destroy - syntax From 63c531e1d749b0e297f0401f0e595efa2ec1cc70 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Thu, 4 May 2023 12:54:18 +0200 Subject: [PATCH 09/11] Cleanup molecule configuration after successful validation. --- roles/agent/molecule/2.0.0/molecule.yml | 1 - roles/agent/molecule/2.1.0/molecule.yml | 1 - roles/agent/molecule/2.2.0/molecule.yml | 1 - 3 files changed, 3 deletions(-) diff --git a/roles/agent/molecule/2.0.0/molecule.yml b/roles/agent/molecule/2.0.0/molecule.yml index c10867c19..7864e6ae7 100644 --- a/roles/agent/molecule/2.0.0/molecule.yml +++ b/roles/agent/molecule/2.0.0/molecule.yml @@ -74,7 +74,6 @@ verifier: scenario: test_sequence: - dependency - # - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 - cleanup - destroy - syntax diff --git a/roles/agent/molecule/2.1.0/molecule.yml b/roles/agent/molecule/2.1.0/molecule.yml index c10867c19..7864e6ae7 100644 --- a/roles/agent/molecule/2.1.0/molecule.yml +++ b/roles/agent/molecule/2.1.0/molecule.yml @@ -74,7 +74,6 @@ verifier: scenario: test_sequence: - dependency - # - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 - cleanup - destroy - syntax diff --git a/roles/agent/molecule/2.2.0/molecule.yml b/roles/agent/molecule/2.2.0/molecule.yml index c10867c19..7864e6ae7 100644 --- a/roles/agent/molecule/2.2.0/molecule.yml +++ b/roles/agent/molecule/2.2.0/molecule.yml @@ -74,7 +74,6 @@ verifier: scenario: test_sequence: - dependency - # - lint # Apparently linting is gone from molecule 5 onwards: https://github.com/ansible-community/molecule/pull/3802 - cleanup - destroy - syntax From c6ab5ac28956f1e8093d5ee80c7b179690389754 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Thu, 4 May 2023 12:55:05 +0200 Subject: [PATCH 10/11] Update molecule config for server role as well. --- roles/server/molecule/2.0.0/molecule.yml | 1 - roles/server/molecule/2.1.0/molecule.yml | 1 - roles/server/molecule/2.2.0/molecule.yml | 1 - 3 files changed, 3 deletions(-) diff --git a/roles/server/molecule/2.0.0/molecule.yml b/roles/server/molecule/2.0.0/molecule.yml index 19d9c24bf..7864e6ae7 100644 --- a/roles/server/molecule/2.0.0/molecule.yml +++ b/roles/server/molecule/2.0.0/molecule.yml @@ -74,7 +74,6 @@ verifier: scenario: test_sequence: - dependency - - lint - cleanup - destroy - syntax diff --git a/roles/server/molecule/2.1.0/molecule.yml b/roles/server/molecule/2.1.0/molecule.yml index 19d9c24bf..7864e6ae7 100644 --- a/roles/server/molecule/2.1.0/molecule.yml +++ b/roles/server/molecule/2.1.0/molecule.yml @@ -74,7 +74,6 @@ verifier: scenario: test_sequence: - dependency - - lint - cleanup - destroy - syntax diff --git a/roles/server/molecule/2.2.0/molecule.yml b/roles/server/molecule/2.2.0/molecule.yml index 19d9c24bf..7864e6ae7 100644 --- a/roles/server/molecule/2.2.0/molecule.yml +++ b/roles/server/molecule/2.2.0/molecule.yml @@ -74,7 +74,6 @@ verifier: scenario: test_sequence: - dependency - - lint - cleanup - destroy - syntax From 261868d1c7618db1e5f37fde9a9f78b475955c2c Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Thu, 4 May 2023 14:39:01 +0200 Subject: [PATCH 11/11] Last clean ups. --- roles/agent/molecule/2.0.0/converge.yml | 2 +- roles/agent/molecule/2.1.0/converge.yml | 2 +- roles/agent/molecule/2.2.0/converge.yml | 4 +++- roles/server/molecule/2.0.0/group_vars/all.yml | 2 +- roles/server/molecule/2.1.0/group_vars/all.yml | 2 +- roles/server/molecule/2.2.0/converge.yml | 6 +++--- roles/server/molecule/2.2.0/group_vars/all.yml | 2 +- 7 files changed, 11 insertions(+), 9 deletions(-) diff --git a/roles/agent/molecule/2.0.0/converge.yml b/roles/agent/molecule/2.0.0/converge.yml index afae38a08..355915cd1 100644 --- a/roles/agent/molecule/2.0.0/converge.yml +++ b/roles/agent/molecule/2.0.0/converge.yml @@ -4,7 +4,7 @@ pre_tasks: - - name: "Update apt cache." + - name: Update apt cache. ansible.builtin.apt: update_cache: true cache_valid_time: 600 diff --git a/roles/agent/molecule/2.1.0/converge.yml b/roles/agent/molecule/2.1.0/converge.yml index afae38a08..355915cd1 100644 --- a/roles/agent/molecule/2.1.0/converge.yml +++ b/roles/agent/molecule/2.1.0/converge.yml @@ -4,7 +4,7 @@ pre_tasks: - - name: "Update apt cache." + - name: Update apt cache. ansible.builtin.apt: update_cache: true cache_valid_time: 600 diff --git a/roles/agent/molecule/2.2.0/converge.yml b/roles/agent/molecule/2.2.0/converge.yml index afae38a08..6fa62fce9 100644 --- a/roles/agent/molecule/2.2.0/converge.yml +++ b/roles/agent/molecule/2.2.0/converge.yml @@ -4,11 +4,12 @@ pre_tasks: - - name: "Update apt cache." + - name: Update apt cache. ansible.builtin.apt: update_cache: true cache_valid_time: 600 when: ansible_os_family == 'Debian' + - name: Install prerequisites. ansible.builtin.apt: name: "{{ item }}" @@ -17,6 +18,7 @@ - apt-utils - man when: ansible_os_family == 'Debian' + - name: Create '/usr/share/man/man8/' on Ubuntu. ansible.builtin.file: path: /usr/share/man/man8/ diff --git a/roles/server/molecule/2.0.0/group_vars/all.yml b/roles/server/molecule/2.0.0/group_vars/all.yml index 6e1337e3c..45c8fdb41 100644 --- a/roles/server/molecule/2.0.0/group_vars/all.yml +++ b/roles/server/molecule/2.0.0/group_vars/all.yml @@ -1,6 +1,6 @@ --- # General -checkmk_version: "2.0.0p34" +checkmk_version: "2.0.0p35" checkmk_edition: "cre" checkmk_site: "my_site" server_url: "http://127.0.0.1/" diff --git a/roles/server/molecule/2.1.0/group_vars/all.yml b/roles/server/molecule/2.1.0/group_vars/all.yml index 4153afac5..dbde2d516 100644 --- a/roles/server/molecule/2.1.0/group_vars/all.yml +++ b/roles/server/molecule/2.1.0/group_vars/all.yml @@ -1,6 +1,6 @@ --- # General -checkmk_version: "2.1.0p25" +checkmk_version: "2.1.0p26" checkmk_edition: "cre" checkmk_site: "my_site" server_url: "http://127.0.0.1/" diff --git a/roles/server/molecule/2.2.0/converge.yml b/roles/server/molecule/2.2.0/converge.yml index f98537dbb..2765b83d9 100644 --- a/roles/server/molecule/2.2.0/converge.yml +++ b/roles/server/molecule/2.2.0/converge.yml @@ -5,28 +5,28 @@ pre_tasks: - name: Update apt cache. - when: ansible_os_family == 'Debian' ansible.builtin.apt: update_cache: true cache_valid_time: 600 + when: ansible_os_family == 'Debian' - name: Install prerequisites. - when: ansible_os_family == 'Debian' ansible.builtin.apt: name: "{{ item }}" state: present loop: - apt-utils - man + when: ansible_os_family == 'Debian' - name: Create '/usr/share/man/man8/' on Ubuntu. - when: ansible_distribution == 'Ubuntu' ansible.builtin.file: path: /usr/share/man/man8/ state: directory mode: "0755" owner: root group: root + when: ansible_distribution == 'Ubuntu' tasks: diff --git a/roles/server/molecule/2.2.0/group_vars/all.yml b/roles/server/molecule/2.2.0/group_vars/all.yml index c3d34aa74..0d4f3edf6 100644 --- a/roles/server/molecule/2.2.0/group_vars/all.yml +++ b/roles/server/molecule/2.2.0/group_vars/all.yml @@ -1,6 +1,6 @@ --- # General -checkmk_version: "2.2.0b2" +checkmk_version: "2.2.0b4" checkmk_edition: "cre" checkmk_site: "my_site" server_url: "http://127.0.0.1/"