mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Added ldap_search module for searching in LDAP servers (#126)
* fix CI * Added ldap_search module for searching in LDAP servers * Fixes from pipeline * Fixed second script as well * fix DOCUMENTATION block * fix DOCUMENTATION block * fix DOCUMENTATION block * fix examples and remove changelog fragment * Added integration tests for ldap_search * fixes Co-authored-by: Sebastian Pfahl <sebastian.pfahl@dcso.de>
This commit is contained in:
parent
2639d4c023
commit
e3e6c6167e
13 changed files with 425 additions and 0 deletions
6
tests/integration/targets/ldap_search/aliases
Normal file
6
tests/integration/targets/ldap_search/aliases
Normal file
|
@ -0,0 +1,6 @@
|
|||
shippable/posix/group1
|
||||
skip/aix
|
||||
skip/freebsd
|
||||
skip/osx
|
||||
skip/rhel
|
||||
needs/root
|
3
tests/integration/targets/ldap_search/meta/main.yml
Normal file
3
tests/integration/targets/ldap_search/meta/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
dependencies:
|
||||
- setup_openldap
|
6
tests/integration/targets/ldap_search/tasks/main.yml
Normal file
6
tests/integration/targets/ldap_search/tasks/main.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
- name: Run LDAP search module tests
|
||||
block:
|
||||
- include_tasks: "{{ item }}"
|
||||
with_fileglob:
|
||||
- 'tests/*.yml'
|
||||
when: ansible_os_family in ['Ubuntu', 'Debian']
|
0
tests/integration/targets/ldap_search/tasks/run-test.yml
Normal file
0
tests/integration/targets/ldap_search/tasks/run-test.yml
Normal file
20
tests/integration/targets/ldap_search/tasks/tests/basic.yml
Normal file
20
tests/integration/targets/ldap_search/tasks/tests/basic.yml
Normal file
|
@ -0,0 +1,20 @@
|
|||
- debug:
|
||||
msg: Running tests/basic.yml
|
||||
|
||||
####################################################################
|
||||
## Search ##########################################################
|
||||
####################################################################
|
||||
- name: Test simple search for a user
|
||||
ldap_search:
|
||||
dn: "ou=users,dc=example,dc=com"
|
||||
scope: "onelevel"
|
||||
filter: "(uid=ldaptest)"
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: assert that test LDAP user can be found
|
||||
assert:
|
||||
that:
|
||||
- output is not failed
|
||||
- output.results | length == 1
|
||||
- output.results.0.displayName == "LDAP Test"
|
|
@ -0,0 +1,22 @@
|
|||
dn: ou=users,dc=example,dc=com
|
||||
objectClass: organizationalUnit
|
||||
objectClass: top
|
||||
ou: users
|
||||
|
||||
dn: uid=ldaptest,ou=users,dc=example,dc=com
|
||||
uid: ldaptest
|
||||
uidNumber: 1111
|
||||
gidNUmber: 100
|
||||
objectClass: top
|
||||
objectClass: posixAccount
|
||||
objectClass: shadowAccount
|
||||
objectClass: person
|
||||
objectClass: organizationalPerson
|
||||
objectClass: inetOrgPerson
|
||||
loginShell: /bin/sh
|
||||
homeDirectory: /home/ldaptest
|
||||
cn: LDAP Test
|
||||
gecos: LDAP Test
|
||||
displayName: LDAP Test
|
||||
mail: ldap.test@example.com
|
||||
sn: Test
|
|
@ -0,0 +1,4 @@
|
|||
dn: olcDatabase={0}config,cn=config
|
||||
changetype: modify
|
||||
replace: olcRootPW
|
||||
olcRootPW: "Test1234!"
|
1
tests/integration/targets/setup_openldap/meta/main.yml
Normal file
1
tests/integration/targets/setup_openldap/meta/main.yml
Normal file
|
@ -0,0 +1 @@
|
|||
---
|
63
tests/integration/targets/setup_openldap/tasks/main.yml
Normal file
63
tests/integration/targets/setup_openldap/tasks/main.yml
Normal file
|
@ -0,0 +1,63 @@
|
|||
---
|
||||
- name: Setup OpenLDAP on Debian or Ubuntu
|
||||
block:
|
||||
- name: Include OS-specific variables
|
||||
include_vars: '{{ ansible_os_family }}.yml'
|
||||
|
||||
- name: Install OpenLDAP server and tools
|
||||
become: True
|
||||
package:
|
||||
name: '{{ item }}'
|
||||
loop: '{{ openldap_packages_name }}'
|
||||
|
||||
- name: Install python-ldap (Python 3)
|
||||
become: True
|
||||
package:
|
||||
name: '{{ python_ldap_package_name_python3 }}'
|
||||
when: ansible_python_version is version('3.0', '>=')
|
||||
|
||||
- name: Install python-ldap (Python 2)
|
||||
become: True
|
||||
package:
|
||||
name: '{{ python_ldap_package_name }}'
|
||||
when: ansible_python_version is version('3.0', '<')
|
||||
|
||||
- name: Make sure OpenLDAP service is stopped
|
||||
become: True
|
||||
shell: 'cat /var/run/slapd/slapd.pid | xargs kill -9 '
|
||||
|
||||
- name: Debconf
|
||||
shell: 'echo "slapd {{ item.question }} {{ item.vtype }} {{ item.value }}" >> /root/debconf-slapd.conf'
|
||||
loop: "{{ openldap_debconfs }}"
|
||||
|
||||
- name: Dpkg reconfigure
|
||||
shell:
|
||||
cmd: "export DEBIAN_FRONTEND=noninteractive; cat /root/debconf-slapd.conf | debconf-set-selections; dpkg-reconfigure -f noninteractive slapd"
|
||||
creates: "/root/slapd_configured"
|
||||
|
||||
- name: Start OpenLDAP service
|
||||
become: True
|
||||
service:
|
||||
name: '{{ openldap_service_name }}'
|
||||
enabled: True
|
||||
state: started
|
||||
|
||||
- name: Copy initial config ldif file
|
||||
become: True
|
||||
copy:
|
||||
src: 'files/{{ item }}'
|
||||
dest: '/tmp/{{ item }}'
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
loop:
|
||||
- rootpw_cnconfig.ldif
|
||||
- initial_config.ldif
|
||||
|
||||
- name: Configure admin password for cn=config
|
||||
shell: "ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/rootpw_cnconfig.ldif"
|
||||
|
||||
- name: Add initial config
|
||||
become: True
|
||||
shell: 'ldapadd -H ldapi:/// -x -D "cn=admin,dc=example,dc=com" -w Test1234! -f /tmp/initial_config.ldif'
|
||||
when: ansible_os_family in ['Ubuntu', 'Debian']
|
55
tests/integration/targets/setup_openldap/vars/Debian.yml
Normal file
55
tests/integration/targets/setup_openldap/vars/Debian.yml
Normal file
|
@ -0,0 +1,55 @@
|
|||
python_ldap_package_name: python-ldap
|
||||
python_ldap_package_name_python3: python3-ldap
|
||||
openldap_packages_name:
|
||||
- slapd
|
||||
- ldap-utils
|
||||
openldap_service_name: slapd
|
||||
openldap_debconfs:
|
||||
- question: "shared/organization"
|
||||
value: "Example Organization"
|
||||
vtype: "string"
|
||||
- question: "slapd/allow_ldap_v2"
|
||||
value: "false"
|
||||
vtype: "boolean"
|
||||
- question: "slapd/backend"
|
||||
value: "MDB"
|
||||
vtype: "select"
|
||||
- question: "slapd/domain"
|
||||
value: "example.com"
|
||||
vtype: "string"
|
||||
- question: "slapd/dump_database"
|
||||
value: "when needed"
|
||||
vtype: "select"
|
||||
- question: "slapd/dump_database_destdir"
|
||||
value: "/var/backups/slapd-VERSION"
|
||||
vtype: "string"
|
||||
- question: "slapd/internal/adminpw"
|
||||
value: "Test1234!"
|
||||
vtype: "password"
|
||||
- question: "slapd/internal/generated_adminpw"
|
||||
value: "Test1234!"
|
||||
vtype: "password"
|
||||
- question: "slapd/invalid_config"
|
||||
value: "true"
|
||||
vtype: "boolean"
|
||||
- question: "slapd/move_old_database"
|
||||
value: "true"
|
||||
vtype: "boolean"
|
||||
- question: "slapd/no_configuration"
|
||||
value: "false"
|
||||
vtype: "boolean"
|
||||
- question: "slapd/password1"
|
||||
value: "Test1234!"
|
||||
vtype: "password"
|
||||
- question: "slapd/password2"
|
||||
value: "Test1234!"
|
||||
vtype: "password"
|
||||
- question: "slapd/password_mismatch"
|
||||
value: ""
|
||||
vtype: "note"
|
||||
- question: "slapd/purge_database"
|
||||
value: "false"
|
||||
vtype: "boolean"
|
||||
- question: "slapd/upgrade_slapcat_failure"
|
||||
value: ""
|
||||
vtype: "error"
|
55
tests/integration/targets/setup_openldap/vars/Ubuntu.yml
Normal file
55
tests/integration/targets/setup_openldap/vars/Ubuntu.yml
Normal file
|
@ -0,0 +1,55 @@
|
|||
python_ldap_package_name: python-ldap
|
||||
python_ldap_package_name_python3: python3-ldap
|
||||
openldap_packages_name:
|
||||
- slapd
|
||||
- ldap-utils
|
||||
openldap_service_name: slapd
|
||||
openldap_debconfs:
|
||||
- question: "shared/organization"
|
||||
value: "Example Organization"
|
||||
vtype: "string"
|
||||
- question: "slapd/allow_ldap_v2"
|
||||
value: "false"
|
||||
vtype: "boolean"
|
||||
- question: "slapd/backend"
|
||||
value: "MDB"
|
||||
vtype: "select"
|
||||
- question: "slapd/domain"
|
||||
value: "example.com"
|
||||
vtype: "string"
|
||||
- question: "slapd/dump_database"
|
||||
value: "when needed"
|
||||
vtype: "select"
|
||||
- question: "slapd/dump_database_destdir"
|
||||
value: "/var/backups/slapd-VERSION"
|
||||
vtype: "string"
|
||||
- question: "slapd/internal/adminpw"
|
||||
value: "Test1234!"
|
||||
vtype: "password"
|
||||
- question: "slapd/internal/generated_adminpw"
|
||||
value: "Test1234!"
|
||||
vtype: "password"
|
||||
- question: "slapd/invalid_config"
|
||||
value: "true"
|
||||
vtype: "boolean"
|
||||
- question: "slapd/move_old_database"
|
||||
value: "true"
|
||||
vtype: "boolean"
|
||||
- question: "slapd/no_configuration"
|
||||
value: "false"
|
||||
vtype: "boolean"
|
||||
- question: "slapd/password1"
|
||||
value: "Test1234!"
|
||||
vtype: "password"
|
||||
- question: "slapd/password2"
|
||||
value: "Test1234!"
|
||||
vtype: "password"
|
||||
- question: "slapd/password_mismatch"
|
||||
value: ""
|
||||
vtype: "note"
|
||||
- question: "slapd/purge_database"
|
||||
value: "false"
|
||||
vtype: "boolean"
|
||||
- question: "slapd/upgrade_slapcat_failure"
|
||||
value: ""
|
||||
vtype: "error"
|
Loading…
Add table
Add a link
Reference in a new issue