Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
5e76d20
LDAP module: First working version.
lgetwan Sep 4, 2025
1782b2b
LDAP module: Added integration tests.
lgetwan Sep 5, 2025
8f42a93
LDAP module: Sanity...
lgetwan Sep 5, 2025
0850583
LDAP Module: documentation sanity, part 03
lgetwan Sep 5, 2025
dcf01b4
LDAP Module: documentation sanity, part 04
lgetwan Sep 5, 2025
0aae87b
LDAP Module: documentation sanity, part 05
lgetwan Sep 5, 2025
27d44a2
LDAP Module: documentation sanity, part 05
lgetwan Sep 5, 2025
2c1dc67
LDAP Module: documentation sanity, part 06
lgetwan Sep 5, 2025
b3ba4f3
LDAP Module: documentation sanity, part 07
lgetwan Sep 5, 2025
2b5128e
LDAP Module: documentation sanity, part 08
lgetwan Sep 5, 2025
056c596
LDAP Module: documentation sanity, part 09
lgetwan Sep 5, 2025
17eca8e
LDAP Module: documentation sanity, part 10
lgetwan Sep 5, 2025
f34f503
LDAP Module: documentation sanity, part 11
lgetwan Sep 5, 2025
9f77e91
LDAP Module: integration test, part 01
lgetwan Sep 5, 2025
50be593
LDAP Module: integration test, part 02
lgetwan Sep 5, 2025
aa1f4d5
LDAP Module: integration test, part 03
lgetwan Sep 5, 2025
d4338b7
LDAP Module: integration test, part 04
lgetwan Sep 8, 2025
6a24bba
LDAP Module: integration test, part 05
lgetwan Sep 8, 2025
b3a102f
LDAP Module: integration test, part 06
lgetwan Sep 8, 2025
f7ab307
LDAP Module: integration test, part 07
lgetwan Sep 12, 2025
ef4484a
LDAP Module: integration test, part 08
lgetwan Sep 16, 2025
bb2ddca
LDAP Module: integration test, part 09
lgetwan Sep 16, 2025
4f32189
LDAP Module: integration test, part 09
lgetwan Sep 16, 2025
f9cdded
LDAP Module: integration test, part 10
lgetwan Sep 16, 2025
442b6a5
LDAP Module: integration test, part 11
lgetwan Sep 16, 2025
273fca1
LDAP Module: lookup modules, part 01
lgetwan Sep 16, 2025
7adf3ab
LDAP Module: lookup modules, part 02
lgetwan Sep 16, 2025
f0bb54f
LDAP Module: lookup modules, part 03
lgetwan Sep 16, 2025
daef8e0
LDAP Module: lookup modules, part 04
lgetwan Sep 16, 2025
8e857fb
LDAP Module: lookup modules, part 05
lgetwan Sep 16, 2025
b8269d8
LDAP Module: lookup modules, part 05
lgetwan Sep 16, 2025
17a1c5d
LDAP Module: lookup modules, part 05
lgetwan Sep 16, 2025
5d02b08
LDAP Module: lookup modules, part 08
lgetwan Sep 16, 2025
debc5ad
LDAP Module: lookup modules, part 09
lgetwan Sep 16, 2025
217200e
LDAP Module: lookup modules, part 10
lgetwan Sep 16, 2025
2c1e9b4
LDAP Module: lookup modules, part 11
lgetwan Sep 16, 2025
2352b4c
LDAP Module: lookup modules, part 12
lgetwan Sep 16, 2025
e4cbe96
LDAP Module: lookup modules, part 13
lgetwan Sep 16, 2025
0306feb
LDAP Module: lookup modules, part 14
lgetwan Sep 16, 2025
a4659f2
LDAP Module: lookup modules, part 15
lgetwan Sep 16, 2025
0b87b60
LDAP Module: lookup modules, part 16
lgetwan Sep 16, 2025
1d09357
LDAP Module: lookup modules, part 17
lgetwan Sep 17, 2025
ef34b8a
LDAP Module: lookup modules, part 18
lgetwan Sep 17, 2025
cd21c5f
LDAP Module: lookup modules, part 19
lgetwan Sep 17, 2025
93bd6f2
LDAP Module: lookup modules, part 20
lgetwan Sep 17, 2025
a2898fc
LDAP Module: lookup modules, part 21
lgetwan Sep 17, 2025
e060cfa
LDAP Module: lookup modules, part 22
lgetwan Sep 17, 2025
66667d9
LDAP Module: Finalizing 000001
lgetwan Sep 17, 2025
8e1f737
LDAP Module: Finalizing 000002
lgetwan Sep 17, 2025
f1ef6fd
LDAP Module: Finalizing 000003
lgetwan Sep 17, 2025
0199c28
LDAP Module: Finalizing 000004
lgetwan Sep 17, 2025
63959f6
LDAP Module: Pimped the examples.
lgetwan Sep 17, 2025
893f50a
LDAP Module: Added changelog.
lgetwan Sep 17, 2025
f1c2c21
Fix linting findings.
robin-checkmk Nov 17, 2025
00b1e76
Prepare fix for new auth options.
robin-checkmk Nov 17, 2025
1fb4b61
Minor tweak to examples.
robin-checkmk Nov 19, 2025
cbbb712
Update GitHub Workflow.
robin-checkmk Nov 19, 2025
95e20db
Align LDAP module tests with #921 and #930.
robin-checkmk Dec 1, 2025
e3b6b2d
default to 'create user on sync'. Repair group to role sync.
lgetwan Dec 5, 2025
e5215da
documentation sanity.
lgetwan Dec 5, 2025
f6fc62a
LDAP module: The integration test variables now meet the conditions.
lgetwan Dec 8, 2025
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
102 changes: 102 additions & 0 deletions .github/workflows/ans-int-test-ldap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# 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: ldap

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

