Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
037b196
LDAP module: First working version.
lgetwan Sep 4, 2025
4e10d3f
LDAP module: Added integration tests.
lgetwan Sep 5, 2025
9f80fb2
LDAP module: Sanity...
lgetwan Sep 5, 2025
a8535d5
LDAP Module: pick dock fragment changes from other branch.
lgetwan Sep 5, 2025
39f908e
LDAP Module: documentation sanity, part 01
lgetwan Sep 5, 2025
13feb8e
LDAP Module: documentation sanity, part 02
lgetwan Sep 5, 2025
6997f14
Merge branch 'feature/ldap_module' of github.com:Checkmk/ansible-coll…
lgetwan Sep 5, 2025
01439d8
LDAP Module: documentation sanity, part 03
lgetwan Sep 5, 2025
411f3a0
LDAP Module: documentation sanity, part 04
lgetwan Sep 5, 2025
ed3088b
LDAP Module: documentation sanity, part 05
lgetwan Sep 5, 2025
5847c71
LDAP Module: documentation sanity, part 05
lgetwan Sep 5, 2025
3ae2efa
Merge branch 'feature/ldap_module' of github.com:Checkmk/ansible-coll…
lgetwan Sep 5, 2025
316793d
LDAP Module: documentation sanity, part 06
lgetwan Sep 5, 2025
0f57ad1
LDAP Module: documentation sanity, part 07
lgetwan Sep 5, 2025
82dcd3e
LDAP Module: documentation sanity, part 08
lgetwan Sep 5, 2025
4d8f82f
LDAP Module: documentation sanity, part 09
lgetwan Sep 5, 2025
1cb4dfb
LDAP Module: documentation sanity, part 10
lgetwan Sep 5, 2025
c7cefe5
LDAP Module: documentation sanity, part 11
lgetwan Sep 5, 2025
f5c66bd
LDAP Module: integration test, part 01
lgetwan Sep 5, 2025
72243f3
LDAP Module: integration test, part 02
lgetwan Sep 5, 2025
ef05469
LDAP Module: integration test, part 03
lgetwan Sep 5, 2025
67e0d1d
LDAP Module: integration test, part 04
lgetwan Sep 8, 2025
dfa9321
LDAP Module: integration test, part 05
lgetwan Sep 8, 2025
44c1ec5
LDAP Module: integration test, part 06
lgetwan Sep 8, 2025
6f36ccb
LDAP Module: integration test, part 07
lgetwan Sep 12, 2025
571b0d7
LDAP Module: integration test, part 08
lgetwan Sep 16, 2025
e4e1fae
LDAP Module: integration test, part 09
lgetwan Sep 16, 2025
a74a72c
LDAP Module: integration test, part 09
lgetwan Sep 16, 2025
2fdcea0
LDAP Module: integration test, part 10
lgetwan Sep 16, 2025
25e2b53
LDAP Module: integration test, part 11
lgetwan Sep 16, 2025
d7d1600
LDAP Module: lookup modules, part 01
lgetwan Sep 16, 2025
a97e939
LDAP Module: lookup modules, part 02
lgetwan Sep 16, 2025
903c892
LDAP Module: lookup modules, part 03
lgetwan Sep 16, 2025
687c63a
LDAP Module: lookup modules, part 04
lgetwan Sep 16, 2025
04d4296
LDAP Module: lookup modules, part 05
lgetwan Sep 16, 2025
6018f76
LDAP Module: lookup modules, part 05
lgetwan Sep 16, 2025
10bf194
LDAP Module: lookup modules, part 05
lgetwan Sep 16, 2025
e32d7b2
LDAP Module: lookup modules, part 08
lgetwan Sep 16, 2025
f9ee22c
LDAP Module: lookup modules, part 09
lgetwan Sep 16, 2025
4112b93
LDAP Module: lookup modules, part 10
lgetwan Sep 16, 2025
1ed9e67
LDAP Module: lookup modules, part 11
lgetwan Sep 16, 2025
80ebdf7
LDAP Module: lookup modules, part 12
lgetwan Sep 16, 2025
27cd389
LDAP Module: lookup modules, part 13
lgetwan Sep 16, 2025
3cf8344
LDAP Module: lookup modules, part 14
lgetwan Sep 16, 2025
c6a6841
LDAP Module: lookup modules, part 15
lgetwan Sep 16, 2025
d0589ec
LDAP Module: lookup modules, part 16
lgetwan Sep 16, 2025
586c09b
LDAP Module: lookup modules, part 17
lgetwan Sep 17, 2025
a65c43b
LDAP Module: lookup modules, part 18
lgetwan Sep 17, 2025
ba0f2a7
LDAP Module: lookup modules, part 19
lgetwan Sep 17, 2025
00e10d8
LDAP Module: lookup modules, part 20
lgetwan Sep 17, 2025
8555853
LDAP Module: lookup modules, part 21
lgetwan Sep 17, 2025
8010b0a
LDAP Module: lookup modules, part 22
lgetwan Sep 17, 2025
9931938
LDAP Module: Finalizing 000001
lgetwan Sep 17, 2025
27eb7ce
LDAP Module: Finalizing 000002
lgetwan Sep 17, 2025
da73d39
LDAP Module: Finalizing 000003
lgetwan Sep 17, 2025
844ddd1
LDAP Module: Finalizing 000004
lgetwan Sep 17, 2025
65e4b03
LDAP Module: Pimped the examples.
lgetwan Sep 17, 2025
b9acae1
LDAP Module: Added changelog.
lgetwan Sep 17, 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
96 changes: 96 additions & 0 deletions .github/workflows/ans-int-test-ldap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# 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'
- '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.16
- stable-2.17
- stable-2.18
- devel
python:
- '3.10'
- '3.11'
- '3.12'
exclude:
# Exclude unsupported sets.
- ansible: stable-2.18
python: '3.10'
- ansible: devel
python: '3.10'
- ansible: devel
python: '3.11'

services:
stable_cre:
image: checkmk/check-mk-raw:2.4.0p9
ports:
- 5024:5000
env:
CMK_SITE_ID: "stable_cre"
CMK_PASSWORD: "Sup3rSec4et!"
stable_cme:
image: checkmk/check-mk-managed:2.4.0p9
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: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Install ansible-base (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check

- name: Run integration test
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.
13 changes: 13 additions & 0 deletions plugins/doc_fragments/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ class ModuleDocFragment(object):
description: The secret to authenticate your automation user.
required: true
type: str
api_auth_type:
description: Type of authentication to use.
required: false
type: str
choices:
- bearer
- basic
- cookie
default: bearer
api_auth_cookie:
description: Authentication cookie for the Checkmk session.
required: false
type: str
validate_certs:
description: Whether to validate the SSL certificate of the Checkmk server.
default: true
Expand Down
184 changes: 184 additions & 0 deletions plugins/lookup/ldap_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# Copyright: (c) 2023, Lars Getwan <[email protected]>
# 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")
user = self.get_option("automation_user")
secret = self.get_option("automation_secret")
validate_certs = self.get_option("validate_certs")

site_url = server_url + "/" + site

api = CheckMKLookupAPI(
site_url=site_url,
user=user,
secret=secret,
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
Loading