refactor: improve reusability using an unique keyword TEMPLATE

BREAKING CHANGE: changed all state names and ids
This commit is contained in:
Dafydd Jones 2019-11-22 22:45:32 +00:00
parent 341f495336
commit 2e8ded6565
39 changed files with 120 additions and 120 deletions

View file

@ -1,9 +1,9 @@
name: template
name: TEMPLATE
os: Debian, Ubuntu, Raspbian, RedHat, Fedora, CentOS, Suse, openSUSE, Gentoo, Funtoo, Arch, Manjaro, Alpine, FreeBSD, OpenBSD, Solaris, SmartOS, Windows, MacOS
os_family: Debian, RedHat, Suse, Gentoo, Arch, Alpine, FreeBSD, OpenBSD, Solaris, Windows, MacOS
version: 3.3.4
release: 1
minimum_version: 2017.7
summary: template formula
summary: TEMPLATE formula
description: Formula to use as a template for other formulas
top_level_dir: template
top_level_dir: TEMPLATE

View file

@ -4,13 +4,13 @@
{#- 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 ~ "/map.jinja" import TEMPLATE with context %}
include:
- {{ sls_service_clean }}
template-config-clean-file-absent:
TEMPLATE-config-clean-file-absent:
file.absent:
- name: {{ template.config }}
- name: {{ TEMPLATE.config }}
- require:
- sls: {{ sls_service_clean }}

View file

@ -4,25 +4,25 @@
{#- 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 ~ "/map.jinja" import TEMPLATE with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
include:
- {{ sls_package_install }}
template-config-file-file-managed:
TEMPLATE-config-file-file-managed:
file.managed:
- name: {{ template.config }}
- name: {{ TEMPLATE.config }}
- source: {{ files_switch(['example.tmpl'],
lookup='template-config-file-file-managed'
lookup='TEMPLATE-config-file-file-managed'
)
}}
- mode: 644
- user: root
- group: {{ template.rootgroup }}
- group: {{ TEMPLATE.rootgroup }}
- makedirs: True
- template: jinja
- require:
- sls: {{ sls_package_install }}
- context:
template: {{ template | json }}
TEMPLATE: {{ TEMPLATE | json }}

View file

@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
template:
TEMPLATE:
pkg:
name: template
name: TEMPLATE
rootgroup: root
config: '/etc/template'
config: '/etc/TEMPLATE'
service:
name: template
name: TEMPLATE
subcomponent:
config: '/etc/template-subcomponent-formula.conf'
config: '/etc/TEMPLATE-subcomponent-formula.conf'
# Just here for testing
added_in_defaults: defaults_value
winner: defaults

View file

@ -6,6 +6,6 @@
This is another example file from SaltStack template-formula.
# This is here for testing purposes
{{ template | json }}
{{ TEMPLATE | json }}
winner of the merge: {{ template['winner'] }}
winner of the merge: {{ TEMPLATE['winner'] }}

View file

@ -46,11 +46,11 @@
)
%}
{#- Change **template** to match with your formula's name and then remove this line #}
{%- set template = config %}
{#- Change **TEMPLATE** to match with your formula's name and then remove this line #}
{%- set TEMPLATE = config %}
{#- Post-processing for specific non-YAML customisations #}
{%- if grains.os == 'MacOS' %}
{%- set macos_group = salt['cmd.run']("stat -f '%Sg' /dev/console") %}
{%- do template.update({'rootgroup': macos_group}) %}
{%- do TEMPLATE.update({'rootgroup': macos_group}) %}
{%- endif %}

View file

@ -12,23 +12,23 @@
---
Debian:
pkg:
name: template-debian
config: /etc/template.d/custom.conf
name: TEMPLATE-debian
config: /etc/TEMPLATE.d/custom.conf
RedHat:
pkg:
name: template-redhat
config: /etc/template.conf
name: TEMPLATE-redhat
config: /etc/TEMPLATE.conf
Suse:
pkg:
name: template-suse
name: TEMPLATE-suse
Gentoo: {}
Arch:
pkg:
name: template-arch
name: TEMPLATE-arch
service:
name: service-arch

View file

@ -12,11 +12,11 @@
---
# os: Ubuntu
Ubuntu-18.04:
config: /etc/template.d/custom-ubuntu-18.04.conf
config: /etc/TEMPLATE.d/custom-ubuntu-18.04.conf
# os: CentOS
CentOS-6:
pkg:
name: template-centos-6
config: /etc/template.d/custom-centos-6.conf
name: TEMPLATE-centos-6
config: /etc/TEMPLATE.d/custom-centos-6.conf
CentOS-7: {}

View file

@ -13,15 +13,15 @@
# os_family: Debian
Ubuntu:
pkg:
name: template-ubuntu
config: /etc/template.d/custom-ubuntu.conf
name: TEMPLATE-ubuntu
config: /etc/TEMPLATE.d/custom-ubuntu.conf
Raspbian: {}
# os_family: RedHat
Fedora:
pkg:
name: template-fedora
name: TEMPLATE-fedora
service:
name: service-fedora

View file

@ -4,13 +4,13 @@
{#- 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 %}
{%- from tplroot ~ "/map.jinja" import TEMPLATE with context %}
include:
- {{ sls_config_clean }}
template-package-clean-pkg-removed:
TEMPLATE-package-clean-pkg-removed:
pkg.removed:
- name: {{ template.pkg.name }}
- name: {{ TEMPLATE.pkg.name }}
- require:
- sls: {{ sls_config_clean }}

View file

@ -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.name }}

View file

@ -3,9 +3,9 @@
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import template with context %}
{%- from tplroot ~ "/map.jinja" import TEMPLATE with context %}
template-service-clean-service-dead:
TEMPLATE-service-clean-service-dead:
service.dead:
- name: {{ template.service.name }}
- name: {{ TEMPLATE.service.name }}
- enable: False

View file

@ -4,14 +4,14 @@
{#- 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 ~ "/map.jinja" import TEMPLATE with context %}
include:
- {{ sls_config_file }}
template-service-running-service-running:
TEMPLATE-service-running-service-running:
service.running:
- name: {{ template.service.name }}
- name: {{ TEMPLATE.service.name }}
- enable: True
- require:
- sls: {{ sls_config_file }}

View file

@ -4,13 +4,13 @@
{#- 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 ~ "/map.jinja" import TEMPLATE with context %}
include:
- {{ sls_service_clean }}
template-subcomponent-config-clean-file-absent:
TEMPLATE-subcomponent-config-clean-file-absent:
file.absent:
- name: {{ template.subcomponent.config }}
- name: {{ TEMPLATE.subcomponent.config }}
- watch_in:
- sls: {{ sls_service_clean }}

View file

@ -4,23 +4,23 @@
{#- 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 ~ "/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:
TEMPLATE-subcomponent-config-file-file-managed:
file.managed:
- name: {{ template.subcomponent.config }}
- name: {{ TEMPLATE.subcomponent.config }}
- source: {{ files_switch(['subcomponent-example.tmpl'],
lookup='template-subcomponent-config-file-file-managed',
lookup='TEMPLATE-subcomponent-config-file-file-managed',
use_subpath=True
)
}}
- mode: 644
- user: root
- group: {{ template.rootgroup }}
- group: {{ TEMPLATE.rootgroup }}
- makedirs: True
- template: jinja
- require_in:

View file

@ -8,7 +8,7 @@ Contributing documentation
.. |docs| image:: https://readthedocs.org/projects/docs/badge/?version=latest
:alt: Documentation Status
:scale: 100%
:target: https://template-formula.readthedocs.io/en/latest/?badge=latest
:target: https://TEMPLATE-formula.readthedocs.io/en/latest/?badge=latest
Toolchain
^^^^^^^^^

View file

@ -1,14 +1,14 @@
.. _readme:
template-formula
TEMPLATE-formula
================
|img_travis| |img_sr|
.. |img_travis| image:: https://travis-ci.com/saltstack-formulas/template-formula.svg?branch=master
.. |img_travis| image:: https://travis-ci.com/saltstack-formulas/TEMPLATE-formula.svg?branch=master
:alt: Travis CI Build Status
:scale: 100%
:target: https://travis-ci.com/saltstack-formulas/template-formula
:target: https://travis-ci.com/saltstack-formulas/TEMPLATE-formula
.. |img_sr| image:: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
:alt: Semantic Release
:scale: 100%
@ -53,79 +53,79 @@ Available states
.. contents::
:local:
``template``
``TEMPLATE``
^^^^^^^^^^^^
*Meta-state (This is a state that includes other states)*.
This installs the template package,
manages the template configuration file and then
starts the associated template service.
This installs the TEMPLATE package,
manages the TEMPLATE configuration file and then
starts the associated TEMPLATE service.
``template.package``
``TEMPLATE.package``
^^^^^^^^^^^^^^^^^^^^
This state will install the template package only.
This state will install the TEMPLATE package only.
``template.config``
``TEMPLATE.config``
^^^^^^^^^^^^^^^^^^^
This state will configure the template service and has a dependency on ``template.install``
This state will configure the TEMPLATE service and has a dependency on ``TEMPLATE.install``
via include list.
``template.service``
``TEMPLATE.service``
^^^^^^^^^^^^^^^^^^^^
This state will start the template service and has a dependency on ``template.config``
This state will start the TEMPLATE service and has a dependency on ``TEMPLATE.config``
via include list.
``template.clean``
``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.
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``
``TEMPLATE.service.clean``
^^^^^^^^^^^^^^^^^^^^^^^^^^
This state will stop the template service and disable it at boot time.
This state will stop the TEMPLATE service and disable it at boot time.
``template.config.clean``
``TEMPLATE.config.clean``
^^^^^^^^^^^^^^^^^^^^^^^^^
This state will remove the configuration of the template service and has a
dependency on ``template.service.clean`` via include list.
This state will remove the configuration of the TEMPLATE service and has a
dependency on ``TEMPLATE.service.clean`` via include list.
``template.package.clean``
``TEMPLATE.package.clean``
^^^^^^^^^^^^^^^^^^^^^^^^^^
This state will remove the template package and has a depency on
``template.config.clean`` via include list.
This state will remove the TEMPLATE package and has a depency on
``TEMPLATE.config.clean`` via include list.
``template.subcomponent``
``TEMPLATE.subcomponent``
^^^^^^^^^^^^^^^^^^^^^^^^^
*Meta-state (This is a state that includes other states)*.
This state installs a subcomponent configuration file before
configuring and starting the template service.
configuring and starting the TEMPLATE service.
``template.subcomponent.config``
``TEMPLATE.subcomponent.config``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This state will configure the template subcomponent and has a
dependency on ``template.config`` via include list.
This state will configure the TEMPLATE subcomponent and has a
dependency on ``TEMPLATE.config`` via include list.
``template.subcomponent.config.clean``
``TEMPLATE.subcomponent.config.clean``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This state will remove the configuration of the template subcomponent
and reload the template service by a dependency on
``template.service.running`` via include list and ``watch_in``
This state will remove the configuration of the TEMPLATE subcomponent
and reload the TEMPLATE service by a dependency on
``TEMPLATE.service.running`` via include list and ``watch_in``
requisite.
Testing
@ -151,7 +151,7 @@ e.g. ``debian-9-2019-2-py3``.
``bin/kitchen converge``
^^^^^^^^^^^^^^^^^^^^^^^^
Creates the docker instance and runs the ``template`` main state, ready for testing.
Creates the docker instance and runs the ``TEMPLATE`` main state, ready for testing.
``bin/kitchen verify``
^^^^^^^^^^^^^^^^^^^^^^

View file

@ -162,7 +162,7 @@ provisioner:
log_level: debug
salt_install: none
require_chef: false
formula: template
formula: TEMPLATE
salt_copy_filter:
- .kitchen
- .git
@ -183,15 +183,15 @@ suites:
state_top:
base:
'*':
- template
- TEMPLATE
pillars:
top.sls:
base:
'*':
- template
- TEMPLATE
- define_roles
pillars_from_files:
template.sls: pillar.example
TEMPLATE.sls: pillar.example
define_roles.sls: test/salt/pillar/define_roles.sls
verifier:
inspec_tests:
@ -203,15 +203,15 @@ suites:
state_top:
base:
'*':
- template
- TEMPLATE
pillars:
top.sls:
base:
'*':
- template
- TEMPLATE
- define_roles
pillars_from_files:
template.sls: test/salt/pillar/centos6.sls
TEMPLATE.sls: test/salt/pillar/centos6.sls
define_roles.sls: test/salt/pillar/define_roles.sls
verifier:
inspec_tests:

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
template:
TEMPLATE:
lookup:
master: template-master
# Just for testing purposes
@ -33,7 +33,7 @@ template:
# All aspects of path/file resolution are customisable using the options below.
# This is unnecessary in most cases; there are sensible defaults.
# Default path: salt://< path_prefix >/< dirs.files >/< dirs.default >
# I.e.: salt://template/files/default
# I.e.: salt://TEMPLATE/files/default
# path_prefix: template_alt
# dirs:
# files: files_alt
@ -41,15 +41,15 @@ template:
# The entries under `source_files` are prepended to the default source files
# given for the state
# source_files:
# template-config-file-file-managed:
# TEMPLATE-config-file-file-managed:
# - 'example_alt.tmpl'
# - 'example_alt.tmpl.jinja'
# For testing purposes
source_files:
template-config-file-file-managed:
TEMPLATE-config-file-file-managed:
- 'example.tmpl.jinja'
template-subcomponent-config-file-file-managed:
TEMPLATE-subcomponent-config-file-file-managed:
- 'subcomponent-example.tmpl.jinja'
# Just for testing purposes

View file

@ -1,10 +0,0 @@
# -*- 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.name }}

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
control 'template configuration' do
control 'TEMPLATE configuration' do
title 'should match desired lines'
describe file('/etc/template-formula.conf') do
@ -24,8 +24,8 @@ control 'template configuration' do
should include(
'"tofs": {"files_switch": ["any/path/can/be/used/here", "id", '\
'"roles", "osfinger", "os", "os_family"], "source_files": '\
'{"template-config-file-file-managed": ["example.tmpl.jinja"], '\
'"template-subcomponent-config-file-file-managed": '\
'{"TEMPLATE-config-file-file-managed": ["example.tmpl.jinja"], '\
'"TEMPLATE-subcomponent-config-file-file-managed": '\
'["subcomponent-example.tmpl.jinja"]}'
)
end

View file

@ -4,7 +4,7 @@
package_name = 'bash'
package_name = 'cronie' if (os[:name] == 'centos') && os[:release].start_with?('6')
control 'template package' do
control 'TEMPLATE package' do
title 'should be installed'
describe package(package_name) do

View file

@ -4,7 +4,7 @@
service_name = 'systemd-udevd'
service_name = 'crond' if (os[:name] == 'centos') && os[:release].start_with?('6')
control 'template service' do
control 'TEMPLATE service' do
impact 0.5
title 'should be running and enabled'

View file

@ -1,9 +1,9 @@
# frozen_string_literal: true
control 'template subcomponent configuration' do
control 'TEMPLATE subcomponent configuration' do
title 'should match desired lines'
describe file('/etc/template-subcomponent-formula.conf') do
describe file('/etc/TEMPLATE-subcomponent-formula.conf') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
@ -11,7 +11,7 @@ control 'template subcomponent configuration' do
its('content') do
should include(
'# File managed by Salt at '\
'<salt://template/subcomponent/config/files/default/'\
'<salt://TEMPLATE/subcomponent/config/files/default/'\
'subcomponent-example.tmpl.jinja>.'
)
end

View file

@ -2,10 +2,10 @@
# vim: ft=yaml
---
name: default
title: template formula
title: TEMPLATE formula
maintainer: SaltStack Formulas
license: Apache-2.0
summary: Verify that the template formula is setup and configured correctly
summary: Verify that the TEMPLATE formula is setup and configured correctly
supports:
- platform-name: debian
- platform-name: ubuntu

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
template:
TEMPLATE:
lookup:
master: template-master
# Just for testing purposes
@ -45,9 +45,9 @@ template:
# For testing purposes
source_files:
template-config-file-file-managed:
TEMPLATE-config-file-file-managed:
- 'example.tmpl.jinja'
template-subcomponent-config-file-file-managed:
TEMPLATE-subcomponent-config-file-file-managed:
- 'subcomponent-example.tmpl.jinja'
# Just for testing purposes