I am trying to set up ldap authentication on Ubuntu machines using Ansible. A challenge here is that if you simply do:
apt-get install -y libnss-ldap libpam-ldap ldap-utils nscd
You get dialog boxes with values to fill in.
I found this out of date page which got me started using debconf to set the values for those dialogs: linux - How to do an initial setup of slapd OLC with ldapmodify - Stack Overflow
And using that I was able to come up with this shell script that works (some values have been anonymized):
export DEBIAN_FRONTEND=noninteractive
sudo debconf-set-selections <<EOF
ldap-auth-config ldap-auth-config/dblogin boolean false
ldap-auth-config ldap-auth-config/dbrootlogin boolean true
ldap-auth-config ldap-auth-config/ldapns/base-dn string myvalue
ldap-auth-config ldap-auth-config/ldapns/ldap-server string myvalue
ldap-auth-config ldap-auth-config/ldapns/ldap_version select 3
ldap-auth-config ldap-auth-config/override boolean true
ldap-auth-config ldap-auth-config/rootbinddn string myvalue
ldap-auth-config ldap-auth-config/rootbindpw password myvalue
EOF
apt-get -y install libnss-ldap libpam-ldap ldap-utils nscd
So trying to convert that to Ansible tasks I’ve got this so far:
- name: install debconf-utils
apt:
name:
- debconf-utils
update_cache: yes
- name: do ldap auth install
ansible.builtin.shell:
cmd: |
export DEBIAN_FRONTEND=noninteractive; debconf-set-selections <<EOF
ldap-auth-config ldap-auth-config/dblogin boolean false
ldap-auth-config ldap-auth-config/dbrootlogin boolean true
ldap-auth-config ldap-auth-config/ldapns/base-dn string myvalue
ldap-auth-config ldap-auth-config/ldapns/ldap-server string myvalue
ldap-auth-config ldap-auth-config/ldapns/ldap_version select 3
ldap-auth-config ldap-auth-config/override boolean true
ldap-auth-config ldap-auth-config/rootbinddn string myvalue
ldap-auth-config ldap-auth-config/rootbindpw password myvalue
EOF; apt-get install -y libnss-ldap libpam-ldap ldap-utils nscd
But I’d really prefer to use the apt module for the actual install but I don’t see how to set the DEBIAN_FRONTEND=noninteractive with the Ansible apt module.
Can someone get me the rest of the way?