|
| 1 | +--- |
| 2 | +- name: Download latest Mailpit install script. |
| 3 | + ansible.builtin.get_url: |
| 4 | + url: https://raw.githubusercontent.com/axllent/mailpit/develop/install.sh |
| 5 | + dest: "{{ mailpit.script_install_path }}/mailpit-install.sh" |
| 6 | + mode: '0750' |
| 7 | + owner: "{{ mailpit.user }}" |
| 8 | + group: "{{ mailpit.group }}" |
| 9 | + force: true |
| 10 | + |
| 11 | +- name: Attempt to install Mailpit. |
| 12 | + ansible.builtin.command: |
| 13 | + cmd: "{{ mailpit.script_install_path }}/mailpit-install.sh" |
| 14 | + |
| 15 | +- name: Generate SSL keys if requested. |
| 16 | + ansible.builtin.include_role: |
| 17 | + name: debian/ssl |
| 18 | + vars: |
| 19 | + ssl: "{{ mailpit.ssl }}" |
| 20 | + when: mailpit.create_cert |
| 21 | + |
| 22 | +- name: Copy basic htauth file to server. |
| 23 | + ansible.builtin.copy: |
| 24 | + src: "{{ mailpit.web_ui_authfile_src }}" |
| 25 | + dest: "{{ mailpit.web_ui_authfile_dest }}" |
| 26 | + owner: root |
| 27 | + group: root |
| 28 | + mode: 0644 |
| 29 | + when: mailpit.web_ui_authfile_dest | length > 0 |
| 30 | + |
| 31 | +- name: Start the launch string for the Mailpit service with the database location. |
| 32 | + ansible.builtin.set_fact: |
| 33 | + _mailpit_service_command: "-d {{ mailpit.database_directory }}/{{ mailpit.database_filename }}" |
| 34 | + when: mailpit.service |
| 35 | + |
| 36 | +- name: Add web UI settings to launch string for Mailpit. |
| 37 | + ansible.builtin.set_fact: |
| 38 | + _mailpit_service_command: "{{ _mailpit_service_command }} --listen {{ mailpit.web_ui_listen }} --webroot {{ mailpit.web_ui_webroot }}" |
| 39 | + when: mailpit.service |
| 40 | + |
| 41 | +- name: Add SMTP settings to launch string for Mailpit. |
| 42 | + ansible.builtin.set_fact: |
| 43 | + _mailpit_service_command: "{{ _mailpit_service_command }} --smtp {{ mailpit.smtp_listen }}" |
| 44 | + when: mailpit.service |
| 45 | + |
| 46 | +- name: Add auth file to the launch string for Mailpit. |
| 47 | + ansible.builtin.set_fact: |
| 48 | + _mailpit_service_command: "{{ _mailpit_service_command }} --ui-auth-file {{ mailpit.web_ui_authfile_dest }}" |
| 49 | + when: |
| 50 | + - mailpit.service |
| 51 | + - mailpit.web_ui_authfile_dest | length > 0 |
| 52 | + |
| 53 | +- name: Add SSL options to the launch string for Mailpit. |
| 54 | + ansible.builtin.set_fact: |
| 55 | + _mailpit_service_command: "{{ _mailpit_service_command }} --ui-tls-cert {{ mailpit.web_ui_ssl_cert }} --ui-tls-key {{ mailpit.web_ui_ssl_key }}" |
| 56 | + when: |
| 57 | + - mailpit.service |
| 58 | + - mailpit.https |
| 59 | + |
| 60 | +- name: Add any additionally provided options to the launch string for Mailpit. |
| 61 | + ansible.builtin.set_fact: |
| 62 | + _mailpit_service_command: "{{ _mailpit_service_command }} {{ mailpit.additional_options }}" |
| 63 | + when: |
| 64 | + - mailpit.service |
| 65 | + - mailpit.additional_options | length > 0 |
| 66 | + |
| 67 | +- name: Copy systemd service file to server. |
| 68 | + ansible.builtin.template: |
| 69 | + src: mailpit.service.j2 |
| 70 | + dest: "/etc/systemd/system/mailpit.service" |
| 71 | + owner: root |
| 72 | + group: root |
| 73 | + mode: 0755 |
| 74 | + when: mailpit.service |
| 75 | + |
| 76 | +- name: Ensure the database directory exists and is writeable. |
| 77 | + ansible.builtin.file: |
| 78 | + path: "{{ mailpit.database_directory }}" |
| 79 | + state: directory |
| 80 | + |
| 81 | +- name: Start Mailpit. |
| 82 | + ansible.builtin.systemd_service: |
| 83 | + name: mailpit |
| 84 | + state: started |
| 85 | + daemon_reload: true |
| 86 | + enabled: true |
| 87 | + when: mailpit.service |
0 commit comments