1
1
---
2
- # Installing required LDAP client packages for the integration.
3
2
4
- - name : LDAP | OS version check
3
+ - name : LDAP | Check OS version
5
4
ansible.builtin.shell : " grep -oE 'release [0-9]+' /etc/redhat-release | awk '{print $2}'"
6
5
register : rhel_version
7
6
changed_when : false
8
7
9
8
- block :
10
- - name : LDAP | Enable LDAP authentication
11
- ansible.builtin.command :
12
- cmd : authconfig --enableldap --enableldapauth --ldapserver=ldap://{{ LDAP_SERVER_IP }} --ldapbasedn="dc={{ BASE_DN.split('.')[0] }},dc={{ BASE_DN.split('.')[1] }}" --enablemkhomedir --update
13
- register : enable_authconfig
14
-
15
- - debug :
16
- var : enable_authconfig.stdout_lines
9
+ - name : LDAP | Check for existing ldap_cacert.pem
10
+ ansible.builtin.stat :
11
+ path : " {{ LDAP_CERT_FILES_DIR }}/ldap_cacert.pem"
12
+ register : ldap_cert_stat
17
13
18
- - name : Update nsswitch.conf
19
- ansible.builtin.lineinfile :
20
- path : /etc/nsswitch.conf
21
- regexp : " {{ item.regexp }}"
22
- line : " {{ item.line }}"
23
- loop :
24
- - { regexp: '^passwd:', line: 'passwd: files ldap' }
25
- - { regexp: '^shadow:', line: 'shadow: files ldap' }
26
- - { regexp: '^group:', line: 'group: files ldap' }
27
-
28
- - name : Remove 'auth' lines from password-auth PAM configuration
29
- ansible.builtin.lineinfile :
30
- path : " {{ item }}"
31
- state : absent
32
- regexp : ' ^auth.*'
33
- loop :
34
- - /etc/pam.d/password-auth
35
- - /etc/pam.d/system-auth
14
+ - name : LDAP | Copy ldap_cacert.pem to remote servers if not present
15
+ ansible.builtin.copy :
16
+ src : " {{ LDAP_CERT_FILES_DIR }}/ldap_cacert.pem"
17
+ dest : /etc/openldap/certs/ldap_cacert.pem
18
+ owner : root
19
+ group : root
20
+ mode : ' 0600'
21
+ when : not ldap_cert_stat.stat.exists
22
+ register : ldap_cert_result
36
23
37
- - name : Add custom auth lines to PAM configuration files
24
+ - name : LDAP | Update LDAP configuration with server details
38
25
ansible.builtin.blockinfile :
39
- path : " {{ item }} "
26
+ path : /etc/openldap/ldap.conf
40
27
block : |
41
- auth required pam_env.so
42
- auth sufficient pam_unix.so nullok try_first_pass
43
- auth requisite pam_succeed_if.so uid >= 1000 quiet_success
44
- auth sufficient pam_ldap.so use_first_pass
45
- auth required pam_deny.so
28
+ BASE dc={{ BASE_DN.split('.')[0] }},dc={{ BASE_DN.split('.')[1] }}
29
+ URI ldap://{{ LDAP_SERVER_IP }}/
30
+ TLS_CACERT /etc/openldap/certs/ldap_cacert.pem
31
+ TLS_CACERTDIR /etc/openldap/certs
46
32
create : yes
47
- loop :
48
- - /etc/pam.d/password-auth
49
- - /etc/pam.d/system-auth
50
- - /etc/pam.d/sshd
51
33
52
- - name : Remove nslcd.conf file
34
+ - name : LDAP | Rehash certificates in OpenLDAP directory
35
+ ansible.builtin.command :
36
+ cmd : openssl rehash /etc/openldap/certs
37
+
38
+ - name : LDAP | Configure SSSD with mkhomedir
39
+ ansible.builtin.command :
40
+ cmd : authselect select sssd with-mkhomedir --force
41
+
42
+ - name : LDAP | Remove existing SSSD configuration file if present
53
43
ansible.builtin.file :
54
- path : /etc/nslcd .conf
44
+ path : /etc/sssd/sssd .conf
55
45
state : absent
56
46
57
- - name : LDAP | Update LDAP Configuration with LDAP_SERVER and BASE_DN
58
- ansible.builtin.blockinfile :
59
- path : /etc/nslcd.conf
60
- block : |
61
- uid nslcd
62
- gid ldap
63
- uri ldap://{{ LDAP_SERVER_IP }}/
64
- base dc={{ BASE_DN.split('.')[0] }},dc={{ BASE_DN.split('.')[1] }}
65
- create : yes
66
-
67
- - name : Allow SSH authentication
68
- ansible.builtin.command : sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
69
- notify : Restart SSH Service
47
+ - name : LDAP | Create new SSSD configuration file
48
+ ansible.builtin.template :
49
+ src : sssd.conf.j2
50
+ dest : /etc/sssd/sssd.conf
51
+ mode : ' 0600'
52
+ owner : root
53
+ group : root
70
54
71
- - name : Restart and enable the services
55
+ - name : LDAP | Restart and enable SSSD and oddjobd services
72
56
ansible.builtin.systemd :
73
57
name : " {{ item }}"
74
58
state : restarted
75
59
enabled : yes
76
60
loop :
77
- - nslcd
78
- - nscd
79
- when : rhel_version.stdout in ["7", "8"]
61
+ - sssd
62
+ - oddjobd
63
+
64
+ - name : LDAP | Allow SSH password authentication
65
+ ansible.builtin.command :
66
+ cmd : sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
67
+ notify : Restart SSH Service
68
+
69
+ when : rhel_version.stdout in ["8", "9"]
0 commit comments