22{%- from tplroot ~ " /map.jinja" import salt_settings with context % }
33{%- from tplroot ~ " /libtofs.jinja" import files_switch with context % }
44
5- {% if salt_settings.install_packages and grains.os == ' MacOS' and salt_settings.salt_minion_pkg_source != ' ' and salt_settings.version != ' ' % }
6- {# 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 #}
7- {# e.g. don't download unless it appears as though we're about to try and upgrade the minion #}
5+ {%- if salt_settings.install_packages and grains.os == ' MacOS' and salt_settings.salt_minion_pkg_source != ' ' and salt_settings.version != ' ' % }
6+ {# - 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 #}
7+ {# - e.g. don't download unless it appears as though we're about to try and upgrade the minion #}
88download- salt- minion:
99 file .managed:
1010 - name: ' /tmp/salt.pkg'
1111 - source: {{ salt_settings.salt_minion_pkg_source }}
12- {% if salt_settings.salt_minion_pkg_hash != ' ' % }
12+ {%- if salt_settings.salt_minion_pkg_hash != ' ' % }
1313 - source_hash: {{ salt_settings.salt_minion_pkg_hash }}
14- {% else % }
14+ {%- else % }
1515 - skip_verify: True
16- {% endif % }
16+ {%- endif % }
1717 - user: root
1818 - group: wheel
1919 - mode: 0644
2020 - unless:
2121 - ' /opt/salt/bin/salt-minion --version | grep {{ salt_settings.version }} '
2222 - require_in:
2323 - macpackage: salt- minion
24- {% endif % }
24+ {%- endif % }
2525
2626salt- minion:
27- {% if salt_settings.install_packages % }
27+ {%- if salt_settings.install_packages % }
2828 {%- if grains.os == ' MacOS' and salt_settings.salt_minion_pkg_source != ' ' and salt_settings.version != ' ' % }
2929 macpackage.installed:
3030 - name: ' /tmp/salt.pkg'
3131 - target: /
32- {# macpackage.installed behaves weirdly with version_check; version_check detects difference but fails to actually complete install. #}
33- {# use force == True as workaround #}
32+ {# - macpackage.installed behaves weirdly with version_check; version_check detects difference but fails to actually complete install. #}
33+ {# - use force == True as workaround #}
3434 - force: True
3535 - version_check: / opt/ salt/ bin / salt- minion -- version=.* {{ salt_settings.version }}.*
36- - require_in:
37- - service: salt- minion
3836 {%- else % }
3937 pkg.installed:
4038 - name: {{ salt_settings.salt_minion }}
41- {%- if salt_settings.version is defined % }
39+ {%- if salt_settings.version is defined % }
4240 - version: {{ salt_settings.version }}
41+ {%- endif % }
4342 {%- endif % }
4443 - require_in:
4544 - service: salt- minion
46- {%- endif % }
47- {% endif % }
45+ - onchanges_in:
46+ - cmd: salt- minion
47+ {%- if salt_settings.restart_via_at % }
48+ - cmd: restart- salt- minion
49+ {%- endif % }
50+ {%- endif % }
51+
4852 file .recurse:
4953 - name: {{ salt_settings.config_path }}/ minion.d
5054 {%- if salt_settings.minion_config_use_TOFS % }
@@ -61,93 +65,71 @@ salt-minion:
6165 {%- endif % }
6266 - clean: {{ salt_settings.clean_config_d_dir }}
6367 - exclude_pat: _*
68+ - onchanges_in:
69+ - cmd: salt- minion
70+ {%- if salt_settings.restart_via_at % }
71+ - cmd: restart- salt- minion
72+ {%- endif % }
73+
6474 service.running:
6575 - enable: True
6676 - name: {{ salt_settings.minion_service }}
6777 - require:
6878 - file : salt- minion
79+
6980{%- if not salt_settings.restart_via_at % }
7081 cmd.run:
71- {%- if grains[' saltversioninfo' ][0 ] >= 2016 and grains[' saltversioninfo' ][1 ] >= 3 % }
7282 {%- if grains[' kernel' ] == ' Windows' % }
7383 - name: ' salt-call.bat --local service.restart {{ salt_settings.minion_service }} '
7484 {%- else % }
7585 - name: ' salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null'
7686 {%- endif % }
7787 - bg: True
78- {%- else % }
79- {%- if grains[' kernel' ] == ' Windows' % }
80- - name: ' start powershell "Restart-Service -Name {{ salt_settings.minion_service }} "'
81- {%- else % }
82- # old style, pre 2016.3. fork and disown the process
83- - name: | -
84- exec 0 > & - # close stdin
85- exec 1 > & - # close stdout
86- exec 2 > & - # close stderr
87- nohup salt- call -- local service.restart {{ salt_settings.minion_service }} -- out- file / dev/ null &
88- {%- endif % }
89- {%- endif % }
90- - onchanges:
91- {%- if salt_settings.install_packages % }
92- {%- if grains.os == ' MacOS' % }
93- - macpackage: salt- minion
94- {%- else % }
95- - pkg: salt- minion
96- {%- endif % }
97- {%- endif % }
98- - file : salt- minion
99- - file : remove- old- minion- conf- file
10088{%- else % }
101-
102- {% if grains.os != ' MacOS' % }
103- {# MacOS has 'at' command; but there's no package to install #}
89+ {%- if grains.os != ' MacOS' % }
90+ {# - MacOS has 'at' command; but there's no package to install #}
10491at:
10592 pkg.installed: []
106- { % endif % }
93+ { %- endif % }
10794
10895restart- salt- minion:
10996 cmd.run:
11097 - name: echo salt- call -- local service.restart {{ salt_settings.minion_service }} | at now + 1 minute
11198 - order: last
11299 - require:
113100 - pkg: at
114- - onchanges:
115- {%- if salt_settings.install_packages % }
116- {%- if grains.os == ' MacOS' % }
117- - macpackage: salt- minion
118- {%- else % }
119- - pkg: salt- minion
120- {%- endif % }
121- {%- endif % }
122- - file : salt- minion
123- - file : remove- old- minion- conf- file
124101{%- endif % }
125102
126- {% if ' inotify' in salt_settings.get(' minion' , {}).get(' beacons' , {}) and salt_settings.get(' pyinotify' , False ) % }
103+ {%- if ' inotify' in salt_settings.get(' minion' , {}).get(' beacons' , {}) and salt_settings.get(' pyinotify' , False ) % }
127104salt- minion- beacon- inotify:
128105 pkg.installed:
129106 - name: {{ salt_settings.pyinotify }}
130107 - require_in:
131108 - service: salt- minion
132109 - watch_in:
133110 - service: salt- minion
134- {% endif % }
111+ {%- endif % }
135112
136- {% if salt_settings.minion_remove_config % }
113+ {%- if salt_settings.minion_remove_config % }
137114remove- default- minion- conf- file :
138115 file .absent:
139116 - name: {{ salt_settings.config_path }}/ minion
140- {% endif % }
117+ {%- endif % }
141118
142119# clean up old _defaults.conf file if they have it around
143120remove- old- minion- conf- file :
144121 file .absent:
145122 - name: {{ salt_settings.config_path }}/ minion.d/ _defaults.conf
123+ - onchanges_in:
124+ - cmd: salt- minion
125+ {%- if salt_settings.restart_via_at % }
126+ - cmd: restart- salt- minion
127+ {%- endif % }
146128
147- {% if grains.os == ' MacOS' % }
129+ {%- if grains.os == ' MacOS' % }
148130remove- macpackage- salt:
149131 cmd.run:
150132 - name: ' rm -f /tmp/salt.pkg'
151133 - onchanges:
152134 - macpackage: salt- minion
153- {% endif % }
135+ {%- endif % }
0 commit comments