Skip to content

Commit 121b628

Browse files
committed
refactor(master): split to multiple subcomponents
Add a verifier in each sls to exclude windows platform.
1 parent 537233f commit 121b628

File tree

8 files changed

+190
-86
lines changed

8 files changed

+190
-86
lines changed

docs/README.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,39 @@ Install a minion
6262

6363
Install a master.
6464

65+
This state can't be run on Windows OS, the ``salt.windows-excluded``
66+
is used as a safeguard dependency.
67+
68+
``salt.master.package``
69+
^^^^^^^^^^^^^^^^^^^^^^^
70+
71+
Install the master package.
72+
73+
This state can't be run on Windows OS, the ``salt.windows-excluded``
74+
is used as a safeguard dependency.
75+
76+
``salt.master.config``
77+
^^^^^^^^^^^^^^^^^^^^^^
78+
79+
Configure the master service.
80+
81+
This state can't be run on Windows OS, the ``salt.windows-excluded``
82+
is used as a safeguard dependency.
83+
84+
``salt.master.service``
85+
^^^^^^^^^^^^^^^^^^^^^^^
86+
87+
Manage the salt master service if
88+
``salt_settings.master_service_details.state`` is not ``ignore``:
89+
90+
- enable and start the salt master service if
91+
``salt_settings.master_service_details.state`` is ``running``, the default.
92+
- stop and disable the salt master service if
93+
``salt_settings.master_service_details.state`` is ``dead``.
94+
95+
This state can't be run on Windows OS, the ``salt.windows-excluded``
96+
is used as a safeguard dependency.
97+
6598
``salt.syndic``
6699
^^^^^^^^^^^^^^^
67100

@@ -159,6 +192,14 @@ If you configure the state to download the formulas from repositories that
159192
you control, then you can safely enable the
160193
``salt_formulas:git_opts:default:update`` pillar setting to ``True``.
161194

195+
``salt.windows-excluded``
196+
^^^^^^^^^^^^^^^^^^^^^^^^^
197+
198+
Safeguard state to exclude Windows OS, used by ``salt.master`` states
199+
and sub states.
200+
201+
It fails using ``test.fail_without_changes`` on Windows OS and succeed
202+
with ``test.succeed_without_changes`` on others.
162203

163204
Configuration
164205
-------------

salt/master/config/files.sls

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split("/")[0] %}
6+
{%- set sls_windows_excluded = tplroot ~ ".windows-excluded" %}
7+
{%- set sls_package_install = tplroot ~ ".master.package.installed" %}
8+
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
9+
10+
include:
11+
- {{ sls_windows_excluded }}
12+
- {{ sls_package_install }}
13+
14+
{%- if salt_settings.master_config_use_TOFS %}
15+
{%- set source = files_switch(["master.d"],
16+
lookup="salt-master"
17+
) %}
18+
{%- set template = "" %}
19+
{%- else %}
20+
{%- set source = "salt://" ~ tplroot ~ "/files/master.d" %}
21+
{%- set template = "jinja" %}
22+
{%- endif %}
23+
24+
salt-master-config-files-file.recurse:
25+
file.recurse:
26+
- name: {{ salt_settings.config_path }}/master.d
27+
- source: {{ source }}
28+
- template: {{ template }}
29+
- clean: {{ salt_settings.clean_config_d_dir }}
30+
- exclude_pat:
31+
- _*
32+
- raas.conf
33+
- require:
34+
- sls: {{ sls_windows_excluded }}
35+
- sls: {{ sls_package_install }}
36+
37+
{%- if salt_settings.master_remove_config %}
38+
salt-master-config-files-remove-old-master-conf-file.absent:
39+
file.absent:
40+
- name: {{ salt_settings.config_path }}/master
41+
- require:
42+
- sls: {{ sls_windows_excluded }}
43+
- sls: {{ sls_package_install }}
44+
{%- endif %}
45+
46+
# clean up old _defaults.conf file if they have it around
47+
salt-master-config-files-remove-old-default-master-conf-file.absent:
48+
file.absent:
49+
- name: {{ salt_settings.config_path }}/master.d/_defaults.conf
50+
51+
{%- if grains.os == "MacOS" %}
52+
salt-master-config-files-macos-LaunchDaemons-file.managed:
53+
file.managed:
54+
- name: /Library/LaunchDaemons/com.saltstack.salt.master.plist
55+
- source: https://raw.githubusercontent.com/saltstack/salt/master/pkg/osx/scripts/com.saltstack.salt.master.plist
56+
- source_hash: {{ salt_settings.salt_master_macos_plist_hash }}
57+
- retry: {{ salt_settings.retry_options | json }}
58+
- require:
59+
- sls: {{ sls_package_install }}
60+
{%- endif %}

salt/master/config/init.sls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
include:
5+
- .files

salt/master/init.sls

