mirror of
https://github.com/saltstack-formulas/template-formula.git
synced 2025-04-17 10:10:28 +00:00
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.
This commit is contained in:
parent
42a75d99ee
commit
c4440d7c55
10 changed files with 76 additions and 0 deletions
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# vim: ft=sls
|
||||
|
||||
include:
|
||||
- .subcomponent.clean
|
||||
- .service.clean
|
||||
- .config.clean
|
||||
- .package.clean
|
||||
|
|
|
@ -5,3 +5,4 @@ include:
|
|||
- .package
|
||||
- .config
|
||||
- .service
|
||||
- .subcomponent
|
||||
|
|
5
template/subcomponent/clean.sls
Normal file
5
template/subcomponent/clean.sls
Normal file
|
@ -0,0 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=sls
|
||||
|
||||
include:
|
||||
- .config.clean
|
16
template/subcomponent/config/clean.sls
Normal file
16
template/subcomponent/config/clean.sls
Normal file
|
@ -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
template/subcomponent/config/file.sls
Normal file
26
template/subcomponent/config/file.sls
Normal file
|
@ -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
template/subcomponent/config/init.sls
Normal file
5
template/subcomponent/config/init.sls
Normal file
|
@ -0,0 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=sls
|
||||
|
||||
include:
|
||||
- .file
|
|
@ -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.
|
|
@ -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
template/subcomponent/init.sls
Normal file
5
template/subcomponent/init.sls
Normal file
|
@ -0,0 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=sls
|
||||
|
||||
include:
|
||||
- .config
|
Loading…
Add table
Reference in a new issue