Basically, you would need to perform two tasks: update hosts and run sendmailconfig.
Note: If you are running Ansible 2.5.0 you might need to install the pexpect module on the remote host, so include this task into your tasks file. For example:
- name: Update hosts
lineinfile:
path: /etc/hosts
regexp: '^127\.0\.0\.1'
line: '127.0.0.1 localhost {{ ansible_host }}'
owner: root
group: root
mode: 0644
- name: Install pexpect module
raw: sudo apt-get -y install python-pexpect
- name: Configure sendmail
expect:
command: sendmailconfig
responses:
Question:
- Configure sendmail with the existing /etc/mail/sendmail.conf? [Y]: y
- Configure sendmail with the existing /etc/mail/sendmail.mc? [Y]: y
- Reload the running sendmail now with the new configuration? [Y]: y
timeout: 30