name: Ansible Integration Tests for LDAP Module
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 0'
pull_request:
branches:
- main
- devel
paths:
- 'plugins/modules/ldap.py'
push:
paths:
- '.github/workflows/ans-int-test-ldap.yaml'
- 'plugins/lookup/ldap_connection.py'
- 'plugins/lookup/ldap_connections.py'
- 'plugins/module_utils/ldap.py'
- 'plugins/modules/ldap.py'
- 'plugins/module_utils/**'
- 'tests/integration/files/includes/**'
- 'tests/integration/targets/ldap/**'

jobs:

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

services:
stable_cre:
image: checkmk/check-mk-raw:2.4.0p15
ports:
- 5024:5000
env:
CMK_SITE_ID: "stable_cre"
CMK_PASSWORD: "Sup3rSec4et!"
stable_cme:
image: checkmk/check-mk-managed:2.4.0p15
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@v7
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}}
5 changes: 5 additions & 0 deletions changelogs/fragments/ldap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
major_changes:
- LDAP module - Add module for LDAP connections.
Refer to the module documentation for further details.
- LDAP Connection lookup module - Add module to lookup details of a single LDAP connection.
- LDAP Connections lookup module - Add module to lookup all LDAP connections and their details.
188 changes: 188 additions & 0 deletions plugins/lookup/ldap_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# Copyright: (c) 2023, Lars Getwan <lars.getwan@checkmk.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function

__metaclass__ = type

