From a28fffa7ae0cff7fa19ad6a4eeec5d9435b53a57 Mon Sep 17 00:00:00 2001 From: jack Date: Sun, 22 Mar 2026 16:55:52 +0700 Subject: [PATCH] fix: mailserver account check via host file, not docker exec setup email list fails with rc=1 when postfix-accounts.cf doesn't exist yet (fresh install). Check the mounted config file on the host instead, which correctly handles the empty/missing case. Co-Authored-By: Claude Sonnet 4.6 --- roles/tools/tasks/main.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/roles/tools/tasks/main.yml b/roles/tools/tasks/main.yml index 8bf6b99..398571b 100644 --- a/roles/tools/tasks/main.yml +++ b/roles/tools/tasks/main.yml @@ -61,16 +61,26 @@ delay: 10 until: postfix_status.rc == 0 +# Check the host-side mounted config file directly (setup email list fails if file doesn't exist yet) - name: Check if noreply mail account exists + ansible.builtin.stat: + path: "{{ tools_root }}/mailserver/config/postfix-accounts.cf" + register: postfix_accounts_file + +- name: Check noreply account in postfix-accounts.cf ansible.builtin.command: > - docker exec mailserver setup email list - register: mail_accounts + grep -q "noreply@{{ domain_base }}" {{ tools_root }}/mailserver/config/postfix-accounts.cf + register: mail_account_check changed_when: false + failed_when: false + when: postfix_accounts_file.stat.exists - name: Create noreply mail account ansible.builtin.command: > docker exec mailserver setup email add noreply@{{ domain_base }} {{ mailserver_noreply_password }} - when: "'noreply@' + domain_base not in mail_accounts.stdout" + when: > + not postfix_accounts_file.stat.exists or + (mail_account_check.rc is defined and mail_account_check.rc != 0) - name: Check if DKIM key exists ansible.builtin.stat: