1- {% from " salt/map.jinja" import salt_settings with context % }
1+ {%- from " salt/map.jinja" import salt_settings with context % }
22
3- {% if salt_settings.install_packages and grains.os == ' MacOS' and salt_settings.salt_minion_pkg_source != ' ' and salt_settings.version != ' ' % }
4- {# 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 #}
5- {# e.g. don't download unless it appears as though we're about to try and upgrade the minion #}
3+ {%- if salt_settings.install_packages and grains.os == ' MacOS' and salt_settings.salt_minion_pkg_source != ' ' and salt_settings.version != ' ' % }
4+ {# - 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 #}
5+ {# - e.g. don't download unless it appears as though we're about to try and upgrade the minion #}
66download- salt- minion:
77 file .managed:
88 - name: ' /tmp/salt.pkg'
99 - source: {{ salt_settings.salt_minion_pkg_source }}
10- {% if salt_settings.salt_minion_pkg_hash != ' ' % }
10+ {%- if salt_settings.salt_minion_pkg_hash != ' ' % }
1111 - source_hash: {{ salt_settings.salt_minion_pkg_hash }}
12- {% else % }
12+ {%- else % }
1313 - skip_verify: True
14- {% endif % }
14+ {%- endif % }
1515 - user: root
1616 - group: wheel
1717 - mode: 0644
1818 - unless:
1919 - ' /opt/salt/bin/salt-minion --version | grep {{ salt_settings.version }} '
2020 - require_in:
2121 - macpackage: salt- minion
22- {% endif % }
22+ {%- endif % }
2323
2424salt- minion:
25- {% if salt_settings.install_packages % }
25+ {%- if salt_settings.install_packages % }
2626 {%- if grains.os == ' MacOS' and salt_settings.salt_minion_pkg_source != ' ' and salt_settings.version != ' ' % }
2727 macpackage.installed:
2828 - name: ' /tmp/salt.pkg'
2929 - target: /
30- {# macpackage.installed behaves weirdly with version_check; version_check detects difference but fails to actually complete install. #}
31- {# use force == True as workaround #}
30+ {# - macpackage.installed behaves weirdly with version_check; version_check detects difference but fails to actually complete install. #}
31+ {# - use force == True as workaround #}
3232 - force: True
3333 - version_check: / opt/ salt/ bin / salt- minion -- version=.* {{ salt_settings.version }}.*
34- - require_in:
35- - service: salt- minion
3634 {%- else % }
3735 pkg.installed:
3836 - name: {{ salt_settings.salt_minion }}
39- {%- if salt_settings.version is defined % }
37+ {%- if salt_settings.version is defined % }
4038 - version: {{ salt_settings.version }}
39+ {%- endif % }
4140 {%- endif % }
4241 - require_in:
4342 - service: salt- minion
44- {%- endif % }
45- {% endif % }
43+ - onchanges_in:
44+ - cmd: salt- minion
45+ {%- if salt_settings.restart_via_at % }
46+ - cmd: restart- salt- minion
47+ {%- endif % }
48+ {%- endif % }
49+
4650 file .recurse:
4751 - name: {{ salt_settings.config_path }}/ minion.d
4852 - template: jinja
@@ -51,93 +55,71 @@ salt-minion:
5155 - exclude_pat: _*
5256 - context:
5357 standalone: False
58+ - onchanges_in:
59+ - cmd: salt- minion
60+ {%- if salt_settings.restart_via_at % }
61+ - cmd: restart- salt- minion
62+ {%- endif % }
63+
5464 service.running:
5565 - enable: True
5666 - name: {{ salt_settings.minion_service }}
5767 - require:
5868 - file : salt- minion
69+
5970{%- if not salt_settings.restart_via_at % }
6071 cmd.run:
61- {%- if grains[' saltversioninfo' ][0 ] >= 2016 and grains[' saltversioninfo' ][1 ] >= 3 % }
6272 {%- if grains[' kernel' ] == ' Windows' % }
6373 - name: ' salt-call.bat --local service.restart {{ salt_settings.minion_service }} '
6474 {%- else % }
6575 - name: ' salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null'
6676 {%- endif % }
6777 - bg: True
68- {%- else % }
69- {%- if grains[' kernel' ] == ' Windows' % }
70- - name: ' start powershell "Restart-Service -Name {{ salt_settings.minion_service }} "'
71- {%- else % }
72- # old style, pre 2016.3. fork and disown the process
73- - name: | -
74- exec 0 > & - # close stdin
75- exec 1 > & - # close stdout
76- exec 2 > & - # close stderr
77- nohup salt- call -- local service.restart {{ salt_settings.minion_service }} -- out- file / dev/ null &
78- {%- endif % }
79- {%- endif % }
80- - onchanges:
81- {%- if salt_settings.install_packages % }
82- {%- if grains.os == ' MacOS' % }
83- - macpackage: salt- minion
84- {%- else % }
85- - pkg: salt- minion
86- {%- endif % }
87- {%- endif % }
88- - file : salt- minion
89- - file : remove- old- minion- conf- file
9078{%- else % }
91-
92- {% if grains.os != ' MacOS' % }
93- {# MacOS has 'at' command; but there's no package to install #}
79+ {%- if grains.os != ' MacOS' % }
80+ {# - MacOS has 'at' command; but there's no package to install #}
9481at:
9582 pkg.installed: []
96- { % endif % }
83+ { %- endif % }
9784
9885restart- salt- minion:
9986 cmd.run:
10087 - name: echo salt- call -- local service.restart {{ salt_settings.minion_service }} | at now + 1 minute
10188 - order: last
10289 - require:
10390 - pkg: at
104- - onchanges:
105- {%- if salt_settings.install_packages % }
106- {%- if grains.os == ' MacOS' % }
107- - macpackage: salt- minion
108- {%- else % }
109- - pkg: salt- minion
110- {%- endif % }
111- {%- endif % }
112- - file : salt- minion
113- - file : remove- old- minion- conf- file
11491{%- endif % }
11592
116- {% if ' inotify' in salt_settings.get(' minion' , {}).get(' beacons' , {}) and salt_settings.get(' pyinotify' , False ) % }
93+ {%- if ' inotify' in salt_settings.get(' minion' , {}).get(' beacons' , {}) and salt_settings.get(' pyinotify' , False ) % }
11794salt- minion- beacon- inotify:
11895 pkg.installed:
11996 - name: {{ salt_settings.pyinotify }}
12097 - require_in:
12198 - service: salt- minion
12299 - watch_in:
123100 - service: salt- minion
124- {% endif % }
101+ {%- endif % }
125102
126- {% if salt_settings.minion_remove_config % }
103+ {%- if salt_settings.minion_remove_config % }
127104remove- default- minion- conf- file :
128105 file .absent:
129106 - name: {{ salt_settings.config_path }}/ minion
130- {% endif % }
107+ {%- endif % }
131108
132109# clean up old _defaults.conf file if they have it around
133110remove- old- minion- conf- file :
134111 file .absent:
135112 - name: {{ salt_settings.config_path }}/ minion.d/ _defaults.conf
113+ - onchanges_in:
114+ - cmd: salt- minion
115+ {%- if salt_settings.restart_via_at % }
116+ - cmd: restart- salt- minion
117+ {%- endif % }
136118
137- {% if grains.os == ' MacOS' % }
119+ {%- if grains.os == ' MacOS' % }
138120remove- macpackage- salt:
139121 cmd.run:
140122 - name: ' rm -f /tmp/salt.pkg'
141123 - onchanges:
142124 - macpackage: salt- minion
143- {% endif % }
125+ {%- endif % }
0 commit comments