DOCUMENTATION = """
name: ldap_connection
author: Lars Getwan (@lgetwan)
version_added: "5.3.0"

short_description: Show the configuration of an ldap connection

description:
- Returns the configuration of an ldap connection

options:

_terms:
description: ldap connection ID
required: True

server_url:
description: URL of the Checkmk server.
required: True
vars:
- name: checkmk_var_server_url
- name: ansible_lookup_checkmk_server_url
env:
- name: CHECKMK_VAR_SERVER_URL
- name: ANSIBLE_LOOKUP_CHECKMK_SERVER_URL
ini:
- section: checkmk_lookup
key: server_url

site:
description: Site name.
required: True
vars:
- name: checkmk_var_site
- name: ansible_lookup_checkmk_site
env:
- name: CHECKMK_VAR_SITE
- name: ANSIBLE_LOOKUP_CHECKMK_SITE
ini:
- section: checkmk_lookup
key: site

automation_user:
description: Automation user for the REST API access.
required: True
vars:
- name: checkmk_var_automation_user
- name: ansible_lookup_checkmk_automation_user
env:
- name: CHECKMK_VAR_AUTOMATION_USER
- name: ANSIBLE_LOOKUP_CHECKMK_AUTOMATION_USER
ini:
- section: checkmk_lookup
key: automation_user

automation_secret:
description: Automation secret for the REST API access.
required: True
vars:
- name: checkmk_var_automation_secret
- name: ansible_lookup_checkmk_automation_secret
env:
- name: CHECKMK_VAR_AUTOMATION_SECRET
- name: ANSIBLE_LOOKUP_CHECKMK_AUTOMATION_SECRET
ini:
- section: checkmk_lookup
key: automation_secret

validate_certs:
description: Whether or not to validate TLS certificates.
type: boolean
required: False
default: True
vars:
- name: checkmk_var_validate_certs
- name: ansible_lookup_checkmk_validate_certs
env:
- name: CHECKMK_VAR_VALIDATE_CERTS
- name: ANSIBLE_LOOKUP_CHECKMK_VALIDATE_CERTS
ini:
- section: checkmk_lookup
key: validate_certs

notes:
- Like all lookups, this runs on the Ansible controller and is unaffected by other keywords such as 'become'.
If you need to use different permissions, you must change the command or run Ansible as another user.
- Alternatively, you can use a shell/command task that runs against localhost and registers the result.
- The directory of the play is used as the current working directory.
- It is B(NOT) possible to assign other variables to the variables mentioned in the C(vars) section!
This is a limitation of Ansible itself.
"""

EXAMPLES = """
- name: Get a site with a particular ldap connection id
ansible.builtin.debug:
msg: "ldap connection: {{ extensions }}"
vars:
extensions: "{{
lookup('checkmk.general.ldap_connection',
'my_ldap_connection',
server_url=server_url,
site=site,
automation_user=automation_user,
automation_secret=automation_secret,
validate_certs=False
)
}}"

- name: "Use variables from inventory."
ansible.builtin.debug:
msg: "ldap connection: {{ extensions }}"
vars:
checkmk_var_server_url: "http://myserver/"
checkmk_var_site: "mysite"
checkmk_var_automation_user: "myuser"
checkmk_var_automation_secret: "mysecret"
checkmk_var_validate_certs: false
attributes: "{{ lookup('checkmk.general.ldap_connection', 'my_ldap_connection') }}"
"""

RETURN = """
_list:
description:
- The details of a particular ldap connection
type: list
elements: str
"""

import json

from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
from ansible_collections.checkmk.general.plugins.module_utils.ldap import (
compress_recursive,
)
from ansible_collections.checkmk.general.plugins.module_utils.lookup_api import (
CheckMKLookupAPI,
)


class LookupModule(LookupBase):
def run(self, terms, variables, **kwargs):
self.set_options(var_options=variables, direct=kwargs)
server_url = self.get_option("server_url")
site = self.get_option("site")
# api_auth_type = self.get_option("api_auth_type") or "bearer"
# api_auth_cookie = self.get_option("api_auth_cookie")
automation_user = self.get_option("automation_user")
automation_secret = self.get_option("automation_secret")
Comment on lines +153 to +156
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I 'fixed' the authentication options, so the tests do not fail anymore, but with the api_ variables I got other errors, so I am certainly missing something here.

validate_certs = self.get_option("validate_certs")

site_url = server_url + "/" + site

api = CheckMKLookupAPI(
site_url=site_url,
# api_auth_type=api_auth_type,
# api_auth_cookie=api_auth_cookie,
automation_user=automation_user,
automation_secret=automation_secret,
Comment on lines +163 to +166
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I 'fixed' the authentication options, so the tests do not fail anymore, but with the api_ variables I got other errors, so I am certainly missing something here.

validate_certs=validate_certs,
)

ret = []

for term in terms:
response = json.loads(api.get("/objects/ldap_connection/" + term))

if "code" in response:
raise AnsibleError(
"Received error for %s - %s: %s"
% (
response.get("url", ""),
response.get("code", ""),
response.get("msg", ""),
)
)

ret.append(compress_recursive(response.get("extensions", {})))

# return log
return ret
Loading