I'm attempting to automate exim4 configuration on Debian in Ansible -- we have been manually configuring up until this point -- but I'm stuck at the stage where I'd run normally dpkg-reconfigure exim4-config
.
I can automate these steps easily enough:
/etc/exim4/exim4-config.conf.conf
dpkg-reconfigure --frontend noninteractive exim4-config
They run fine in the playbook, however the issue is that not all the options that I see in the interactive prompt are in this conf file. For example, the second setting, System mail name
is not specified anywhere in the conf file. Nor is the last setting, Root and postmaster mail recipient
, which also stops showing up in the interactive prompt after the first configuration (why is that?)
I then saw that some people have suggested using debconf-set-selections
(here), and I tried looking into that - I installed the debconf-utils
package and then ran debconf-get-selections
- I then saw all the options there, but now I'm wondering if there is a way to use debconf-set-selections
without having to use a file that sets all of the settings all at once, since I just want to change the values associated with exim4. I'm trying to avoid overwriting any other values (not associated with exim4) that might be set if I need to run the playbook again.
Short of writing the output of debconf-get-selections
to a file and then using Ansible's lineinfile
/template
modules to replace the values I want to change, is there perhaps a simpler way of going about this? I'd prefer to avoid this method.
It's a bit late, but I suggest you to use the ansible debconf module (it basically does a debconf-set-selections
).
Like this example :
- name: Debconf question dc_eximconfig_configtype
debconf: name='exim4-config'
question: 'exim4/dc_eximconfig_configtype'
value: 'internet site; mail is sent and received directly using SMTP'
vtype: select
Or this one :
- name: Debconf question mailname
debconf: name='exim4-config'
question: 'exim4/mailname'
value: '{{ inventory_hostname }}'
vtype: string
However, if you are reconfiguring exim (after you configured it once), then you have to delete 2 files before doing a dpkg-reconfigure
, it can be done with theses commands :
- name: remove exim config files
file: path={{ item }} state=absent
with_items:
- "/etc/exim4/update-exim4.conf.conf"
- "/etc/mailname"
Finally, do a dpkg-reconfigure
, which also restart exim.
- name: Reconfigure package exim4-config
command: dpkg-reconfigure -fnoninteractive exim4-config
i had the following error with the lines "debconf: name='exim4-config'":
ERROR! Syntax Error while loading YAML.
and i also prefered to use "value: 'smarthost'" to set "dc_eximconfig_configtype='smarthost'" in /etc/exim4/update-exim4.conf.conf...
Consequently, my roles/smtp_client/tasks/main.yml file contains the following lines:
- name: remove exim config files
file: path={{ item }} state=absent
with_items:
- "/etc/exim4/update-exim4.conf.conf"
- "/etc/mailname"
- name: Debconf question mailname
debconf:
name: 'ansible_hostname exim4-config'
question: 'exim4/mailname'
value: '{{ ansible_hostname }}'
vtype: string
- name: Debconf question dc_eximconfig_configtype
debconf:
name: 'dc_eximconfig_configtype exim4-config'
question: 'exim4/dc_eximconfig_configtype'
value: 'smarthost'
vtype: select
- name: Debconf question dc_smarthost
debconf:
name: 'dc_smarthost exim4-config'
question: 'exim4/dc_smarthost'
value: '{{ my_smtp_server }}'
vtype: string
- name: Reconfigure package exim4-config
command: dpkg-reconfigure -fnoninteractive exim4-config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With