diff --git a/salt/master.sls b/salt/master.sls deleted file mode 100644 index 577bebc..0000000 --- a/salt/master.sls +++ /dev/null @@ -1,89 +0,0 @@ -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import salt_settings with context %} -{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} - -{% if salt_settings.pin_version and salt_settings.version and grains.os_family|lower == 'debian' %} -include: - - .pin -{% endif %} - -{%- if grains.kernel != 'Windows' %} - - {%- 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/osx/scripts/com.saltstack.salt.master.plist - - source_hash: {{ salt_settings.salt_master_macos_plist_hash }} - - retry: {{ salt_settings.retry_options | json }} - - require_in: - - service: salt-master - {%- endif %} - -salt-master: - {% if salt_settings.install_packages %} - pkg.installed: - - name: {{ salt_settings.salt_master }} - {%- if salt_settings.version is defined %} - - version: {{ salt_settings.version }} - {%- endif %} - {% if salt_settings.master_service_details.state != 'ignore' %} - - require_in: - - service: salt-master - - watch_in: - - service: salt-master - {% endif %} - {% endif %} - file.recurse: - - name: {{ salt_settings.config_path }}/master.d - {%- if salt_settings.master_config_use_TOFS %} - - template: '' - - source: {{ files_switch(['master.d'], - lookup='salt-master' - ) - }} - {%- else %} - - template: jinja - - source: salt://{{ tplroot }}/files/master.d - {%- endif %} - - clean: {{ salt_settings.clean_config_d_dir }} - - exclude_pat: - - _* - - raas.conf - {% 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 }} - {%- if grains.os_family == 'FreeBSD' %} - - retry: {{ salt_settings.retry_options | json }} - {%- endif %} - - watch: - {%- if grains.kernel|lower == 'darwin' %} - - file: salt-master-macos - {%- else %} - - file: salt-master - {%- endif %} - - file: remove-old-master-conf-file - - order: last - {% endif %} - {% if salt_settings.master_remove_config %} -remove-default-master-conf-file: - file.absent: - - name: {{ salt_settings.config_path }}/master - - watch_in: - - service: salt-master - {% endif %} - -# clean up old _defaults.conf file if they have it around -remove-old-master-conf-file: - file.absent: - - name: {{ salt_settings.config_path }}/master.d/_defaults.conf - -{%- else %} - -salt-master-install-skip: - test.show_notification: - - text: | - No salt-master state for Windows - -{%- endif %} diff --git a/salt/master/config/files.sls b/salt/master/config/files.sls new file mode 100644 index 0000000..e4607f2 --- /dev/null +++ b/salt/master/config/files.sls @@ -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.install" %} +{%- 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 %} diff --git a/salt/master/config/init.sls b/salt/master/config/init.sls new file mode 100644 index 0000000..c5d9fb9 --- /dev/null +++ b/salt/master/config/init.sls @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .files diff --git a/salt/master/init.sls b/salt/master/init.sls new file mode 100644 index 0000000..858a8e6 --- /dev/null +++ b/salt/master/init.sls @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .package + - .config + - .service diff --git a/salt/master/package/init.sls b/salt/master/package/init.sls new file mode 100644 index 0000000..d3e5518 --- /dev/null +++ b/salt/master/package/init.sls @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .install diff --git a/salt/master/package/install.sls b/salt/master/package/install.sls new file mode 100644 index 0000000..ef03fdd --- /dev/null +++ b/salt/master/package/install.sls @@ -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-install-pkg.installed: + pkg.installed: + - name: {{ salt_settings.salt_master }} + - version: {{ salt_settings.version | default('~') }} + - require: + - sls: {{ sls_windows_excluded }} +{%- endif %} diff --git a/salt/master/service/init.sls b/salt/master/service/init.sls new file mode 100644 index 0000000..0f7e271 --- /dev/null +++ b/salt/master/service/init.sls @@ -0,0 +1,28 @@ +# -*- 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 = { + 'darwin': salt_settings.retry_options | json, + }.get(grains.kernel|lower, '') + %} + +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 %} diff --git a/salt/windows-excluded.sls b/salt/windows-excluded.sls new file mode 100644 index 0000000..c8cfb82 --- /dev/null +++ b/salt/windows-excluded.sls @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{%- if grains.kernel == 'Windows' %} +salt-windows-excluded-test.fail_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 %}