diff --git a/README.rst b/README.rst index 1d5d1125..744bffbf 100644 --- a/README.rst +++ b/README.rst @@ -48,9 +48,11 @@ Available states Meta-state (This is a state that includes other states) -This installs the template package, and starts the associated template service. +This installs the template package, +manages the template configuration file and then +starts the associated template service. -``template.install`` +``template.package`` -------------------- This state will install the template package only. @@ -58,12 +60,39 @@ This state will install the template package only. ``template.config`` ------------------- -This state will configure the template service and has a depency on ``template.install`` +This state will configure the template service and has a dependency on ``template.install`` via include list. ``template.service`` -------------------- -This state will start the template service and has a depency on ``template.config`` +This state will start the template service and has a dependency on ``template.config`` +via include list. + +``template.clean`` +------------------ + +Meta-state (This is a state that includes other states) + +this state will undo everything performed in the ``template`` meta-state in reverse order, i.e. +stops the service, +removes the configuration file and +then uninstalls the package. + +``template.service.clean`` +-------------------------- + +This state will stop the template service and disable it at boot time. + +``template.config.clean`` +------------------------- + +This state will remove the configuration of the template service and has a dependency on ``template.service.clean`` +via include list. + +``template.package.clean`` +-------------------------- + +This state will remove the template package and has a depency on ``template.config.clean`` via include list. diff --git a/template/clean.sls b/template/clean.sls new file mode 100644 index 00000000..2cefe7dd --- /dev/null +++ b/template/clean.sls @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .service.clean + - .config.clean + - .package.clean diff --git a/template/config.sls b/template/config.sls deleted file mode 100644 index 13ad6686..00000000 --- a/template/config.sls +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{%- set topdir = tpldir.split('/')[0] %} -{%- from tpldir ~ "/map.jinja" import template with context %} -{%- from tpldir ~ "/macros.jinja" import files_switch with context %} - -include: - - template.install - -template-config: - file.managed: - - name: {{ template.config }} - - source: {{ files_switch( - salt['config.get']( - topdir ~ ':tofs:files:template-config', - ['example.tmpl', 'example.tmpl.jinja'] - ) - ) }} - - mode: 644 - - user: root - - group: root - - template: jinja diff --git a/template/config/clean.sls b/template/config/clean.sls new file mode 100644 index 00000000..5b3ee11d --- /dev/null +++ b/template/config/clean.sls @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- set sls_service_clean = tplroot ~ '.service.clean' %} +{%- from tplroot ~ "/map.jinja" import template with context %} +{%- from tplroot ~ "/macros.jinja" import files_switch with context %} + +include: + - {{ sls_service_clean }} + +template-config-clean-file-absent: + file.absent: + - name: {{ template.config }} + - require: + - sls: {{ sls_service_clean }} diff --git a/template/config/file.sls b/template/config/file.sls new file mode 100644 index 00000000..be73822d --- /dev/null +++ b/template/config/file.sls @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- set sls_package_install = tplroot ~ '.package.install' %} +{%- from tplroot ~ "/map.jinja" import template with context %} +{%- from tplroot ~ "/macros.jinja" import files_switch with context %} + +include: + - {{ sls_package_install }} + +template-config-file-file-managed: + file.managed: + - name: {{ template.config }} + - source: {{ files_switch( + salt['config.get']( + tplroot ~ ':tofs:files:template-config', + ['example.tmpl', 'example.tmpl.jinja'] + ) + ) }} + - mode: 644 + - user: root + - group: root + - template: jinja + - require: + - sls: {{ sls_package_install }} diff --git a/template/config/init.sls b/template/config/init.sls new file mode 100644 index 00000000..465ddfea --- /dev/null +++ b/template/config/init.sls @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .file diff --git a/template/init.sls b/template/init.sls index 1de0f0bd..858a8e6e 100644 --- a/template/init.sls +++ b/template/init.sls @@ -2,6 +2,6 @@ # vim: ft=sls include: - - template.install - - template.config - - template.service + - .package + - .config + - .service diff --git a/template/install.sls b/template/install.sls deleted file mode 100644 index bb45cc1a..00000000 --- a/template/install.sls +++ /dev/null @@ -1,8 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{%- from tpldir ~ "/map.jinja" import template with context %} - -template-pkg: - pkg.installed: - - name: {{ template.pkg }} diff --git a/template/map.jinja b/template/map.jinja index 5bfeb2d7..7d28ed9b 100644 --- a/template/map.jinja +++ b/template/map.jinja @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- # vim: ft=jinja -{#- Get the `topdir` from `tpldir` #} -{%- set topdir = tpldir.split('/')[0] %} +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} {#- Start imports as #} -{%- import_yaml topdir ~ "/defaults.yaml" or {} as default_settings %} -{%- import_yaml topdir ~ "/osfamilymap.yaml" or {} as osfamilymap %} -{%- import_yaml topdir ~ "/osmap.yaml" or {} as osmap %} -{%- import_yaml topdir ~ "/osfingermap.yaml" or {} as osfingermap %} +{%- import_yaml tplroot ~ "/defaults.yaml" or {} as default_settings %} +{%- import_yaml tplroot ~ "/osfamilymap.yaml" or {} as osfamilymap %} +{%- import_yaml tplroot ~ "/osmap.yaml" or {} as osmap %} +{%- import_yaml tplroot ~ "/osfingermap.yaml" or {} as osfingermap %} {% set defaults = salt['grains.filter_by'](default_settings, default='template', diff --git a/template/package/clean.sls b/template/package/clean.sls new file mode 100644 index 00000000..8d2660f9 --- /dev/null +++ b/template/package/clean.sls @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- set sls_config_clean = tplroot ~ '.config.clean' %} +{%- from tplroot ~ "/map.jinja" import template with context %} + +include: + - {{ sls_config_clean }} + +template-package-clean-pkg-removed: + pkg.removed: + - name: {{ template.pkg }} + - require: + - sls: {{ sls_config_clean }} diff --git a/template/package/init.sls b/template/package/init.sls new file mode 100644 index 00000000..d3e55181 --- /dev/null +++ b/template/package/init.sls @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .install diff --git a/template/package/install.sls b/template/package/install.sls new file mode 100644 index 00000000..78bdb5ea --- /dev/null +++ b/template/package/install.sls @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import template with context %} + +template-package-install-pkg-installed: + pkg.installed: + - name: {{ template.pkg }} diff --git a/template/service.sls b/template/service.sls deleted file mode 100644 index 4e4daae6..00000000 --- a/template/service.sls +++ /dev/null @@ -1,12 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{%- from tpldir ~ "/map.jinja" import template with context %} - -include: - - template.config - -template-name: - service.running: - - name: {{ template.service.name }} - - enable: True diff --git a/template/service/clean.sls b/template/service/clean.sls new file mode 100644 index 00000000..2074193d --- /dev/null +++ b/template/service/clean.sls @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import template with context %} + +template-service-clean-service-dead: + service.dead: + - name: {{ template.service.name }} + - enable: False diff --git a/template/service/init.sls b/template/service/init.sls new file mode 100644 index 00000000..6fe4d1a3 --- /dev/null +++ b/template/service/init.sls @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .running diff --git a/template/service/running.sls b/template/service/running.sls new file mode 100644 index 00000000..d668f85f --- /dev/null +++ b/template/service/running.sls @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- set sls_config_file = tplroot ~ '.config.file' %} +{%- from tplroot ~ "/map.jinja" import template with context %} + +include: + - {{ sls_config_file }} + +template-service-running-service-running: + service.running: + - name: {{ template.service.name }} + - enable: True + - require: + - sls: {{ sls_config_file }}