
Resolve "add smtp relay"

Closes #31 (closed)
Merge request reports
Activity
added Doing label
assigned to @arthur.boudreault
I've been working on this subject all day and os far I haven't found the best way to handle that issue.
The best way would be for Ansible to be able to recognize when the smtp_* variables have changed so it triggers the set command and otherwise it does nothing. This is the normal behaviour of Ansible and its Python modules however it doesn't work this way for the command module and so you have to implement these tests by yourself.
I have found two ways but both are imperfect:
- 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
Doing like this for the four settings. This provides a working check (only triggers a change if variables between the system and Ansible are different otherwise skipping the task) but this is not optimized and quite redundant.
- 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 }}"
This solution is better BUT I haven't found a way to implement a check with WHEN because I can't find a way to easily manipulate data contained in registered variable
_ynh_smtp_current_values
so here it triggers a change at every play.Do you have any suggestions @cchaudier @thomas_michel ?
Edited by Arthur BOUDREAULT- Resolved by Arthur BOUDREAULT
added Need review label and removed Doing label
- Resolved by Arthur BOUDREAULT
- Resolved by Arthur BOUDREAULT
- Resolved by Arthur BOUDREAULT
- Resolved by Arthur BOUDREAULT
- Resolved by Arthur BOUDREAULT
added 1 commit
- 37760097 - refactor(yunohost): Apply suggestions to smtp relay feat code
- Resolved by Arthur BOUDREAULT