fix(sys-svc-mail-msmtp,sys-ctl-hlth-msmtp): make health-check resilient on minimal images

CI run 26721196005 failed at:

  TASK [sys-service : sys-service | Fail after shared service diagnostics]
  msg: Unable to start service hlth-msmtp.9.0.2.infinito.nexus.service.

Two breakages in the start sequence:

1. `sys-ctl-hlth-msmtp/files/script.sh` called `hostname` in `$(...)`.
   The CI deploy containers ship without that binary, so `set -eu`
   aborted before msmtp ever saw stdin. Fall back to `${HOSTNAME:-...}`
   then `uname -n` then a literal "unknown".

2. `sys-svc-mail-msmtp/templates/msmtprc.conf.j2` hard-coded the trust
   file path per RedHat family — the file was missing on the deploy
   image and msmtp aborted with `Error while reading file. exit=66`.
   Probe a candidate list at deploy time (`SYS_SVC_MAIL_MSMTP_CA_BUNDLE_CANDIDATES`),
   pick the first existing path, surface it as
   `sys_svc_mail_msmtp_ca_bundle`, and install `ca-certificates`
   ahead of the probe.

`make test` 5/5 green (186 OK).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 4.7 committed 2026-05-31 22:35:12 +02:00
1 parent 033495d42f
commit d5da1c116e
6 files changed
+39 -4

No files matched your search

+2
View File
@@ -23,6 +23,7 @@ job-logs.txt
.claude/skills
.claude/agents
.claude/commands
.claude/hooks
.claude/settings.local.json
*.lock
node_modules/
@@ -42,3 +43,4 @@ node_modules/
.vscode
.zprofile
.zshrc
+3 -2
View File
@@ -2,9 +2,10 @@
set -eu
: "${MAIL_RECIPIENT:?MAIL_RECIPIENT not set}"
: "${MAIL_TIMEOUT:?MAIL_TIMEOUT not set}"
HOST="${HOSTNAME:-$(uname -n 2>/dev/null || echo unknown)}"
{
echo "To: ${MAIL_RECIPIENT}"
echo "Subject: $(hostname) is alive"
echo "Subject: ${HOST} is alive"
echo
echo "Host $(hostname) reports at $(date): I'm alive."
echo "Host ${HOST} reports at $(date): I'm alive."
} | timeout "${MAIL_TIMEOUT}"s msmtp -t
+24
View File
@@ -12,6 +12,11 @@
name: "{{ SYS_SVC_MAIL_MSMTP_PACKAGES.base }}"
state: present
- name: Ensure system CA certificates are installed
package:
name: ca-certificates
state: present
- name: "Disable SMTP to avoid port conflicts"
include_tasks: "{{ [playbook_dir, 'roles/sys-svc-mail-smtp/tasks/disable.yml' ] | path_join }}"
@@ -31,6 +36,25 @@
force: true
when: SYS_SVC_MAIL_MSMTP_PACKAGES.mta == ''
- name: Probe CA bundle candidate paths for msmtp TLS trust file
ansible.builtin.stat:
path: "{{ item }}"
loop: "{{ SYS_SVC_MAIL_MSMTP_CA_BUNDLE_CANDIDATES }}"
register: _sys_svc_mail_msmtp_ca_probe
- name: Select first existing CA bundle path for msmtp
ansible.builtin.set_fact:
sys_svc_mail_msmtp_ca_bundle: >-
{{
(
_sys_svc_mail_msmtp_ca_probe.results
| selectattr('stat.exists')
| map(attribute='item')
| list
| first
) | default(SYS_SVC_MAIL_MSMTP_CA_BUNDLE_CANDIDATES | first, true)
}}
- name: configure msmtprc.conf.j2
template:
src: "msmtprc.conf.j2"
@@ -7,7 +7,7 @@ syslog {{ MODE_DEBUG | on_off }}
auth {{ email.auth | on_off }}
tls_starttls {{ email.start_tls | on_off }}
tls {{ email.tls | on_off }}
tls_trust_file {{ '/etc/pki/tls/certs/ca-bundle.crt' if (ansible_facts['os_family'] | lower == 'redhat') else '/etc/ssl/certs/ca-certificates.crt' }}
tls_trust_file {{ sys_svc_mail_msmtp_ca_bundle }}
tls_host_override {{ email.host }}
account system_email_no_reply
host {{ '127.0.0.1' if (DOCKER_IN_CONTAINER | bool) else email.host }}
+7
View File
@@ -56,3 +56,10 @@ SYS_SVC_MAIL_MSMTP_EPEL_DISTRIBUTIONS:
- RedHat
- Rocky
- AlmaLinux
SYS_SVC_MAIL_MSMTP_CA_BUNDLE_CANDIDATES:
- /etc/pki/tls/certs/ca-bundle.crt
- /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
- /etc/ssl/certs/ca-certificates.crt
- /etc/ssl/cert.pem
- /etc/ssl/ca-bundle.pem
+2 -1
View File
@@ -70,7 +70,8 @@ discourse:
mem_reservation: 1g
mem_limit: 2g
pids_limit: 1024
local_login_enabled: "{{ not (lookup('config', 'web-app-discourse', 'services.sso.enabled') | bool) or (lookup('config', 'web-app-discourse', 'services.ldap.enabled') | bool) }}"
local_login_enabled: "{{ not (lookup('config', 'web-app-discourse', 'services.sso.enabled') | bool) or (lookup('config', 'web-app-discourse', 'services.ldap.enabled')
| bool) }}"
# nocheck: playwright-service-flag — css consumer, no Playwright surface (provider: web-svc-css)
css:
enabled: "{{ 'web-svc-css' in group_names }}"