Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/ans-int-test-inv_plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# README:
# - When changing the module name, it needs to be changed in 'env:MODULE_NAME' and in 'on:pull_requests:path'!
#
# Resources:
# - Template for this file: https://github.com/ansible-collections/collection_template/blob/main/.github/workflows/ansible-test.yml
# - About Ansible integration tests: https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html

env:
NAMESPACE: checkmk
COLLECTION_NAME: general
MODULE_NAME: inv_plugin

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

name: Ansible Integration Tests for Inventory Plugin
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 0'
pull_request:
branches:
- main
- devel
paths:
- 'plugins/inventory/checkmk.py'
push:
paths:
- '.github/workflows/ans-int-test-inv_plugin.yaml'
- 'plugins/inventory/checkmk.py'
- 'tests/integration/files/includes/'
- 'tests/integration/targets/inv_plugin/'

jobs:

integration:
runs-on: ubuntu-24.04
name: Ⓐ${{ matrix.ansible }}+py${{ matrix.python }}
strategy:
fail-fast: false
matrix:
ansible:
- stable-2.17
- stable-2.18
- stable-2.19
- devel
python:
- '3.11'
- '3.12'
exclude:
# Exclude unsupported sets.
- ansible: devel
python: '3.11'

services:
stable_cme:
image: checkmk/check-mk-managed:2.4.0p10
ports:
- 5324:5000
env:
CMK_SITE_ID: "stable_cme"
CMK_PASSWORD: "Sup3rSec4et!"

steps:
- name: Check out code
uses: actions/checkout@v5
with:
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}

- name: "Install uv and set the python version."
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python }}
enable-cache: true
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}/

- name: "Setup uv venv."
run: uv venv
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}

- name: Install ansible-base (${{ matrix.ansible }})
run: uv pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}

- name: Run integration test
run: uv run ansible-test integration ${{env.MODULE_NAME}} -v --color --continue-on-error --diff --python ${{ matrix.python }}
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
8 changes: 4 additions & 4 deletions playbooks/inventory/checkmk.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
plugin: checkmk.general.checkmk
server_url: "http://localhost/"
site: "hyde"
automation_user: "cmkadmin"
automation_secret: "cmk"
server_url: "http://myserver/"
site: "mysite"
automation_user: "myuser"
automation_secret: "mysecret"
validate_certs: false
groupsources: ["hosttags", "sites"]
want_ipv4: false
9 changes: 9 additions & 0 deletions tests/integration/targets/inv_plugin/inventory/checkmk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugin: checkmk.general.checkmk
server_url: "http://127.0.0.1:5324/"
site: "stable_cme"
automation_user: "cmkadmin"
automation_secret: "Sup3rSec4et!"
validate_certs: false
# groupsources: ["hosttags", "sites", "labels"]
groupsources: ["hosttags", "sites"]
want_ipv4: false
35 changes: 35 additions & 0 deletions tests/integration/targets/inv_plugin/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
- name: "Include Global Variables."
ansible.builtin.include_vars: "{{ lookup('ansible.builtin.first_found', checkmk_var_params) }}"
vars:
checkmk_var_params:
files:
- global.yml
paths:
- /home/runner/work/ansible-collection-checkmk.general/ansible-collection-checkmk.general/ansible_collections/checkmk/general/tests/integration/files/includes/vars/
- /root/ansible_collections/checkmk/general/tests/integration/files/includes/vars/
- tests/integration/files/includes/vars/

- name: "Print Identifier."
ansible.builtin.debug:
msg: "{{ ansible_facts.system_vendor }} {{ ansible_facts.product_name }} running {{ ansible_facts.virtualization_type }}"

