From eab6e1b85fb79a0fd67876d477fe178b161606c5 Mon Sep 17 00:00:00 2001 From: Joe Groocock Date: Sun, 12 Jul 2020 09:50:30 +0100 Subject: [PATCH] Manage salt-minion package, service and config Restart the service after upgrading the package or modifying the minion configuration file. Signed-off-by: Joe Groocock --- states/salt/minion/init.sls | 38 +++++++++++++++++++++++++++++ states/salt/minion/templates/minion | 26 ++++++++++++++++++++ states/top.sls | 1 + 3 files changed, 65 insertions(+) create mode 100644 states/salt/minion/init.sls create mode 100644 states/salt/minion/templates/minion diff --git a/states/salt/minion/init.sls b/states/salt/minion/init.sls new file mode 100644 index 0000000..dc797ac --- /dev/null +++ b/states/salt/minion/init.sls @@ -0,0 +1,38 @@ +{%- set masters = ['salt.nerdhouse.io'] %} + +salt-minion: + pkg.installed: + - version: latest + service.running: + - enable: true + - require: + - pkg: salt-minion + - file: /etc/salt/minion + +restart-salt-minion: + service.restart: + - name: salt-minion + - order: last + - no_block: true + - watch: + - pkg: salt-minion + - file: /etc/salt/minion + - require: + - cmd: check-minion-config + +/etc/salt/minion: + file.managed: + - source: salt://{{ slspath }}/minion.jinja + - user: root + - group: root + - mode: 644 + - context: + - masters: {{ masters|json }} + - require: + - pkg: salt-minion + +check-minion-config: + cmd.run: + - name: sudo salt-call --local --skip-grains test.ping + - watch: + - file: /etc/salt/minion diff --git a/states/salt/minion/templates/minion b/states/salt/minion/templates/minion new file mode 100644 index 0000000..3d15089 --- /dev/null +++ b/states/salt/minion/templates/minion @@ -0,0 +1,26 @@ +id: {{ minion_id }} +log_level: info +ipv6: true +ssl: true +transport: tcp + +# https://github.com/saltstack/salt/blob/b95213ec903402f25c1e0aeb3990fe8452ab63ce/conf/minion#L39-L47 +# str, failover or disable +master_type: str +{% if masters is defined %} +master: + {%- for master in masters %} +- {{ master }} + {%- endfor %} +{%- endif %} + +# set the default saltenv for highstate +# otherwise it tries to run all of them 🤔 +saltenv: base +# useful for influencing git_pillar and gitfs at the same time +pillarenv_from_saltenv: true + +enable_fqdns_grains: false +enable_gpu_grains: false + +# vim: ft=yaml diff --git a/states/top.sls b/states/top.sls index a5c0bee..f178fbf 100644 --- a/states/top.sls +++ b/states/top.sls @@ -2,3 +2,4 @@ '*': - users - sshd + - salt.minion