Skip to content
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

feat(pkg): separate components, use requisites and add clean states #48

Merged
merged 13 commits into from
Feb 28, 2019
Merged
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
37 changes: 33 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,51 @@ 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.

``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.

7 changes: 7 additions & 0 deletions template/clean.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .service.clean
- .config.clean
- .package.clean
23 changes: 0 additions & 23 deletions template/config.sls

This file was deleted.

17 changes: 17 additions & 0 deletions template/config/clean.sls
Original file line number Diff line number Diff line change
@@ -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 }}
27 changes: 27 additions & 0 deletions template/config/file.sls
Original file line number Diff line number Diff line change
@@ -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
noelmcloughlin marked this conversation as resolved.
Show resolved Hide resolved
- group: root
- template: jinja
- require:
- sls: {{ sls_package_install }}
5 changes: 5 additions & 0 deletions template/config/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
myii marked this conversation as resolved.
Show resolved Hide resolved
# vim: ft=sls

include:
- .file
6 changes: 3 additions & 3 deletions template/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# vim: ft=sls

include:
- template.install
- template.config
- template.service
- .package
- .config
- .service
8 changes: 0 additions & 8 deletions template/install.sls

This file was deleted.

12 changes: 6 additions & 6 deletions template/map.jinja
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
16 changes: 16 additions & 0 deletions template/package/clean.sls
Original file line number Diff line number Diff line change
@@ -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 }}
5 changes: 5 additions & 0 deletions template/package/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .install
10 changes: 10 additions & 0 deletions template/package/install.sls
Original file line number Diff line number Diff line change
@@ -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 }}
12 changes: 0 additions & 12 deletions template/service.sls

This file was deleted.

11 changes: 11 additions & 0 deletions template/service/clean.sls
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions template/service/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .running
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Againinit.sls could include the actual startup SLS so it mirrors clean.sls which manages the dead SLS.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I see running.sls mirroring clean.sls.

17 changes: 17 additions & 0 deletions template/service/running.sls
Original file line number Diff line number Diff line change
@@ -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 }}