- name: "Run preparations."
ansible.builtin.include_tasks: "{{ lookup('ansible.builtin.first_found', checkmk_var_params) }}"
vars:
checkmk_var_params:
files:
- prep.yml
paths:
- /home/runner/work/ansible-collection-checkmk.general/ansible-collection-checkmk.general/ansible_collections/checkmk/general/tests/integration/files/includes/tasks/
- /root/ansible_collections/checkmk/general/tests/integration/files/includes/tasks/
- tests/integration/files/includes/tasks/
when: |
(ansible_facts.system_vendor == "Dell Inc." and 'Latitude' in ansible_facts.product_name and ansible_facts.virtualization_type == "container")
or (ansible_facts.system_vendor == "QEMU" and 'Ubuntu' in ansible_facts.product_name and ansible_facts.virtualization_type == "container")

- name: "Testing."
ansible.builtin.include_tasks: test.yml
loop: "{{ checkmk_var_test_sites }}"
loop_control:
loop_var: outer_item
53 changes: 53 additions & 0 deletions tests/integration/targets/inv_plugin/tasks/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Set customer when needed."
ansible.builtin.set_fact:
checkmk_var_customer: "provider"
when: outer_item.edition == "cme"

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Unset customer when needed."
ansible.builtin.set_fact:
checkmk_var_customer: null
when: outer_item.edition != "cme"

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Create hosts."
host:
server_url: "{{ checkmk_var_server_url }}"
site: "{{ outer_item.site }}"
automation_user: "{{ checkmk_var_automation_user }}"
automation_secret: "{{ checkmk_var_automation_secret }}"
name: "{{ item.name }}"
folder: "{{ item.folder }}"
attributes:
site: "{{ outer_item.site }}"
ipaddress: 127.0.0.1
state: "present"
delegate_to: localhost
run_once: true # noqa run-once[task]
loop: "{{ checkmk_var_hosts }}"

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate changes."
activation:
server_url: "{{ checkmk_var_server_url }}"
site: "{{ outer_item.site }}"
automation_user: "{{ checkmk_var_automation_user }}"
automation_secret: "{{ checkmk_var_automation_secret }}"
delegate_to: localhost
run_once: true # noqa run-once[task]

- name: "Run the inventory plugin on GitHub Actions." # noqa no-changed-when
when: |
not (ansible_facts.system_vendor == "Dell Inc." and 'Latitude' in ansible_facts.product_name and ansible_facts.virtualization_type == "container")
and not (ansible_facts.system_vendor == "QEMU" and 'Ubuntu' in ansible_facts.product_name and ansible_facts.virtualization_type == "container")
ansible.builtin.shell: |
ansible-inventory -i /home/runner/work/ansible-collection-checkmk.general/ansible-collection-checkmk.general/ansible_collections/checkmk/general/tests/integration/targets/inv_plugin/inventory/checkmk.yml --list --export
register: __checkmk_var_inventory_output
failed_when: "'site_stable_cme' not in __checkmk_var_inventory_output.stdout"

- name: "Run the inventory plugin on local Test VM." # noqa no-changed-when
when: |
(ansible_facts.system_vendor == "Dell Inc." and 'Latitude' in ansible_facts.product_name and ansible_facts.virtualization_type == "container")
or (ansible_facts.system_vendor == "QEMU" and 'Ubuntu' in ansible_facts.product_name and ansible_facts.virtualization_type == "container")
ansible.builtin.shell: |
ansible-inventory -i /root/ansible_collections/checkmk/general/tests/integration/targets/inv_plugin/inventory/checkmk.yml --list --export
register: __checkmk_var_inventory_output
failed_when: "'site_stable_cme' not in __checkmk_var_inventory_output.stdout"
18 changes: 18 additions & 0 deletions tests/integration/targets/inv_plugin/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
checkmk_var_test_sites:
- version: "2.4.0p10"
edition: "cme"
site: "stable_cme"
port: "5324"

checkmk_var_hosts:
- name: test1.tld
folder: "/"
- name: test2.tld
folder: "/"
- name: test3.tld
folder: "/"
- name: test4.tld
folder: "/"
- name: test5.tld
folder: "/"