-4

enter image description here

I am trying to install Exim4 in Ubuntu using the playbook. But getting error. I am in the process of learning an ansible-playbook and it would be great if someone could help here how to achieve this. My Ansible book look like this

- name: installing exim4.
  remote_user: ubuntu
  become: true
  hosts: sample

tasks:
   - name: Update apt repo and cache on all Debian/Ubuntu boxes
     apt: update_cache=yes force_apt_get=yes cache_valid_time=3600

   - name: Upgrade all packages on servers
     apt: upgrade=dist force_apt_get=yes

   - name: Check if a reboot is needed on all servers
     register: reboot_required_file
     stat: path=/var/run/reboot-required get_md5=no

   - name: Reboot the box if kernel updated
     reboot:
       msg: "Reboot initiated by Ansible for kernel updates"
       connect_timeout: 5
       reboot_timeout: 300
       pre_reboot_delay: 0
       post_reboot_delay: 30
       test_command: uptime
     when: reboot_required_file.stat.exists

   - name: Installing Exim4.
     ansible.builtin.expect:
       command: dpkg-reconfigure exim4-config
       responses:
         General type of mail configuration: 'internet site; mail is sent and received directly using SMTP'
         System mail name: 'ok-golen.yoursitetobe.com'
         IP-addresses to listen on for incoming SMTP connections: '127.0.0.1 ; ::1'
         Other destinations for which mail is accepted: 'golden-image'
         Domains to relay mail for: ''
         Machines to relay mail for: ''
         Keep number of DNS-queries minimal (Dial-on-Demand)?: 'No'
         Delivery method for local mail: 'Maildir format in the home directory'
         Split configuration into small files?: 'No'
         Root and postmaster mail recipient: 'root'

I am not sure this is the right way. Any other alternate way is also appreciated. I am getting the below error.

