Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects

:white_check_mark:Resolve "add smtp relay"

Merged Arthur BOUDREAULT requested to merge 31-add-smtp-relay into main

Closes #31 (closed)

Edited by Arthur BOUDREAULT

Merge request reports

Pipeline #2930 passed with warnings

Pipeline passed with warnings for 11cd568e on 31-add-smtp-relay

Merged by Christophe ChaudierChristophe Chaudier 3 years ago (Oct 26, 2021 1:52pm UTC)

Loading

Pipeline #2931 passed with warnings

Pipeline passed with warnings for c17121b3 on main

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • added Doing label

  • 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
  • added 1 commit

    • 5ed53953 - feat: Added smtp_relay support

    Compare with previous version

  • Christophe Chaudier
  • added 1 commit

    • f479aba2 - feat(yunohost): add SMTP relay support

    Compare with previous version

  • Arthur BOUDREAULT resolved all threads

    resolved all threads

  • Arthur BOUDREAULT changed title from Draft: Resolve "add smtp relay" to Draft: :white_check_mark:Resolve "add smtp relay"

    changed title from Draft: Resolve "add smtp relay" to Draft: :white_check_mark:Resolve "add smtp relay"

  • Arthur BOUDREAULT added Need review label and removed Doing label

    added Need review label and removed Doing label

  • Arthur BOUDREAULT marked this merge request as ready

    marked this merge request as ready

  • Christophe Chaudier
  • added 1 commit

    • 37760097 - refactor(yunohost): Apply suggestions to smtp relay feat code

    Compare with previous version

  • Arthur BOUDREAULT resolved all threads

    resolved all threads

  • Christophe Chaudier
  • Arthur BOUDREAULT resolved all threads

    resolved all threads

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading