Skip to content

Commit

Permalink
Add MacOS support; fix Issue saltstack-formulas#352
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-stubbs committed Apr 2, 2018
1 parent 9a81ab2 commit cd40b52
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion salt/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
52 changes: 50 additions & 2 deletions salt/minion.sls
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 %}

0 comments on commit cd40b52

Please sign in to comment.