fatal: [server1]: FAILED! => {"changed": true, "cmd": "dpkg-reconfigure exim4-config", "delta": "0:00:29.323447", "end": "2022-02-23 16:47:09.332278", "msg": "command exceeded timeout", "rc": null, "start": "2022-02-23 16:46:40.008831", "stdout": "\u001b[?1049h\u001b[22;0;0t\u001b[1;24r\u001b[4l\u001b[?25l\u001b(B\u001b[m\u001b[37m\u001b[40m\u001b[1;24r\u001b[H\u001b[2J\u001b[1;1H\u001b[1m\u001b[37m\u001b[45m                                                                                \u001b[2;1H                                                                                \u001b[3;1H                                                                                \u001b[4;1H                                                                                \u001b[5;1H                                                                                \u001b[6;1H                                                                                \u001b[7;1H                                                                                \u001b[8;1H                                                                                \u001b[9;1H                                                                                \u001b[10;1H                                                                                \u001b[11;1H                                                                                \u001b[12;1H                                                                                \u001b[13;1H                                                                                \u001b[14;1H                                                                                \u001b[15;1H                                                                                \u001b[16;1H                                                                                \u001b[17;1H                                                                                \u001b[18;1H                                                                                \u001b[19;1H                                                                                \u001b[20;1H                                                                                \u001b[21;1H                                                                                \u001b[22;1H                                                                                \u001b[23;1H                                                                                \u001b[24;1H                                                                               \u001b[24;79H \b\u001b[4h \u001b[4l\u001b[1;1H\u001b(B\u001b[m\u001b[37m\u001b[45mPackage configuration\u001b[4;2H\u001b[30m\u001b[47m┌───────────────────────┤ \u001b[31mMail Server configuration\u001b[30m ├───────────────────────┐\u001b[5;2H│                                                                           │\u001b[1m\u001b[37m\u001b[40m \u001b[6;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ Please select the mail server configuration type that best meets your     │\u001b[1m\u001b[37m\u001b[40m \u001b[7;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ needs.                                                                    │\u001b[1m\u001b[37m\u001b[40m \u001b[8;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│                                                                           │\u001b[1m\u001b[37m\u001b[40m \u001b[9;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ Systems with dynamic IP addresses, including dialup systems, should       │\u001b[1m\u001b[37m\u001b[40m \u001b[10;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ generally be configured to send outgoing mail to another machine, called  │\u001b[1m\u001b[37m\u001b[40m \u001b[11;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ a 'smarthost' for delivery because many receiving systems on the          │\u001b[1m\u001b[37m\u001b[40m \u001b[12;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ Internet block incoming mail from dynamic IP addresses as spam            │\u001b[1m\u001b[37m\u001b[40m \u001b[13;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ protection.                                                               │\u001b[1m\u001b[37m\u001b[40m \u001b[14;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│                                                                           │\u001b[1m\u001b[37m\u001b[40m \u001b[15;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ A system with a dynamic IP address can receive its own mail, or local     │\u001b[1m\u001b[37m\u001b[40m \u001b[16;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ delivery can be disabled entirely (except mail for root and postmaster).  │\u001b[1m\u001b[37m\u001b[40m \u001b[17;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│                                                                           │\u001b[1m\u001b[37m\u001b[40m \u001b[18;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│                                  \u001b[37m\u001b[41m<Ok>\u001b[30m\u001b[47m                                     │\u001b[1m\u001b[37m\u001b[40m \u001b[19;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│                                                                           │\u001b[1m\u001b[37m\u001b[40m \u001b[20;2H\u001b(B\u001b[m\u001b[30m\u001b[47m└───────────────────────────────────────────────────────────────────────────┘\u001b[1m\u001b[37m\u001b[40m \u001b[21;3H                                                                             \u001b[18;38H", "stdout_lines": ["\u001b[?1049h\u001b[22;0;0t\u001b[1;24r\u001b[4l\u001b[?25l\u001b(B\u001b[m\u001b[37m\u001b[40m\u001b[1;24r\u001b[H\u001b[2J\u001b[1;1H\u001b[1m\u001b[37m\u001b[45m                                                                                \u001b[2;1H                                                                                \u001b[3;1H                                                                                \u001b[4;1H                                                                                \u001b[5;1H                                                                                \u001b[6;1H                                                                                \u001b[7;1H                                                                                \u001b[8;1H                                                                                \u001b[9;1H                                                                                \u001b[10;1H                                                                                \u001b[11;1H                                                                                \u001b[12;1H                                                                                \u001b[13;1H                                                                                \u001b[14;1H                                                                                \u001b[15;1H                                                                                \u001b[16;1H                                                                                \u001b[17;1H                                                                                \u001b[18;1H                                                                                \u001b[19;1H                                                                                \u001b[20;1H                                                                                \u001b[21;1H                                                                                \u001b[22;1H                                                                                \u001b[23;1H                                                                                \u001b[24;1H                                                                               \u001b[24;79H \b\u001b[4h \u001b[4l\u001b[1;1H\u001b(B\u001b[m\u001b[37m\u001b[45mPackage configuration\u001b[4;2H\u001b[30m\u001b[47m┌───────────────────────┤ \u001b[31mMail Server configuration\u001b[30m ├───────────────────────┐\u001b[5;2H│                                                                           │\u001b[1m\u001b[37m\u001b[40m \u001b[6;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ Please select the mail server configuration type that best meets your     │\u001b[1m\u001b[37m\u001b[40m \u001b[7;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ needs.                                                                    │\u001b[1m\u001b[37m\u001b[40m \u001b[8;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│                                                                           │\u001b[1m\u001b[37m\u001b[40m \u001b[9;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ Systems with dynamic IP addresses, including dialup systems, should       │\u001b[1m\u001b[37m\u001b[40m \u001b[10;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ generally be configured to send outgoing mail to another machine, called  │\u001b[1m\u001b[37m\u001b[40m \u001b[11;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ a 'smarthost' for delivery because many receiving systems on the          │\u001b[1m\u001b[37m\u001b[40m \u001b[12;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ Internet block incoming mail from dynamic IP addresses as spam            │\u001b[1m\u001b[37m\u001b[40m \u001b[13;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ protection.                                                               │\u001b[1m\u001b[37m\u001b[40m \u001b[14;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│                                                                           │\u001b[1m\u001b[37m\u001b[40m \u001b[15;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ A system with a dynamic IP address can receive its own mail, or local     │\u001b[1m\u001b[37m\u001b[40m \u001b[16;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│ delivery can be disabled entirely (except mail for root and postmaster).  │\u001b[1m\u001b[37m\u001b[40m \u001b[17;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│                                                                           │\u001b[1m\u001b[37m\u001b[40m \u001b[18;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│                                  \u001b[37m\u001b[41m<Ok>\u001b[30m\u001b[47m                                     │\u001b[1m\u001b[37m\u001b[40m \u001b[19;2H\u001b(B\u001b[m\u001b[30m\u001b[47m│                                                                           │\u001b[1m\u001b[37m\u001b[40m \u001b[20;2H\u001b(B\u001b[m\u001b[30m\u001b[47m└───────────────────────────────────────────────────────────────────────────┘\u001b[1m\u001b[37m\u001b[40m \u001b[21;3H                                                                             \u001b[18;38H"]}
U880D
  • 8,601
  • 6
  • 24
  • 40
  • 5
    Please edit your question and add the **code, logs, output, error messages... in the question body as code blocks**. Using images for this has [numerous disadvantages](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557) and is specifically listed as a bad practice in the must read help article [How to ask](/help/how-to-ask). Thanks – Zeitounator Feb 23 '22 at 17:10
  • 1
    And you almost certainly want to use `dpkg-configure` and not some `expect` wizardry, unless the package is very poorly coded – mdaniel Feb 23 '22 at 21:55
  • @mdaniel so its not possible to achieve what i am looking for?? – Muneesh DuRaipandi Feb 24 '22 at 09:28

1 Answers1

1

I am not sure this is the right way.

By using expect - Execute a command and respond to prompt you are trying to script an interactive configuration. The Debian documentation describes the Exim - Configuration with a file.

Any other alternate way is also appreciated.

An simple Example, a non-interactive way of "How to make Bash the default shell".

- name: Prepare Bash as default shell
  shell:
    cmd: 'echo "dash dash/sh boolean false" | debconf-set-selections'

- name: Make sure that default shell is set to Bash
  shell:
    cmd: "dpkg-reconfigure -f noninteractive dash"
  register: dpkg_reconfigure

- name: STDOUT dpkg_reconfigure
  debug: 
    var: dpkg_reconfigure.stdout_lines

... its not possible to achieve what i am looking for

No, it is. You may proceed further with checking how debconf-show exim4-config works.

Further Readings

U880D
  • 8,601
  • 6
  • 24
  • 40