Skip to content

Commit

Permalink
feat(sub-component): manage a dedicated configuration file
Browse files Browse the repository at this point in the history
* pillar.example (template.subcomponent): configurable sub-component
  destination.
  (template.tofs.source_files): override sub-component template

* template/init.sls (include): setup sub-component last.

* template/clean.sls (include): clean sub-component first.

* template/subcomponent/init.sls: include the only setup state
  “config”.

* template/subcomponent/config/init.sls: include the only config state
  “file”.

* template/subcomponent/config/file.sls: manage the sub-component
  configuration file. It requires the main component configuration.

* template/subcomponent/files/default/subcomponent-example.tmpl.jinja:
  jinja template for the sub-component.

* template/subcomponent/files/default/subcomponent-example.tmpl:
  static configuration for the sub-component.

* template/subcomponent/clean.sls: include the only cleanup state “config”.

* template/subcomponent/config/clean.sls: remove the sub-component
  configuration file.
  • Loading branch information
baby-gnu committed Jul 30, 2019
1 parent 42a75d9 commit c4440d7
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ template:
{%- endif %}
config: /etc/template-formula.conf

subcomponent:
config: /etc/template-subcomponent-formula.conf

tofs:
# The files_switch key serves as a selector for alternative
# directories under the formula files directory. See TOFS pattern
Expand Down Expand Up @@ -54,6 +57,8 @@ template:
source_files:
template-config-file-file-managed:
- 'example.tmpl.jinja'
template-subcomponent-config-file-file-managed:
- 'subcomponent-example.tmpl.jinja'

# Just for testing purposes
winner: pillar
Expand Down
1 change: 1 addition & 0 deletions template/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# vim: ft=sls

include:
- .subcomponent.clean
- .service.clean
- .config.clean
- .package.clean
1 change: 1 addition & 0 deletions template/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ include:
- .package
- .config
- .service
- .subcomponent
5 changes: 5 additions & 0 deletions template/subcomponent/clean.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .config.clean
16 changes: 16 additions & 0 deletions template/subcomponent/config/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_service_running = tplroot ~ '.service.running' %}
{%- from tplroot ~ "/map.jinja" import template with context %}
include:
- {{ sls_service_running }}
template-subcomponent-config-clean-file-absent:
file.absent:
- name: {{ template.subcomponent.config }}
- watch_in:
- sls: {{ sls_service_running }}
26 changes: 26 additions & 0 deletions template/subcomponent/config/file.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- 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 %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
include:
- {{ sls_config_file }}
template-subcomponent-config-file-file-managed:
file.managed:
- name: {{ template.subcomponent.config }}
- source: {{ files_switch(['subcomponent-example.tmpl'],
lookup='template-subcomponent-config-file-file-managed'
)
}}
- mode: 644
- user: root
- group: {{ template.rootgroup }}
- makedirs: True
- template: jinja
- require_in:
- sls: {{ sls_config_file }}
5 changes: 5 additions & 0 deletions template/subcomponent/config/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .file
6 changes: 6 additions & 0 deletions template/subcomponent/files/default/subcomponent-example.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
########################################################################
# File managed by Salt at <{{ source }}>.
# Your changes will be overwritten.
########################################################################

This is a subcomponent example file from SaltStack template-formula.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
########################################################################
# File managed by Salt at <{{ source }}>.
# Your changes will be overwritten.
########################################################################

This is another subcomponent example file from SaltStack template-formula.
5 changes: 5 additions & 0 deletions template/subcomponent/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .config

0 comments on commit c4440d7

Please sign in to comment.