Skip to content

Commit c4440d7

Browse files
committed
feat(sub-component): manage a dedicated configuration file
* 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.
1 parent 42a75d9 commit c4440d7

File tree

10 files changed

+76
-0
lines changed

10 files changed

+76
-0
lines changed

pillar.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ template:
2424
{%- endif %}
2525
config: /etc/template-formula.conf
2626

27+
subcomponent:
28+
config: /etc/template-subcomponent-formula.conf
29+
2730
tofs:
2831
# The files_switch key serves as a selector for alternative
2932
# directories under the formula files directory. See TOFS pattern
@@ -54,6 +57,8 @@ template:
5457
source_files:
5558
template-config-file-file-managed:
5659
- 'example.tmpl.jinja'
60+
template-subcomponent-config-file-file-managed:
61+
- 'subcomponent-example.tmpl.jinja'
5762

5863
# Just for testing purposes
5964
winner: pillar

template/clean.sls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# vim: ft=sls
33

44
include:
5+
- .subcomponent.clean
56
- .service.clean
67
- .config.clean
78
- .package.clean

template/init.sls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ include:
55
- .package
66
- .config
77
- .service
8+
- .subcomponent

template/subcomponent/clean.sls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
include:
5+
- .config.clean
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- set sls_service_running = tplroot ~ '.service.running' %}
7+
{%- from tplroot ~ "/map.jinja" import template with context %}
8+
9+
include:
10+
- {{ sls_service_running }}
11+
12+
template-subcomponent-config-clean-file-absent:
13+
file.absent:
14+
- name: {{ template.subcomponent.config }}
15+
- watch_in:
16+
- sls: {{ sls_service_running }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- set sls_config_file = tplroot ~ '.config.file' %}
7+
{%- from tplroot ~ "/map.jinja" import template with context %}
8+
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
9+
10+
include:
11+
- {{ sls_config_file }}
12+
13+
template-subcomponent-config-file-file-managed:
14+
file.managed:
15+
- name: {{ template.subcomponent.config }}
16+
- source: {{ files_switch(['subcomponent-example.tmpl'],
17+
lookup='template-subcomponent-config-file-file-managed'
18+
)
19+
}}
20+
- mode: 644
21+
- user: root
22+
- group: {{ template.rootgroup }}
23+
- makedirs: True
24+
- template: jinja
25+
- require_in:
26+
- sls: {{ sls_config_file }}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
include:
5+
- .file
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
########################################################################
2+
# File managed by Salt at <{{ source }}>.
3+
# Your changes will be overwritten.
4+
########################################################################
5+
6+
This is a subcomponent example file from SaltStack template-formula.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
########################################################################
2+
# File managed by Salt at <{{ source }}>.
3+
# Your changes will be overwritten.
4+
########################################################################
5+
6+
This is another subcomponent example file from SaltStack template-formula.

template/subcomponent/init.sls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
include:
5+
- .config

0 commit comments

Comments
 (0)