Add an idempotent baseline step that enforces myhostname/mydomain from hostname -f and reloads postfix only when drift is detected. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.6 KiB
YAML+Jinja
51 lines
1.6 KiB
YAML+Jinja
{% set pmg_services = salt['pillar.get']('pmg:pmg_services', []) %}
|
|
{% set pmg_cluster_only_services = salt['pillar.get']('pmg:pmg_cluster_only_services', ['pmgmirror', 'pmgtunnel']) %}
|
|
{% set manage_hosts_file = salt['pillar.get']('pmg:manage_hosts_file', False) %}
|
|
{% set hosts_file_entries = salt['pillar.get']('pmg:hosts_file_entries', []) %}
|
|
|
|
{% for svc in pmg_services %}
|
|
pmg-service-{{ svc }}:
|
|
service.running:
|
|
- name: {{ svc }}
|
|
- enable: true
|
|
{% if svc in pmg_cluster_only_services %}
|
|
- onlyif: "pmgcm status 2>/dev/null | awk 'BEGIN { ok=1 } /no cluster defined/ { ok=0 } END { exit(ok ? 0 : 1) }'"
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
pmg-cluster-status:
|
|
cmd.run:
|
|
- name: pmgcm status
|
|
|
|
pmg-postfix-identity-from-system-hostname:
|
|
cmd.run:
|
|
- name: >-
|
|
HN="$(hostname -f)" &&
|
|
DM="${HN#*.}" &&
|
|
postconf -e "myhostname=${HN}" "mydomain=${DM}" &&
|
|
systemctl reload postfix
|
|
- unless: >-
|
|
HN="$(hostname -f)" &&
|
|
DM="${HN#*.}" &&
|
|
[ "$(postconf -h myhostname)" = "${HN}" ] &&
|
|
[ "$(postconf -h mydomain)" = "${DM}" ]
|
|
- require:
|
|
- service: pmg-service-postfix
|
|
|
|
{% if manage_hosts_file %}
|
|
pmg-managed-hosts:
|
|
file.blockreplace:
|
|
- name: /etc/hosts
|
|
- marker_start: "#-- SALT PMG HOSTS START --"
|
|
- marker_end: "#-- SALT PMG HOSTS END --"
|
|
- append_if_not_found: true
|
|
- content: |
|
|
{% for host in hosts_file_entries %}
|
|
{% if host.get('aliases', []) %}
|
|
{{ host['ip'] }} {{ host['hostname'] }} {{ ' '.join(host['aliases']) }}
|
|
{% else %}
|
|
{{ host['ip'] }} {{ host['hostname'] }}
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% endif %}
|