Skip to content

refactor(sls): make states more readable by spliting into sub-components #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,39 @@ Install a minion

Install a master.

This state can't be run on Windows OS, the ``salt.windows-excluded``
is used as a safeguard dependency.

``salt.master.package``
^^^^^^^^^^^^^^^^^^^^^^^

Install the master package.

This state can't be run on Windows OS, the ``salt.windows-excluded``
is used as a safeguard dependency.

``salt.master.config``
^^^^^^^^^^^^^^^^^^^^^^

Configure the master service.

This state can't be run on Windows OS, the ``salt.windows-excluded``
is used as a safeguard dependency.

``salt.master.service``
^^^^^^^^^^^^^^^^^^^^^^^

Manage the salt master service if
``salt_settings.master_service_details.state`` is not ``ignore``:

- enable and start the salt master service if
``salt_settings.master_service_details.state`` is ``running``, the default.
- stop and disable the salt master service if
``salt_settings.master_service_details.state`` is ``dead``.

This state can't be run on Windows OS, the ``salt.windows-excluded``
is used as a safeguard dependency.

``salt.syndic``
^^^^^^^^^^^^^^^

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

``salt.windows-excluded``
^^^^^^^^^^^^^^^^^^^^^^^^^

Safeguard state to exclude Windows OS, used by ``salt.master`` states
and sub states.

It fails using ``test.fail_without_changes`` on Windows OS and succeed
with ``test.succeed_without_changes`` on others.

Configuration
-------------
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
89 changes: 0 additions & 89 deletions salt/master.sls

This file was deleted.

60 changes: 60 additions & 0 deletions salt/master/config/files.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split("/")[0] %}
{%- set sls_windows_excluded = tplroot ~ ".windows-excluded" %}
{%- set sls_package_install = tplroot ~ ".master.package.installed" %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}

include:
- {{ sls_windows_excluded }}
- {{ sls_package_install }}

{%- if salt_settings.master_config_use_TOFS %}
{%- set source = files_switch(["master.d"],
lookup="salt-master"
) %}
{%- set template = "" %}
{%- else %}
{%- set source = "salt://" ~ tplroot ~ "/files/master.d" %}
{%- set template = "jinja" %}
{%- endif %}

salt-master-config-files-file.recurse:
file.recurse:
- name: {{ salt_settings.config_path }}/master.d
- source: {{ source }}
- template: {{ template }}
- clean: {{ salt_settings.clean_config_d_dir }}
- exclude_pat:
- _*
- raas.conf
- require:
- sls: {{ sls_windows_excluded }}
- sls: {{ sls_package_install }}

{%- if salt_settings.master_remove_config %}
salt-master-config-files-remove-old-master-conf-file.absent:
file.absent:
- name: {{ salt_settings.config_path }}/master
- require:
- sls: {{ sls_windows_excluded }}
- sls: {{ sls_package_install }}
{%- endif %}

# clean up old _defaults.conf file if they have it around
salt-master-config-files-remove-old-default-master-conf-file.absent:
file.absent:
- name: {{ salt_settings.config_path }}/master.d/_defaults.conf

{%- if grains.os == "MacOS" %}
salt-master-config-files-macos-LaunchDaemons-file.managed:
file.managed:
- name: /Library/LaunchDaemons/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: {{ salt_settings.retry_options | json }}
- require:
- sls: {{ sls_package_install }}
{%- endif %}
5 changes: 5 additions & 0 deletions salt/master/config/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .files
12 changes: 12 additions & 0 deletions salt/master/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_windows_excluded = tplroot ~ ".windows-excluded" %}

include:
- {{ sls_windows_excluded }}
- .package
- .config
- .service
5 changes: 5 additions & 0 deletions salt/master/package/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .installed
26 changes: 26 additions & 0 deletions salt/master/package/installed.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_windows_excluded = tplroot ~ '.windows-excluded' %}
{%- set sls_pin_version = tplroot ~ '.pin' %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}

{#- `salt-master` cannot be installed on Windows machines #}
{%- set sls_dependencies = [sls_windows_excluded] %}

{%- if salt_settings.pin_version and salt_settings.version and grains.os_family|lower == 'debian' %}
{%- do sls_dependencies.append(sls_pin_version) %}
{%- endif %}

include: {{ sls_dependencies }}

{%- if salt_settings.install_packages %}
salt-master-package-installed-pkg.installed:
pkg.installed:
- name: {{ salt_settings.salt_master }}
- version: {{ salt_settings.version | default('~') }}
- require:
- sls: {{ sls_windows_excluded }}
{%- endif %}
29 changes: 29 additions & 0 deletions salt/master/service/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_windows_excluded = tplroot ~ ".windows-excluded" %}
{%- set sls_config_files = tplroot ~ '.master.config.files' %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}

{%- if salt_settings.master_service_details.state != 'ignore' %}
include:
- {{ sls_windows_excluded }}
- {{ sls_config_files }}

{%- set wanted_state = salt_settings.master_service_details.state %}
{%- set retry = {
'FreeBSD': salt_settings.retry_options | json,
'Gentoo': salt_settings.retry_options | json,
}.get(grains.os_family, '')
%}

salt-master-service-{{ wanted_state }}:
service.{{ wanted_state }}:
- enable: {{ salt_settings.master_service_details.enabled }}
- name: {{ salt_settings.master_service }}
- retry: {{ retry }}
- watch:
- sls: {{ sls_config_files }}
{%- endif %}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions salt/windows-excluded.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{%- if grains.kernel == 'Windows' %}
salt-windows-excluded-testfail_without_changes:
test.fail_without_changes:
- name: Verify that current platform is not Windows
- comment: Platform Windows is not supported
{%- else %}
{#- Workaround https://github.com/saltstack/salt/issues/10852 #}
salt-windows-excluded-test.succeed_without_changes:
test.succeed_without_changes:
- name: Verify that current platform is not Windows
- comment: Platform {{ grains.kernel }} is supported
{%- endif %}
Loading