From cd40b523c65a4df4502ec61603093819414775a5 Mon Sep 17 00:00:00 2001 From: Colin Stubbs Date: Mon, 2 Apr 2018 13:22:29 +1000 Subject: [PATCH] Add MacOS support; fix Issue #352 --- salt/map.jinja | 2 +- salt/minion.sls | 52 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/salt/map.jinja b/salt/map.jinja index eb60f560d..37a4491bc 100644 --- a/salt/map.jinja +++ b/salt/map.jinja @@ -162,7 +162,7 @@ that differ from whats in defaults.yaml }, 'MacOS': { 'salt_minion': 'com.saltstack.salt', - 'salt_minion_pkg_source': 'https://repo.saltstack.com/osx/salt-' + salt_release + '-py2-x86_64.pkg', + 'salt_minion_pkg_source': '', 'salt_minion_pkg_hash': '', 'config_path': '/private/etc/salt', 'minion_service': 'com.saltstack.salt.minion', 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 %}