Skip to content

Commit

Permalink
feat(mapping): better control of the service's state
Browse files Browse the repository at this point in the history
Instead of the default service.running + enabled, you can control
the actual state, via pillar.
And you can even say 'state = ignore' and no state will be generated
to control the service
  • Loading branch information
cr1st1p committed Feb 20, 2020
1 parent 4955737 commit 29ffd68
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
6 changes: 4 additions & 2 deletions salt/api.sls
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ salt-api:
- version: {{ salt_settings.version }}
{%- endif %}
{% endif %}
service.running:
- enable: True
{% if salt_settings.api_service_details.state != 'ignore' %}
service.{{ salt_settings.api_service_details.state }}:
- enable: {{ salt_settings.api_service_details.enabled }}:
- name: {{ salt_settings.api_service }}
- require:
- service: {{ salt_settings.master_service }}
Expand All @@ -21,3 +22,4 @@ salt-api:
- pkg: salt-api
{% endif %}
- file: salt-master
{% endif %}
15 changes: 15 additions & 0 deletions salt/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,23 @@ salt:
master_config_use_TOFS: false

minion_service: salt-minion
minion_service_details:
# special name 'ignore' will not output anything about the service
state: running
enabled: true

master_service: salt-master
master_service_details:
# special name 'ignore' will not output anything about the service
state: running
enabled: true

api_service: salt-api
api_service_details:
# special name 'ignore' will not output anything about the service
state: running
enabled: true

syndic_service: salt-syndic

salt_master: salt-master
Expand Down
9 changes: 6 additions & 3 deletions salt/master.sls
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ 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
Expand All @@ -28,13 +30,14 @@ salt-master:
{%- endif %}
- clean: {{ salt_settings.clean_config_d_dir }}
- exclude_pat: _*
service.running:
- enable: True
{% 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 }}
- watch:
- file: salt-master
- file: remove-old-master-conf-file
{% endif %}
{% if salt_settings.master_remove_config %}
remove-default-master-conf-file:
file.absent:
Expand Down
10 changes: 8 additions & 2 deletions salt/minion.sls
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ salt-minion:
- force: True
- unless:
- test -n "{{ salt_settings.version }}" && '/opt/salt/bin/salt-minion --version=.*{{ salt_settings.version }}.*'
{% if salt_settings.minion_service_details.state != 'ignore' %}
- require_in:
- service: salt-minion
{% endif %}
- onchanges_in:
- cmd: remove-macpackage-salt
{%- elif grains.os != 'MacOS' and "workaround https://github.com/saltstack/salt/issues/49348" %}
Expand All @@ -51,8 +53,10 @@ salt-minion:
{%- if salt_settings.version %}
- version: {{ salt_settings.version }}
{%- endif %}
{% if salt_settings.minion_service_details.state != 'ignore' %}
- require_in:
- service: salt-minion
{% endif %}
{%- endif %}
{% endif %}
file.recurse:
Expand All @@ -71,11 +75,13 @@ salt-minion:
{%- endif %}
- clean: {{ salt_settings.clean_config_d_dir }}
- exclude_pat: _*
service.running:
- enable: True
{% if salt_settings.minion_service_details.state != 'ignore' %}
service.{{ salt_settings.minion_service_details.state }}:
- enable: {{ salt_settings.minion_service_details.enabled }}
- name: {{ salt_settings.minion_service }}
- require:
- file: salt-minion
{% endif %}
{%- if not salt_settings.restart_via_at %}
cmd.run:
{%- if grains['saltversioninfo'] >= [ 2016, 3 ] %}
Expand Down

0 comments on commit 29ffd68

Please sign in to comment.