Files
mailgw-salt/pmg/cluster_join.sls

31 lines
1.4 KiB
YAML+Jinja

{% set cluster_join_enabled = salt['pillar.get']('pmg:cluster_join:enabled', False) %}
{% set cluster_join_master_ip = salt['pillar.get']('pmg:cluster_join:master_ip', '') %}
{% set cluster_join_fingerprint = salt['pillar.get']('pmg:cluster_join:fingerprint', '') %}
{% set cluster_join_password = salt['pillar.get']('pmg:cluster_join:password', '') %}
{% if cluster_join_enabled and cluster_join_master_ip and cluster_join_fingerprint %}
pmg-cluster-join-passwordless-ssh-check:
cmd.run:
- name: ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new root@{{ cluster_join_master_ip }} "exit 0"
- timeout: 20
{% if cluster_join_password %}
pmg-cluster-join:
cmd.run:
- name: pmgcm join {{ cluster_join_master_ip }} --fingerprint {{ cluster_join_fingerprint }}
- stdin: "{{ cluster_join_password }}"
- timeout: 60
- require:
- cmd: pmg-cluster-join-passwordless-ssh-check
- unless: "pmgcm status 2>/dev/null | awk 'BEGIN { ok=1 } /no cluster defined/ { ok=0 } END { exit(ok ? 0 : 1) }'"
{% else %}
pmg-cluster-join-skipped-password:
test.show_notification:
- text: "Cluster join skipped: set pmg.cluster_join.password (PMG root@pam password on master) for non-interactive join."
{% endif %}
{% elif cluster_join_enabled %}
pmg-cluster-join-skipped:
test.show_notification:
- text: "Cluster join skipped: set pmg.cluster_join.master_ip and pmg.cluster_join.fingerprint in pillar."
{% endif %}