From fbaa456ca69fafa2a8a4ef910b5e09dafffe5ece Mon Sep 17 00:00:00 2001 From: N Date: Tue, 18 Feb 2020 13:34:38 +0000 Subject: [PATCH] feat(metastate): add metastate per community convention --- docs/README.rst | 7 +++++++ pillar.example | 11 +++++++++++ salt/defaults.yaml | 6 ++++++ salt/init.sls | 30 ++++++++++++++++++++++++++++++ salt/pkgrepo/init.sls | 8 ++++++++ salt/standalone.sls | 24 ++++++++++++------------ 6 files changed, 74 insertions(+), 12 deletions(-) create mode 100755 salt/init.sls diff --git a/docs/README.rst b/docs/README.rst index 517d135..fa8d29c 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -45,6 +45,13 @@ Available states .. contents:: :local: +``salt`` +^^^^^^^^ + +*Meta-state (This is a state that includes other states)*. + +This calls all runable states based on configured pillar data. + ``salt.minion`` ^^^^^^^^^^^^^^^ diff --git a/pillar.example b/pillar.example index 550cff5..38ea094 100644 --- a/pillar.example +++ b/pillar.example @@ -80,6 +80,7 @@ salt: # salt master config master_config_use_TOFS: true master: + standalone: false fileserver_backend: - git - s3fs @@ -163,6 +164,9 @@ salt: minion_config_use_TOFS: true minion: + # standalone setup + master_type: false # see init.sls & standalone.sls + # single master setup master: salt @@ -268,6 +272,13 @@ salt: - test.ping - saltutil.find_job + # init.sls skips salt.api and salt.syndic states + # unless those dicts are populated with something + api: + somekey: somevalue + syndic: + somekey: somevalue + # salt cloud config cloud: master: salt diff --git a/salt/defaults.yaml b/salt/defaults.yaml index ee603e0..e36a6c8 100644 --- a/salt/defaults.yaml +++ b/salt/defaults.yaml @@ -30,11 +30,16 @@ salt: salt_api: salt-api salt_ssh: salt-ssh + pkgrepo: '' # see osfamilymap + ssh_roster: {} # see pillar data + python_git: python-git python_dulwich: python-dulwich master: gitfs_provider: gitpython + minion: + master_type: true # see init.sls & standalone.sls gitfs: dulwich: @@ -62,6 +67,7 @@ salt: maps: salt://salt/files/cloud.maps.d salt_formulas: + list: {} # via pillar data checkout_orig_branch: false git_opts: default: diff --git a/salt/init.sls b/salt/init.sls new file mode 100755 index 0000000..e0eecb1 --- /dev/null +++ b/salt/init.sls @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - salt.pkgrepo + {%- if salt.config.get('salt_formulas:list') %} + - salt.formulas + {%- endif %} + {%- if salt.config.get('salt:master')|length > 1 %} + - salt.master + {%- endif %} + {%- if salt.config.get('salt:cloud')|length > 1 %} + - salt.cloud + {%- endif %} + {%- if salt.config.get('salt:ssh_roster') %} + - salt.ssh + {%- endif %} + {%- if salt.config.get('salt:minion')|length > 1 %} + {%- if salt.config.get('salt:minion:master_type') %} + - salt.minion + {%- else %} + - salt.standalone + {%- endif %} + {%- endif %} + {%- if salt.config.get('salt:api') %} + - salt.api + {%- endif %} + {%- if salt.config.get('salt:syndic') %} + - salt.syndic + {%- endif %} diff --git a/salt/pkgrepo/init.sls b/salt/pkgrepo/init.sls index b2c794c..9212737 100644 --- a/salt/pkgrepo/init.sls +++ b/salt/pkgrepo/init.sls @@ -1,2 +1,10 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls +{% from "salt/map.jinja" import salt_settings with context %} + + {%- if salt_settings.pkgrepo %} + include: - .{{ grains['os_family']|lower }} + + {%- endif %} diff --git a/salt/standalone.sls b/salt/standalone.sls index dd38a5a..8829d2c 100644 --- a/salt/standalone.sls +++ b/salt/standalone.sls @@ -1,14 +1,14 @@ {%- set tplroot = tpldir.split('/')[0] %} {% from "salt/map.jinja" import salt_settings with context %} -salt-minion: -{% if salt_settings.install_packages %} +salt-minion-standalone: + {% if salt_settings.install_packages %} pkg.installed: - name: {{ salt_settings.salt_minion }} - {%- if salt_settings.version is defined %} + {%- if salt_settings.version is defined %} - version: {{ salt_settings.version }} - {%- endif %} -{% endif %} + {%- endif %} + {% endif %} file.recurse: - name: {{ salt_settings.config_path }}/minion.d - template: jinja @@ -17,19 +17,19 @@ salt-minion: - exclude_pat: _* - context: standalone: True -{%- if salt_settings.minion.master_type is defined and salt_settings.minion.master_type == 'disable' %} + {%- if not salt_settings.minion.master_type %} service.running: - enable: True -{%- else %} + {%- else %} service.dead: - enable: False -{%- endif %} + {%- endif %} - name: {{ salt_settings.minion_service }} - require: -{% if salt_settings.install_packages %} - - pkg: salt-minion -{% endif %} - - file: salt-minion + {% if salt_settings.install_packages %} + - pkg: salt-minion-standalone + {% endif %} + - file: salt-minion-standalone # clean up old _defaults.conf file if they have it around remove-old-standalone-conf-file: