Install Mailcatcher on Ubuntu 16.04 with Ansible

I’ve been using Ansible to provision my Vagrant boxes since much of the work for provisioning can be replicated in production and staging environments. One of the tools I find essential is Mailcatcher. The following Ansible tasks handle this for me:

- name: Install Mailcatcher Dependencies
  apt: name={{item}} state=installed
    - build-essential
    - ruby
    - ruby-dev
    - sqlite3
    - libsqlite3-dev
- name: Install mailcatcher
  gem: name=mailcatcher state=present
- name: Create mailcatcher service file
    src: templates/mailcatcher.service.j2
    dest: /lib/systemd/system/mailcatcher.service
- name: Enable mailcatcher service
  systemd: name=mailcatcher enabled=yes state=started
- name: Update php cli settings for mailcatcher
  ini_file: dest=/etc/php/7.0/cli/php.ini create=no option=sendmail_path value='/usr/local/bin/catchmail -f' section=sendmail
- name: Update php fpm settings for mailcatcher
  ini_file: dest=/etc/php/7.0/fpm/php.ini create=no option=sendmail_path value='/usr/local/bin/catchmail -f' section=sendmail

In my templates folder (under my Ansible playbook root where the above exists), I have a systemd Unit called mailcatcher.service that is as follows:

After=network.service vagrant.mount
ExecStart=/usr/local/bin/mailcatcher --foreground --ip

I’d like to update this to it’s own ansible role, and I may do that soon. If I do, I will try to remember to update this post :).

Leave a Reply