2020-04-17 10:53:37 +02:00
|
|
|
---
|
2020-09-25 08:01:17 +02:00
|
|
|
####################################################################
|
|
|
|
# WARNING: These are designed specifically for Ansible tests #
|
|
|
|
# and should not be used as examples of how to write Ansible roles #
|
|
|
|
####################################################################
|
|
|
|
|
2022-08-05 21:31:34 +02:00
|
|
|
# Copyright (c) Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-04-17 10:53:37 +02:00
|
|
|
- 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
|
2023-03-06 23:02:24 +01:00
|
|
|
become: true
|
2020-04-17 10:53:37 +02:00
|
|
|
package:
|
|
|
|
name: '{{ item }}'
|
|
|
|
loop: '{{ openldap_packages_name }}'
|
|
|
|
|
|
|
|
- name: Install python-ldap (Python 3)
|
2023-03-06 23:02:24 +01:00
|
|
|
become: true
|
2020-04-17 10:53:37 +02:00
|
|
|
package:
|
|
|
|
name: '{{ python_ldap_package_name_python3 }}'
|
|
|
|
when: ansible_python_version is version('3.0', '>=')
|
|
|
|
|
|
|
|
- name: Install python-ldap (Python 2)
|
2023-03-06 23:02:24 +01:00
|
|
|
become: true
|
2020-04-17 10:53:37 +02:00
|
|
|
package:
|
|
|
|
name: '{{ python_ldap_package_name }}'
|
|
|
|
when: ansible_python_version is version('3.0', '<')
|
|
|
|
|
|
|
|
- name: Make sure OpenLDAP service is stopped
|
2023-03-06 23:02:24 +01:00
|
|
|
become: true
|
2020-05-20 12:59:35 +02:00
|
|
|
shell: 'cat /var/run/slapd/slapd.pid | xargs -r kill -9 '
|
2020-04-17 10:53:37 +02:00
|
|
|
|
|
|
|
- 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"
|
|
|
|
|
2023-06-15 07:19:29 +02:00
|
|
|
- name: Enable secure ldap
|
|
|
|
lineinfile:
|
|
|
|
path: /etc/default/slapd
|
|
|
|
regexp: "^SLAPD_SERVICES"
|
|
|
|
line: 'SLAPD_SERVICES="ldap:/// ldaps:/// ldapi:///"'
|
|
|
|
|
|
|
|
- name: Create certificates
|
|
|
|
shell: |
|
|
|
|
openssl req -x509 -batch -sha256 -days 1825 -newkey rsa:2048 -nodes -keyout /root/ca.key -out /usr/local/share/ca-certificates/ca.crt
|
|
|
|
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
|
|
|
|
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
|
|
|
|
chgrp openldap /etc/ldap/localhost.key
|
|
|
|
chmod 0640 /etc/ldap/localhost.key
|
|
|
|
openssl req -batch -sha256 -days 365 -newkey rsa:2048 -subj "/UID=ldaptest" -nodes -keyout /root/user.key -out /root/user.csr
|
|
|
|
openssl x509 -req -CA /usr/local/share/ca-certificates/ca.crt -CAkey /root/ca.key -CAcreateserial -in /root/user.csr -out /root/user.crt
|
|
|
|
|
2020-04-17 10:53:37 +02:00
|
|
|
- name: Start OpenLDAP service
|
2023-03-06 23:02:24 +01:00
|
|
|
become: true
|
2020-04-17 10:53:37 +02:00
|
|
|
service:
|
|
|
|
name: '{{ openldap_service_name }}'
|
2023-03-06 23:02:24 +01:00
|
|
|
enabled: true
|
2020-04-17 10:53:37 +02:00
|
|
|
state: started
|
|
|
|
|
|
|
|
- name: Copy initial config ldif file
|
2023-03-06 23:02:24 +01:00
|
|
|
become: true
|
2020-04-17 10:53:37 +02:00
|
|
|
copy:
|
2021-07-25 13:53:38 +02:00
|
|
|
src: 'files/{{ item }}'
|
|
|
|
dest: '/tmp/{{ item }}'
|
2020-04-17 10:53:37 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0644'
|
|
|
|
loop:
|
|
|
|
- rootpw_cnconfig.ldif
|
2023-06-15 07:19:29 +02:00
|
|
|
- cert_cnconfig.ldif
|
2020-04-17 10:53:37 +02:00
|
|
|
- initial_config.ldif
|
|
|
|
|
|
|
|
- name: Configure admin password for cn=config
|
2023-06-15 07:19:29 +02:00
|
|
|
shell: "ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/{{ item }}"
|
|
|
|
loop:
|
|
|
|
- rootpw_cnconfig.ldif
|
|
|
|
- cert_cnconfig.ldif
|
2020-04-17 10:53:37 +02:00
|
|
|
|
|
|
|
- name: Add initial config
|
2023-03-06 23:02:24 +01:00
|
|
|
become: true
|
2020-04-17 10:53:37 +02:00
|
|
|
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']
|