fix: make mail account creation idempotent by ignoring 'already exists' error
Replace fragile file-content lookup with proper failed_when that accepts 'already exists' exit code 1 as a non-failure. Simpler and works on every run. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
836d554e7b
commit
aa6b20c463
1 changed files with 5 additions and 8 deletions
|
|
@ -131,11 +131,6 @@
|
|||
delay: 10
|
||||
until: postfix_status.rc == 0
|
||||
|
||||
- name: Check postfix-accounts.cf exists
|
||||
ansible.builtin.stat:
|
||||
path: "{{ tools_root }}/mailserver/config/postfix-accounts.cf"
|
||||
register: postfix_accounts_file
|
||||
|
||||
- name: Create mail accounts
|
||||
ansible.builtin.command: >
|
||||
docker exec mailserver setup email add {{ item.address }} {{ item.password }}
|
||||
|
|
@ -143,9 +138,11 @@
|
|||
- { address: "noreply@{{ domain_base }}", password: "{{ mailserver_noreply_password }}" }
|
||||
- { address: "admin@{{ domain_base }}", password: "{{ mailserver_admin_password }}" }
|
||||
- { address: "jack@{{ domain_base }}", password: "{{ mailserver_jack_password }}" }
|
||||
when: >
|
||||
not postfix_accounts_file.stat.exists or
|
||||
item.address not in (lookup('file', tools_root + '/mailserver/config/postfix-accounts.cf', errors='ignore') | default('', true))
|
||||
register: mail_account_result
|
||||
changed_when: mail_account_result.rc == 0
|
||||
failed_when: >
|
||||
mail_account_result.rc != 0 and
|
||||
'already exists' not in mail_account_result.stderr
|
||||
|
||||
# ── DKIM ─────────────────────────────────────────────────────────────────────
|
||||
- name: Check if DKIM key exists
|
||||
|
|
|
|||
Loading…
Reference in a new issue