Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/setup_openldap/tasks/main.yml

raw
1 ---
2 ####################################################################
3 # WARNING: These are designed specifically for Ansible tests #
4 # and should not be used as examples of how to write Ansible roles #
5 ####################################################################
6
7 # Copyright (c) Ansible Project
8 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
9 # SPDX-License-Identifier: GPL-3.0-or-later
10
11 - name: Setup OpenLDAP on Debian or Ubuntu
12 block:
13 - name: Include OS-specific variables
14 include_vars: '{{ ansible_facts.os_family }}.yml'
15
16 - name: Install OpenLDAP server and tools
17 become: true
18 package:
19 name: '{{ item }}'
20 loop: '{{ openldap_packages_name }}'
21
22 - name: Install python-ldap
23 become: true
24 package:
25 name: '{{ python_ldap_package_name_python3 }}'
26
27 - name: Make sure OpenLDAP service is stopped
28 become: true
29 shell: 'cat /var/run/slapd/slapd.pid | xargs -r kill -9 '
30
31 - name: Debconf
32 shell: 'echo "slapd {{ item.question }} {{ item.vtype }} {{ item.value }}" >> /root/debconf-slapd.conf'
33 loop: "{{ openldap_debconfs }}"
34
35 - name: Dpkg reconfigure
36 shell:
37 cmd: "export DEBIAN_FRONTEND=noninteractive; cat /root/debconf-slapd.conf | debconf-set-selections; dpkg-reconfigure -f noninteractive slapd"
38 creates: "/root/slapd_configured"
39
40 - name: Enable secure ldap
41 lineinfile:
42 path: /etc/default/slapd
43 regexp: "^SLAPD_SERVICES"
44 line: 'SLAPD_SERVICES="ldap:/// ldaps:/// ldapi:///"'
45
46 - name: Create certificates
47 shell: |
48 openssl req -x509 -batch -sha256 -days 1825 -newkey rsa:2048 -nodes -keyout /root/ca.key -out /usr/local/share/ca-certificates/ca.crt
49 openssl req -batch -sha256 -days 365 -newkey rsa:2048 -subj "/CN=$(hostname)" -addext "subjectAltName = DNS:localhost" -nodes -keyout /etc/ldap/localhost.key -out /etc/ldap/localhost.csr
50 openssl x509 -req -CA /usr/local/share/ca-certificates/ca.crt -CAkey /root/ca.key -CAcreateserial -in /etc/ldap/localhost.csr -out /etc/ldap/localhost.crt
51 chgrp openldap /etc/ldap/localhost.key
52 chmod 0640 /etc/ldap/localhost.key
53 openssl req -batch -sha256 -days 365 -newkey rsa:2048 -subj "/UID=ldaptest" -nodes -keyout /root/user.key -out /root/user.csr
54 openssl x509 -req -CA /usr/local/share/ca-certificates/ca.crt -CAkey /root/ca.key -CAcreateserial -in /root/user.csr -out /root/user.crt
55
56 - name: Start OpenLDAP service
57 become: true
58 service:
59 name: '{{ openldap_service_name }}'
60 enabled: true
61 state: started
62
63 - name: Copy initial config ldif file
64 become: true
65 copy:
66 src: 'files/{{ item }}'
67 dest: '/tmp/{{ item }}'
68 owner: root
69 group: root
70 mode: '0644'
71 loop:
72 - rootpw_cnconfig.ldif
73 - cert_cnconfig.ldif
74 - initial_config.ldif
75 - inc_schema_cnconfig.ldif
76 - ldap_inc_config.ldif
77
78 - name: Configure admin password for cn=config
79 shell: "ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/{{ item }}"
80 loop:
81 - rootpw_cnconfig.ldif
82 - cert_cnconfig.ldif
83 - inc_schema_cnconfig.ldif
84
85 - name: Add initial config
86 become: true
87 shell: 'ldapadd -H ldapi:/// -x -D "cn=admin,dc=example,dc=com" -w Test1234! -f /tmp/{{ item }}'
88 loop:
89 - initial_config.ldif
90 - ldap_inc_config.ldif
91
92 when: ansible_facts.os_family in ['Ubuntu', 'Debian']