From 5ed539536a2fb1eb2eee5b2e0822e1df5779a541 Mon Sep 17 00:00:00 2001 From: Arthur BOUDREAULT <boudreaultarthur@ik.me> Date: Mon, 25 Oct 2021 16:19:30 +0200 Subject: [PATCH] feat: Added smtp_relay support --- defaults/main.yml | 9 ++++++ tasks/main.yml | 4 +++ tasks/smtp_relay.yml | 72 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 tasks/smtp_relay.yml diff --git a/defaults/main.yml b/defaults/main.yml index 2971031..8c49cfa 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -36,6 +36,15 @@ ynh_users: null # lastname: Doe # mail_domain: domain.tld +# SMTP custom settings ( Only override if you need a SMTP relay) +ynh_smtp_get_cli: yunohost settings get smtp.relay +ynh_smtp_set_cli: yunohost settings set smtp.relay +ynh_new_smtp_relay: null + # host: smtp.domain.tld + # port: 25 + # user: user1 + # password: Pa$$w0rd + # The list of Yunohost apps. ynh_apps: null # - label: Tiny Tiny RSS diff --git a/tasks/main.yml b/tasks/main.yml index e0f8b73..9cb201e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -60,6 +60,10 @@ ansible.builtin.command: yunohost domain cert-install changed_when: False +- name: Configure SMTP relay + ansible.builtin.include_tasks: smtp_relay.yml + when: ynh_new_smtp_relay + - name: Add Yunohost users ansible.builtin.include_tasks: users.yml when: ynh_users diff --git a/tasks/smtp_relay.yml b/tasks/smtp_relay.yml new file mode 100644 index 0000000..4259de6 --- /dev/null +++ b/tasks/smtp_relay.yml @@ -0,0 +1,72 @@ +--- +#-----------------------------------------------------------------------------# +# ansible-yunohost allows to deploy Yunohost using Ansible # +# Copyright 2021-2021 Lydra https://www.lydra.fr/ # +# # +# this program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# this program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <http://www.gnu.org/licenses/>. # +# # +#-----------------------------------------------------------------------------# + +# - name: Get current SMTP relay host +# ansible.builtin.command: "{{ ynh_smtp_get_cli }}.host" +# register: ynh_old_smtp_relay_host +# changed_when: False + +# - name: Set new SMTP relay host +# ansible.builtin.command: "{{ ynh_smtp_set_cli }}.host -v {{ ynh_new_smtp_relay.host }}" +# when: ynh_old_smtp_relay_host.stdout != ynh_new_smtp_relay.host + +# - name: Get current SMTP relay port +# ansible.builtin.command: "{{ ynh_smtp_get_cli }}.port" +# register: ynh_old_smtp_port +# changed_when: False + +# - name: Set new SMTP relay port +# ansible.builtin.command: "{{ ynh_smtp_set_cli }}.host -v {{ ynh_new_smtp_relay.port }}" +# when: ynh_old_smtp_port.stdout != ynh_new_smtp_relay.port + +# - name: Get current SMTP relay username +# ansible.builtin.command: "{{ ynh_smtp_get_cli }}.user" +# register: ynh_old_smtp_user +# changed_when: False + +# - name: Set new SMTP relay username +# ansible.builtin.command: "{{ ynh_smtp_set_cli }}.user -v {{ ynh_new_smtp_relay.user }}" +# when: ynh_old_smtp_user.stdout != ynh_new_smtp_relay.user + +# - name: Get current SMTP relay password +# ansible.builtin.command: "{{ ynh_smtp_get_cli }}.password" +# register: ynh_old_smtp_password +# changed_when: False + +# - name: Set new SMTP relay password +# ansible.builtin.command: "{{ ynh_smtp_set_cli }}.host -v {{ ynh_new_smtp_relay.password }}" +# when: ynh_old_smtp_password.stdout != ynh_new_smtp_relay.password + +# - name: Set new SMTP relay port +# ansible.builtin.command: "{{ ynh_smtp_set_cli }}.host -v {{ ynh_smtp_relay.host }}" +# when: ynh_smtp_host_config.stdout != ynh_smtp_relay.host + +- name: Get current SMTP settings + ansible.builtin.command: + "{{ ynh_smtp_get_cli }}.{{ item }}" + register: _ynh_smtp_current_values + with_items: "{{ ynh_new_smtp_relay }}" + changed_when: False + +- name: Set new SMTP settings + ansible.builtin.command: + "{{ ynh_smtp_set_cli }}.{{ item.key }} -v {{ item.value }}" + with_items: "{{ ynh_new_smtp_relay | dict2items }}" + changed_when: False -- GitLab