From 94027f7332093764553162d9e80074029647f7ef Mon Sep 17 00:00:00 2001 From: N Date: Wed, 22 Jan 2020 15:55:42 +0000 Subject: [PATCH 1/5] feat(macos): basic launchctl service support --- salt/defaults.yaml | 2 ++ salt/master.sls | 21 +++++++++++++++++++ salt/minion.sls | 51 +++++++++++++++++++++++++++++++++++----------- salt/osmap.yaml | 4 ++++ 4 files changed, 66 insertions(+), 12 deletions(-) diff --git a/salt/defaults.yaml b/salt/defaults.yaml index e2a8dbf..4c42944 100644 --- a/salt/defaults.yaml +++ b/salt/defaults.yaml @@ -24,6 +24,8 @@ salt: salt_master: salt-master salt_minion: salt-minion + salt_master_macos_plist_hash: '' + salt_minion_macos_plist_hash: '' salt_syndic: salt-syndic salt_cloud: salt-cloud salt_api: salt-api diff --git a/salt/master.sls b/salt/master.sls index 4a23cca..2003be3 100644 --- a/salt/master.sls +++ b/salt/master.sls @@ -2,6 +2,27 @@ {%- from tplroot ~ "/map.jinja" import salt_settings with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} + {%- if grains.os == 'MacOS' %} +salt-master-macos: + file.managed: + - name: /Library/LaunchDaemons/com.saltstack.salt.master.plist + - source: https://raw.githubusercontent.com/saltstack/salt/master/pkg/darwin/com.saltstack.salt.master.plist + - source_hash: {{ salt_settings.salt_master_macos_plist_hash }} + - retry: + attempts: 2 + until: True + interval: 10 + splay: 10 + cmd.run: + - names: + - launchctl load -w /Library/LaunchDaemons/com.saltstack.salt.master.plist + - launchctl unload /Library/LaunchDaemons/com.saltstack.salt.master.plist + - require: + - file: salt-master-macos + - require_in: + - service: salt-master + {%- endif %} + salt-master: {% if salt_settings.install_packages %} pkg.installed: diff --git a/salt/minion.sls b/salt/minion.sls index e492a49..01cbe42 100644 --- a/salt/minion.sls +++ b/salt/minion.sls @@ -2,33 +2,60 @@ {%- from tplroot ~ "/map.jinja" import salt_settings with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} -{% if salt_settings.install_packages and grains.os == 'MacOS' %} + {%- if grains.os == 'MacOS' %} + {% if salt_settings.install_packages %} download-salt-minion: - {% if salt_settings.salt_minion_pkg_source %} - {# only download IF we know where to get the pkg from and 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 #} + {% if salt_settings.salt_minion_pkg_source %} + {# only IF we know source and version to check the current install (if installed) against #} + {# e.g. don't download unless a minion upgrade is happening #} file.managed: - name: '/tmp/salt.pkg' - source: {{ salt_settings.salt_minion_pkg_source }} - {%- if salt_settings.salt_minion_pkg_hash %} + {%- if salt_settings.salt_minion_pkg_hash %} - source_hash: {{ salt_settings.salt_minion_pkg_hash }} - {% else %} + {% else %} - skip_verify: True - {% endif %} + {% endif %} - user: root - group: wheel - - mode: 0644 + - mode: '0644' - unless: - test -n "{{ salt_settings.version }}" && '/opt/salt/bin/salt-minion --version=.*{{ salt_settings.version }}.*' - require_in: - macpackage: salt-minion - {%- elif "workaround https://github.com/saltstack/salt/issues/49348" %} + - retry: + attempts: 2 + until: True + interval: 10 + splay: 10 + {%- elif "workaround https://github.com/saltstack/salt/issues/49348" %} cmd.run: - name: /usr/local/bin/brew install {{ salt_settings.salt_minion }} - onlyif: test -x /usr/local/bin/brew - runas: {{ salt_settings.rootuser }} - {%- endif %} -{% endif %} + {%- endif %} + +salt-minion-macos: + file.managed: + - onlyif: {{ grains.os == 'MacOS' }} + - name: /Library/LaunchDaemons/com.saltstack.salt.minion.plist + - source: https://raw.githubusercontent.com/saltstack/salt/master/pkg/darwin/com.saltstack.salt.minion.plist + - source_hash: {{ salt_settings.salt_minion_macos_plist_hash }} + - retry: + attempts: 2 + until: True + interval: 10 + splay: 10 + cmd.run: + - names: + - launchctl load -w /Library/LaunchDaemons/com.saltstack.salt.minion.plist + - launchctl unload /Library/LaunchDaemons/com.saltstack.salt.minion.plist + - require: + - file: salt-minion-macos + - require_in: + - service: salt-minion + {%- endif %} +{%- endif %} salt-minion: {% if salt_settings.install_packages %} @@ -36,7 +63,7 @@ salt-minion: macpackage.installed: - name: '/tmp/salt.pkg' - target: / - {# macpackage.installed behaves weirdly with version_check; version_check detects difference but fails to actually complete install. #} + {# macpackage.installed behaves weirdly with version_check, detects diff but fails to complete install. #} {# use force == True as workaround #} - force: True - unless: diff --git a/salt/osmap.yaml b/salt/osmap.yaml index 55d16b3..6bc77ec 100644 --- a/salt/osmap.yaml +++ b/salt/osmap.yaml @@ -57,3 +57,7 @@ SmartOS: config_path: /opt/local/etc/salt master: gitfs_provider: dulwich + +MacOS: + salt_master_macos_plist_hash: 9c55cb448269f4d7c433429448d1ec7dda260f180bbcf5197bc430f7645017de + salt_minion_macos_plist_hash: 6383d2d336b06802bfdf25a4c21ee25c85ee9fa57d3ef5776321d9c8cd096395 From 37eb3b35141885fe16ddc59d0ba45b29dbd5babe Mon Sep 17 00:00:00 2001 From: N Date: Wed, 22 Jan 2020 15:56:12 +0000 Subject: [PATCH 2/5] test(versions): bump pkg versions --- test/integration/v201803-py2/controls/pkgs_spec.rb | 4 ++-- test/integration/v201902-py2/controls/pkgs_spec.rb | 13 +++++++++---- test/integration/v201902-py3/controls/pkgs_spec.rb | 8 ++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/test/integration/v201803-py2/controls/pkgs_spec.rb b/test/integration/v201803-py2/controls/pkgs_spec.rb index 37f5aae..22d6ee8 100644 --- a/test/integration/v201803-py2/controls/pkgs_spec.rb +++ b/test/integration/v201803-py2/controls/pkgs_spec.rb @@ -1,9 +1,9 @@ version = case platform[:family] when 'redhat' - '2018.3.4-1.el7' + '2018.3.5-1.el7' when 'debian' - '2018.3.4+ds-1' + '2018.3.5+ds-1' end control 'salt packages' do diff --git a/test/integration/v201902-py2/controls/pkgs_spec.rb b/test/integration/v201902-py2/controls/pkgs_spec.rb index a5ed397..e0bfd3e 100644 --- a/test/integration/v201902-py2/controls/pkgs_spec.rb +++ b/test/integration/v201902-py2/controls/pkgs_spec.rb @@ -1,13 +1,18 @@ version = case platform[:family] when 'redhat' - '2019.2.1-1.el7' - when 'fedora' - '2019.2.0-1.fc30' + case platform[:name] + when 'amazon' + '2019.2.3-1.el7' + when 'centos' + '2019.2.1-1.el7' + when 'fedora' + '2019.2.0-1.fc30' + end when 'suse' '2019.2.0-lp151.5.3.1' when 'debian' - '2019.2.1+ds-1' + '2019.2.3+ds-1' end control 'salt packages' do diff --git a/test/integration/v201902-py3/controls/pkgs_spec.rb b/test/integration/v201902-py3/controls/pkgs_spec.rb index 99b1b27..e1c0ba2 100644 --- a/test/integration/v201902-py3/controls/pkgs_spec.rb +++ b/test/integration/v201902-py3/controls/pkgs_spec.rb @@ -6,13 +6,13 @@ version = '2019.2.0-1.el7' when 'centos' '2019.2.1-1.el7' + when 'fedora' + '2019.2.0-1.fc30' end - when 'fedora' - '2019.2.0-1.fc30' when 'suse' - '2019.2.0-lp151.5.3.1' + '2019.2.0-lp151.5.9.1' when 'debian' - '2019.2.1+ds-1' + '2019.2.3+ds-1' end control 'salt packages' do From 8875b93eb7f39e4a10e04c81225d1d488314a8af Mon Sep 17 00:00:00 2001 From: N Date: Sat, 13 Jun 2020 21:11:28 +0100 Subject: [PATCH 3/5] chore(pr): adopt pr comments; indent jinja --- salt/master.sls | 23 ++++++----- salt/minion.sls | 107 ++++++++++++++++++++++++------------------------ 2 files changed, 66 insertions(+), 64 deletions(-) diff --git a/salt/master.sls b/salt/master.sls index c225d47..ff68a4f 100644 --- a/salt/master.sls +++ b/salt/master.sls @@ -11,7 +11,7 @@ include: salt-master-macos: file.managed: - name: /Library/LaunchDaemons/com.saltstack.salt.master.plist - - source: https://raw.githubusercontent.com/saltstack/salt/master/pkg/darwin/com.saltstack.salt.master.plist + - source: https://raw.githubusercontent.com/saltstack/salt/master/pkg/osx/scripts/com.saltstack.salt.master.plist - source_hash: {{ salt_settings.salt_master_macos_plist_hash }} - retry: attempts: 2 @@ -29,19 +29,19 @@ salt-master-macos: {%- endif %} salt-master: -{% if salt_settings.install_packages %} + {% if salt_settings.install_packages %} pkg.installed: - name: {{ salt_settings.salt_master }} - {%- if salt_settings.version is defined %} + {%- if salt_settings.version is defined %} - version: {{ salt_settings.version }} - {%- endif %} -{% if salt_settings.master_service_details.state != 'ignore' %} + {%- endif %} + {% if salt_settings.master_service_details.state != 'ignore' %} - require_in: - service: salt-master - watch_in: - service: salt-master -{% endif %} -{% endif %} + {% endif %} + {% endif %} file.recurse: - name: {{ salt_settings.config_path }}/master.d {%- if salt_settings.master_config_use_TOFS %} @@ -56,19 +56,20 @@ salt-master: {%- endif %} - clean: {{ salt_settings.clean_config_d_dir }} - exclude_pat: _* -{% if salt_settings.master_service_details.state != 'ignore' %} + {% if salt_settings.master_service_details.state != 'ignore' %} service.{{ salt_settings.master_service_details.state }}: - enable: {{ salt_settings.master_service_details.enabled }} - name: {{ salt_settings.master_service }} - watch: + - file: salt-master-macos - file: salt-master - file: remove-old-master-conf-file -{% endif %} -{% if salt_settings.master_remove_config %} + {% endif %} + {% if salt_settings.master_remove_config %} remove-default-master-conf-file: file.absent: - name: {{ salt_settings.config_path }}/master -{% endif %} + {% endif %} # clean up old _defaults.conf file if they have it around remove-old-master-conf-file: diff --git a/salt/minion.sls b/salt/minion.sls index 6d8cb1c..3a9c174 100644 --- a/salt/minion.sls +++ b/salt/minion.sls @@ -42,7 +42,7 @@ salt-minion-macos: file.managed: - onlyif: {{ grains.os == 'MacOS' }} - name: /Library/LaunchDaemons/com.saltstack.salt.minion.plist - - source: https://raw.githubusercontent.com/saltstack/salt/master/pkg/darwin/com.saltstack.salt.minion.plist + - source: https://raw.githubusercontent.com/saltstack/salt/master/pkg/osx/scripts/com.saltstack.salt.master.plist - source_hash: {{ salt_settings.salt_minion_macos_plist_hash }} - retry: attempts: 2 @@ -57,38 +57,37 @@ salt-minion-macos: - file: salt-minion-macos - require_in: - service: salt-minion + {%- endif %} {%- endif %} -{%- endif %} salt-minion: -{% if salt_settings.install_packages %} - {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %} + {% if salt_settings.install_packages %} + {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %} macpackage.installed: - name: '/tmp/salt.pkg' - target: / - {# macpackage.installed behaves weirdly with version_check, detects diff but fails to complete install. #} - {# use force == True as workaround #} - - force: True + {# macpackage.installed is weird with version_check, detects diff but incomplete install #} + - force: True {# workaround #} - unless: - test -n "{{ salt_settings.version }}" && '/opt/salt/bin/salt-minion --version=.*{{ salt_settings.version }}.*' -{% if salt_settings.minion_service_details.state != 'ignore' %} + {% if salt_settings.minion_service_details.state != 'ignore' %} - require_in: - service: salt-minion -{% endif %} + {% endif %} - onchanges_in: - cmd: remove-macpackage-salt - {%- elif grains.os != 'MacOS' and "workaround https://github.com/saltstack/salt/issues/49348" %} + {%- elif grains.os != 'MacOS' and "workaround https://github.com/saltstack/salt/issues/49348" %} pkg.installed: - name: {{ salt_settings.salt_minion }} - {%- if salt_settings.version %} + {%- if salt_settings.version %} - version: {{ salt_settings.version }} - {%- endif %} -{% if salt_settings.minion_service_details.state != 'ignore' %} + {%- endif %} + {% if salt_settings.minion_service_details.state != 'ignore' %} - require_in: - service: salt-minion -{% endif %} - {%- endif %} -{% endif %} + {% endif %} + {%- endif %} + {% endif %} file.recurse: - name: {{ salt_settings.config_path }}/minion.d {%- if salt_settings.minion_config_use_TOFS %} @@ -105,53 +104,55 @@ salt-minion: {%- endif %} - clean: {{ salt_settings.clean_config_d_dir }} - exclude_pat: _* -{% if salt_settings.minion_service_details.state != 'ignore' %} + {% if salt_settings.minion_service_details.state != 'ignore' %} service.{{ salt_settings.minion_service_details.state }}: - enable: {{ salt_settings.minion_service_details.enabled }} - name: {{ salt_settings.minion_service }} - - require: - - file: salt-minion -{% endif %} -{%- if not salt_settings.restart_via_at %} + - watch: + - file: salt-master-macos + - file: salt-master + - file: remove-old-minion-conf-file + {% endif %} + {%- if not salt_settings.restart_via_at %} cmd.run: - {%- if grains['saltversioninfo'] >= [ 2016, 3 ] %} - {%- if grains['kernel'] == 'Windows' %} + {%- if grains['saltversioninfo'] >= [ 2016, 3 ] %} + {%- if grains['kernel'] == 'Windows' %} - name: 'salt-call.bat --local service.restart {{ salt_settings.minion_service }}' - {%- else %} + {%- else %} - name: 'salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null' - {%- endif %} + {%- endif %} - bg: True - {%- else %} - {%- if grains['kernel'] == 'Windows' %} + {%- else %} + {%- if grains['kernel'] == 'Windows' %} - name: 'start powershell "Restart-Service -Name {{ salt_settings.minion_service }}"' - {%- else %} + {%- else %} # old style, pre 2016.3. fork and disown the process - name: |- exec 0>&- # close stdin exec 1>&- # close stdout exec 2>&- # close stderr nohup salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null & - {%- endif %} - {%- endif %} + {%- endif %} + {%- endif %} - onchanges: - {%- if salt_settings.install_packages %} - {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %} + {%- if salt_settings.install_packages %} + {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %} - macpackage: salt-minion - {%- elif grains.os == 'MacOS' %} + {%- elif grains.os == 'MacOS' %} - cmd: download-salt-minion - {%- else %} + {%- else %} - pkg: salt-minion - {%- endif %} - {%- endif %} + {%- endif %} + {%- endif %} - file: salt-minion - file: remove-old-minion-conf-file -{%- else %} + {%- else %} - {% if grains.os != 'MacOS' %} - {# MacOS has 'at' command; but there's no package to install #} + {% if grains.os != 'MacOS' %} + {# MacOS has 'at' command; but there's no package to install #} at: pkg.installed: [] - {% endif %} + {% endif %} restart-salt-minion: cmd.run: @@ -160,20 +161,20 @@ restart-salt-minion: - require: - pkg: at - onchanges: - {%- if salt_settings.install_packages %} - {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %} + {%- if salt_settings.install_packages %} + {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %} - macpackage: salt-minion - {%- elif grains.os == 'MacOS' %} + {%- elif grains.os == 'MacOS' %} - cmd: download-salt-minion - {%- else %} + {%- else %} - pkg: salt-minion - {%- endif %} - {%- endif %} + {%- endif %} + {%- endif %} - file: salt-minion - file: remove-old-minion-conf-file -{%- endif %} + {%- endif %} -{% if 'inotify' in salt_settings.get('minion', {}).get('beacons', {}) and salt_settings.get('pyinotify', False) %} + {% if 'inotify' in salt_settings.get('minion', {}).get('beacons', {}) and salt_settings.get('pyinotify', False) %} salt-minion-beacon-inotify: pkg.installed: - name: {{ salt_settings.pyinotify }} @@ -181,22 +182,22 @@ salt-minion-beacon-inotify: - service: salt-minion - watch_in: - service: salt-minion -{% endif %} + {% endif %} -{% if salt_settings.minion_remove_config %} + {% if salt_settings.minion_remove_config %} remove-default-minion-conf-file: file.absent: - name: {{ salt_settings.config_path }}/minion -{% endif %} + {% endif %} # clean up old _defaults.conf file if they have it around remove-old-minion-conf-file: file.absent: - name: {{ salt_settings.config_path }}/minion.d/_defaults.conf -{% if grains.os == 'MacOS' %} + {% if grains.os == 'MacOS' %} remove-macpackage-salt: file.absent: - name: /tmp/salt.pkg - force: True -{% endif %} + {% endif %} From f389b19a498342f3fe5c0e87adfc38e19a664114 Mon Sep 17 00:00:00 2001 From: N Date: Sat, 13 Jun 2020 21:11:58 +0100 Subject: [PATCH 4/5] chore(hashsum): add values for master/minion files --- salt/osmap.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/osmap.yaml b/salt/osmap.yaml index 6816e96..c82cf8c 100644 --- a/salt/osmap.yaml +++ b/salt/osmap.yaml @@ -57,5 +57,5 @@ SmartOS: gitfs_provider: dulwich MacOS: - salt_master_macos_plist_hash: 9c55cb448269f4d7c433429448d1ec7dda260f180bbcf5197bc430f7645017de - salt_minion_macos_plist_hash: 6383d2d336b06802bfdf25a4c21ee25c85ee9fa57d3ef5776321d9c8cd096395 + salt_master_macos_plist_hash: 8435331b2d48ca8f0759f216e5b15ec9171a4216b1441328c732c6906728b7c9 + salt_minion_macos_plist_hash: 26b33da12e0d8960ee96b488c8352002c22a377c19bf3df3f986a1e49eca8b20 From c72b183f5ff885b30f0ac0fff8c9a847333a9304 Mon Sep 17 00:00:00 2001 From: N Date: Sat, 13 Jun 2020 21:23:14 +0100 Subject: [PATCH 5/5] fix(macos): use macos service names X --- salt/master.sls | 6 ------ salt/minion.sls | 6 ------ salt/osmap.yaml | 2 ++ 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/salt/master.sls b/salt/master.sls index ff68a4f..20476c6 100644 --- a/salt/master.sls +++ b/salt/master.sls @@ -18,12 +18,6 @@ salt-master-macos: until: True interval: 10 splay: 10 - cmd.run: - - names: - - launchctl load -w /Library/LaunchDaemons/com.saltstack.salt.master.plist - - launchctl unload /Library/LaunchDaemons/com.saltstack.salt.master.plist - - require: - - file: salt-master-macos - require_in: - service: salt-master {%- endif %} diff --git a/salt/minion.sls b/salt/minion.sls index 4ef4ed0..301c74a 100644 --- a/salt/minion.sls +++ b/salt/minion.sls @@ -50,12 +50,6 @@ salt-minion-macos: until: True interval: 10 splay: 10 - cmd.run: - - names: - - launchctl load -w /Library/LaunchDaemons/com.saltstack.salt.minion.plist - - launchctl unload /Library/LaunchDaemons/com.saltstack.salt.minion.plist - - require: - - file: salt-minion-macos - require_in: - service: salt-minion {%- endif %} diff --git a/salt/osmap.yaml b/salt/osmap.yaml index c82cf8c..2224a23 100644 --- a/salt/osmap.yaml +++ b/salt/osmap.yaml @@ -57,5 +57,7 @@ SmartOS: gitfs_provider: dulwich MacOS: + minion_service: com.saltstack.salt.minion + master_service: com.saltstack.salt.master salt_master_macos_plist_hash: 8435331b2d48ca8f0759f216e5b15ec9171a4216b1441328c732c6906728b7c9 salt_minion_macos_plist_hash: 26b33da12e0d8960ee96b488c8352002c22a377c19bf3df3f986a1e49eca8b20