From a2a4fc5af5f007118bb714a7bfbd592ad8289c83 Mon Sep 17 00:00:00 2001 From: Colin Stubbs Date: Mon, 2 Apr 2018 13:17:44 +1000 Subject: [PATCH] Add MacOS minion upgrade support Fixes issue #352 --- salt/minion.sls | 52 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/salt/minion.sls b/salt/minion.sls index eb65eecc9..0286742e4 100644 --- a/salt/minion.sls +++ b/salt/minion.sls @@ -1,13 +1,43 @@ {% from "salt/map.jinja" import salt_settings with context %} -{% if grains.os != "MacOS" %} +{% if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source != '' and salt_settings.version != '' %} +{# only download IF we know where to get the pkg from and if we know what version to check the current install (if installed) against #} +{# e.g. don't download unless it appears as though we're about to try and upgrade the minion #} +download-salt-minion: + file.managed: + - name: '/tmp/salt.pkg' + - source: {{ salt_settings.salt_minion_pkg_source }} + {% if salt_settings.salt_minion_pkg_hash != '' %} + - source_hash: {{ salt_settings.salt_minion_pkg_hash }} + {% else %} + - skip_verify: True + {% endif %} + - user: root + - group: wheel + - mode: 0644 + - unless: + - '/opt/salt/bin/salt-minion --version | grep {{ salt_settings.version }}' + - require_in: + - macpackage: salt-minion +{% endif %} + salt-minion: {% if salt_settings.install_packages %} + {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source != '' and salt_settings.version != '' %} + macpackage.installed: + - name: '/tmp/salt.pkg' + - target: / + {# macpackage.installed behaves weirdly with version_check; version_check detects difference but fails to actually complete install. #} + {# use force == True as workaround #} + - force: True + - version_check: /opt/salt/bin/salt-minion --version=.*{{ salt_settings.version }}.* + {%- else %} pkg.installed: - name: {{ salt_settings.salt_minion }} {%- if salt_settings.version is defined %} - version: {{ salt_settings.version }} {%- endif %} + {%- endif %} {% endif %} file.recurse: - name: {{ salt_settings.config_path }}/minion.d @@ -45,23 +75,35 @@ salt-minion: {%- endif %} - onchanges: {%- if salt_settings.install_packages %} + {%- if grains.os == 'MacOS' %} + - macpackage: salt-minion + {%- else %} - pkg: salt-minion + {%- endif %} {%- endif %} - file: salt-minion - file: remove-old-minion-conf-file {%- else %} + + {% if grains.os != 'MacOS' %} + {# MacOS has 'at' command; but there's no package to install #} at: pkg.installed: [] + {% endif %} restart-salt-minion: cmd.run: - - name: echo salt-call --local service.restart salt-minion | at now + 1 minute + - name: echo salt-call --local service.restart {{ salt_settings.minion_service }} | at now + 1 minute - order: last - require: - pkg: at - onchanges: {%- if salt_settings.install_packages %} + {%- if grains.os == 'MacOS' %} + - macpackage: salt-minion + {%- else %} - pkg: salt-minion + {%- endif %} {%- endif %} - file: salt-minion - file: remove-old-minion-conf-file @@ -88,4 +130,10 @@ remove-old-minion-conf-file: file.absent: - name: {{ salt_settings.config_path }}/minion.d/_defaults.conf +{% if grains.os == 'MacOS' %} +remove-macpackage-salt: + cmd.run: + - name: 'rm -f /tmp/salt.pkg' + - onchanges: + - macpackage: salt-minion {% endif %}