Lines changed: 9 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{#- Get the `tplroot` from `tpldir` #}
15
{%- set tplroot = tpldir.split('/')[0] %}
2-
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
3-
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
6+
{%- set sls_windows_excluded = tplroot ~ ".windows-excluded" %}
47

5-
{% if salt_settings.pin_version and salt_settings.version and grains.os_family|lower == 'debian' %}
68
include:
7-
- .pin
8-
{% endif %}
9-
10-
{%- if grains.kernel != 'Windows' %}
11-
12-
{%- if grains.os == 'MacOS' %}
13-
salt-master-macos:
14-
file.managed:
15-
- name: /Library/LaunchDaemons/com.saltstack.salt.master.plist
16-
- source: https://raw.githubusercontent.com/saltstack/salt/master/pkg/osx/scripts/com.saltstack.salt.master.plist
17-
- source_hash: {{ salt_settings.salt_master_macos_plist_hash }}
18-
- retry: {{ salt_settings.retry_options | json }}
19-
- require_in:
20-
- service: salt-master
21-
{%- endif %}
22-
23-
salt-master:
24-
{% if salt_settings.install_packages %}
25-
pkg.installed:
26-
- name: {{ salt_settings.salt_master }}
27-
{%- if salt_settings.version is defined %}
28-
- version: {{ salt_settings.version }}
29-
{%- endif %}
30-
{% if salt_settings.master_service_details.state != 'ignore' %}
31-
- require_in:
32-
- service: salt-master
33-
- watch_in:
34-
- service: salt-master
35-
{% endif %}
36-
{% endif %}
37-
file.recurse:
38-
- name: {{ salt_settings.config_path }}/master.d
39-
{%- if salt_settings.master_config_use_TOFS %}
40-
- template: ''
41-
- source: {{ files_switch(['master.d'],
42-
lookup='salt-master'
43-
)
44-
}}
45-
{%- else %}
46-
- template: jinja
47-
- source: salt://{{ tplroot }}/files/master.d
48-
{%- endif %}
49-
- clean: {{ salt_settings.clean_config_d_dir }}
50-
- exclude_pat:
51-
- _*
52-
- raas.conf
53-
{% if salt_settings.master_service_details.state != 'ignore' %}
54-
service.{{ salt_settings.master_service_details.state }}:
55-
- enable: {{ salt_settings.master_service_details.enabled }}
56-
- name: {{ salt_settings.master_service }}
57-
{%- if grains.os_family in ['FreeBSD', 'Gentoo'] %}
58-
- retry: {{ salt_settings.retry_options | json }}
59-
{%- endif %}
60-
- watch:
61-
{%- if grains.kernel|lower == 'darwin' %}
62-
- file: salt-master-macos
63-
{%- else %}
64-
- file: salt-master
65-
{%- endif %}
66-
- file: remove-old-master-conf-file
67-
- order: last
68-
{% endif %}
69-
{% if salt_settings.master_remove_config %}
70-
remove-default-master-conf-file:
71-
file.absent:
72-
- name: {{ salt_settings.config_path }}/master
73-
- watch_in:
74-
- service: salt-master
75-
{% endif %}
76-
77-
# clean up old _defaults.conf file if they have it around
78-
remove-old-master-conf-file:
79-
file.absent:
80-
- name: {{ salt_settings.config_path }}/master.d/_defaults.conf
81-
82-
{%- else %}
83-
84-
salt-master-install-skip:
85-
test.show_notification:
86-
- text: |
87-
No salt-master state for Windows
88-
89-
{%- endif %}
9+
- {{ sls_windows_excluded }}
10+
- .package
11+
- .config
12+
- .service

salt/master/package/init.sls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
include:
5+
- .installed

salt/master/package/installed.sls

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- set sls_windows_excluded = tplroot ~ '.windows-excluded' %}
7+
{%- set sls_pin_version = tplroot ~ '.pin' %}
8+
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
9+
10+
{#- `salt-master` cannot be installed on Windows machines #}
11+
{%- set sls_dependencies = [sls_windows_excluded] %}
12+
13+
{%- if salt_settings.pin_version and salt_settings.version and grains.os_family|lower == 'debian' %}
14+
{%- do sls_dependencies.append(sls_pin_version) %}
15+
{%- endif %}
16+
17+
include: {{ sls_dependencies }}
18+
19+
{%- if salt_settings.install_packages %}
20+
salt-master-package-installed-pkg.installed:
21+
pkg.installed:
22+
- name: {{ salt_settings.salt_master }}
23+
- version: {{ salt_settings.version | default('~') }}
24+
- require:
25+
- sls: {{ sls_windows_excluded }}
26+
{%- endif %}

salt/master/service/init.sls

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- set sls_windows_excluded = tplroot ~ ".windows-excluded" %}
7+
{%- set sls_config_files = tplroot ~ '.master.config.files' %}
8+
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
9+
10+
{%- if salt_settings.master_service_details.state != 'ignore' %}
11+
include:
12+
- {{ sls_windows_excluded }}
13+
- {{ sls_config_files }}
14+
15+
{%- set wanted_state = salt_settings.master_service_details.state %}
16+
{%- set retry = {
17+
'FreeBSD': salt_settings.retry_options | json,
18+
'Gentoo': salt_settings.retry_options | json,
19+
}.get(grains.os_family, '')
20+
%}
21+
22+
salt-master-service-{{ wanted_state }}:
23+
service.{{ wanted_state }}:
24+
- enable: {{ salt_settings.master_service_details.enabled }}
25+
- name: {{ salt_settings.master_service }}
26+
- retry: {{ retry }}
27+
- watch:
28+
- sls: {{ sls_config_files }}
29+
{%- endif %}

salt/windows-excluded.sls

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{%- if grains.kernel == 'Windows' %}
5+
salt-windows-excluded-testfail_without_changes:
6+
test.fail_without_changes:
7+
- name: Verify that current platform is not Windows
8+
- comment: Platform Windows is not supported
9+
{%- else %}
10+
{#- Workaround https://github.com/saltstack/salt/issues/10852 #}
11+
salt-windows-excluded-test.succeed_without_changes:
12+
test.succeed_without_changes:
13+
- name: Verify that current platform is not Windows
14+
- comment: Platform {{ grains.kernel }} is supported
15+
{%- endif %}

0 commit comments

Comments
 (0)