Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automating *just* exim4 configuration with debconf-set-selections with Ansible

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:

  • Update the conf file at /etc/exim4/exim4-config.conf.conf
  • Run 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.

like image 817
3cheesewheel Avatar asked Jul 19 '16 09:07

3cheesewheel


2 Answers

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
like image 107
DeLoVaN Avatar answered Sep 28 '22 09:09

DeLoVaN


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
like image 42
MaxiReglisse Avatar answered Sep 28 '22 10:09

MaxiReglisse