Skip to content

Commit 5105d29

Browse files
committed
docs(tofs): improve general use of language
1 parent 3fa3640 commit 5105d29

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

TOFS_pattern.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
# TOFS: A pattern for using Saltstack
1+
# TOFS: A pattern for using SaltStack
22

33
Roberto Moreda <[email protected]>
44
29/12/2014
55

66
Modified by Daniel Dehennin <[email protected]>
77

8-
All that follows is a proposal based on my experience with [Saltstack](http://www.saltstack.com/). The good thing of a piece of software like this is that you can "bend it" to suit your needs in many possible ways, and this is one of them. All the recommendations and thoughts are given "as it is" with no warranty of any type.
8+
Updated by Imran Iqbal <https://github.com/myii>
9+
10+
All that follows is a proposal based on my experience with [SaltStack](http://www.saltstack.com/). The good thing of a piece of software like this is that you can "bend it" to suit your needs in many possible ways, and this is one of them. All the recommendations and thoughts are given "as it is" with no warranty of any type.
911

1012
<table><tr><th>Table of Contents</th></tr><tr><td>
1113

1214
<!-- toc -->
1315

1416
- [Usage of values in pillar vs templates in file_roots](#usage-of-values-in-pillar-vs-templates-in-file_roots)
15-
- [On reusability of Saltstack state files](#on-reusability-of-saltstack-state-files)
17+
- [On reusability of SaltStack state files](#on-reusability-of-saltstack-state-files)
1618
- [The Template Override and Files Switch (TOFS) pattern](#the-template-override-and-files-switch-tofs-pattern)
1719
* [Template Override](#template-override)
1820
* [Files Switch](#files-switch)
@@ -22,31 +24,31 @@ All that follows is a proposal based on my experience with [Saltstack](http://ww
2224
</td></tr></table>
2325

2426

25-
## Usage of values in pillar vs templates in file_roots
27+
## Usage of values in pillar vs templates in `file_roots`
2628

2729
Among other functions, the _master_ (or _salt-master_) serves files to the _minions_ (or _salt-minions_). The [file_roots](http://docs.saltstack.com/en/latest/ref/file_server/file_roots.html) is the list of directories used in sequence to find a file when a minion requires it: the first match is served to the minion. Those files could be [state files](http://docs.saltstack.com/en/latest/topics/tutorials/starting_states.html) or configuration templates, among others.
2830

29-
Using Saltstack is a simple and effective way to implement configuration management, but even in a [non multitenant](http://en.wikipedia.org/wiki/Multitenancy) scenario, it's not a good idea to generally accessible some data (e.g. the database password in our [Zabbix](http://www.zabbix.com/) server configuration file or the private key of our [Nginx](http://nginx.org/en/) TLS certificate).
31+
Using SaltStack is a simple and effective way to implement configuration management, but even in a [non-multitenant](http://en.wikipedia.org/wiki/Multitenancy) scenario, it is not a good idea to generally access some data (e.g. the database password in our [Zabbix](http://www.zabbix.com/) server configuration file or the private key of our [Nginx](http://nginx.org/en/) TLS certificate).
3032

31-
To avoid this situation we can use the [pillar mechanism](http://docs.saltstack.com/en/latest/topics/pillar/), which is designed to provide a controlled access to data from the minions based on some selection rules. As pillar data could be easily integrated in the [Jinja](http://docs.saltstack.com/en/latest/topics/tutorials/pillar.html) templates, it's a good mechanism to store values to be used in the final render of state files and templates.
33+
To avoid this situation we can use the [pillar mechanism](http://docs.saltstack.com/en/latest/topics/pillar/), which is designed to provide controlled access to data from the minions based on some selection rules. As pillar data could be easily integrated in the [Jinja](http://docs.saltstack.com/en/latest/topics/tutorials/pillar.html) templates, it is a good mechanism to store values to be used in the final rendering of state files and templates.
3234

33-
There are a variety of approaches on usage of pillar and templates seen in [saltstack-formulas](https://github.com/saltstack-formulas) repositories. [Some](https://github.com/saltstack-formulas/nginx-formula/pull/18) [developments](https://github.com/saltstack-formulas/php-formula/pull/14) stress the initial purpose of pillar data into an storage for most of possible variables for a determined system configuration. This, in my opinion, shifting too much load from the original template files approach. Adding up some [non-trivial Jinja](https://github.com/spsoit/nginx-formula/blob/81de880fe0276dd9488ffa15bc78944c0fc2b919/nginx/ng/files/nginx.conf) code as essential part of composing the state file definitely makes Saltstack state files (hence formulas) more difficult to read. The extreme of this approach is that we could end up with a new render mechanism, implemented in Jinja, storing everything needed in pillar data to compose configurations. Additionally, we are establishing a strong dependency with the Jinja renderer.
35+
There are a variety of approaches on the usage of pillar and templates as seen in the [saltstack-formulas](https://github.com/saltstack-formulas)' repositories. [Some](https://github.com/saltstack-formulas/nginx-formula/pull/18) [developments](https://github.com/saltstack-formulas/php-formula/pull/14) stress the initial purpose of pillar data into a storage for most of the possible variables for a determined system configuration. This, in my opinion, is shifting too much load from the original template files approach. Adding up some [non-trivial Jinja](https://github.com/spsoit/nginx-formula/blob/81de880fe0276dd9488ffa15bc78944c0fc2b919/nginx/ng/files/nginx.conf) code as essential part of composing the state file definitely makes SaltStack state files (hence formulas) more difficult to read. The extreme of this approach is that we could end up with a new render mechanism, implemented in Jinja, storing everything needed in pillar data to compose configurations. Additionally, we are establishing a strong dependency with the Jinja renderer.
3436

35-
Opposed to the _put in file\_roots the code and in pillar the data_ approach, there's the _pillar as a store for a set of key-values_ approach. A full-blown configuration file abstracted in pillar and jinja is complicated to develop, understand and maintain. I think it's better a simpler approach keeping a configuration file templated using just a basic (non-extensive but extensible) set of pillar values.
37+
In opposition to the _put the code in file\_roots and the data in pillars_ approach, there is the _pillar as a store for a set of key-values_ approach. A full-blown configuration file abstracted in pillar and jinja is complicated to develop, understand and maintain. I think a better and simpler approach is to keep a configuration file templated using just a basic (non-extensive but extensible) set of pillar values.
3638

3739

38-
## On reusability of Saltstack state files
40+
## On the reusability of SaltStack state files
3941

40-
There's a brilliant initiative of the Saltstack community called [salt-formulas](https://github.com/saltstack-formulas). The goal is to provide state files, pillar examples and configuration templates ready to be used for provisioning. I'm a contributor or two small ones: [zabbix-formula](https://github.com/saltstack-formulas/zabbix-formula) and [varnish-formula](https://github.com/saltstack-formulas/varnish-formula).
42+
There is a brilliant initiative of the SaltStack community called [salt-formulas](https://github.com/saltstack-formulas). Their goal is to provide state files, pillar examples and configuration templates ready to be used for provisioning. I am a contributor for two small ones: [zabbix-formula](https://github.com/saltstack-formulas/zabbix-formula) and [varnish-formula](https://github.com/saltstack-formulas/varnish-formula).
4143

42-
The [design guidelines](http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html) for formulas are clear in many aspects and it's a recommended reading for anyone willing to write state files, even non-formulaic ones.
44+
The [design guidelines](http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html) for formulas are clear in many aspects and it is a recommended reading for anyone willing to write state files, even non-formulaic ones.
4345

44-
In the next section I'm going to describe my proposal to extend even further the reusability of formulas, suggesting some patterns of usage.
46+
In the next section, I am going to describe my proposal to extend further the reusability of formulas, suggesting some patterns of usage.
4547

4648

4749
## The Template Override and Files Switch (TOFS) pattern
4850

49-
I understand a formula as a **complete, independent set of Saltstack state and configuration template files sufficient to configure a system**. A system could be something as simple as a ntp server or some other much more complex service that requires many state and configuration template files.
51+
I understand a formula as a **complete, independent set of SaltStack state and configuration template files sufficient to configure a system**. A system could be something as simple as an NTP server or some other much more complex service that requires many state and configuration template files.
5052

5153
The customization of a formula should be done mainly by providing pillar data used later to render either the state or the configuration template files.
5254

@@ -88,7 +90,7 @@ file_roots:
8890
}, merge=salt['pillar.get']('ntp:lookup')) %}
8991
```
9092

91-
In `init.sls` we have the minimal states required to have NTP configured. In many cases `init.sls` is almost equivalent to a `apt-get install` or a `yum install` of the package.
93+
In `init.sls` we have the minimal states required to have NTP configured. In many cases `init.sls` is almost equivalent to an `apt-get install` or a `yum install` of the package.
9294

9395
```
9496
## /srv/saltstack/salt-formulas/ntp-saltstack-formula/ntp/init.sls
@@ -106,7 +108,7 @@ Enable and start NTP:
106108
- pkg: Install NTP package
107109
```
108110

109-
In `conf.sls` we have the configuration states. In most cases that is just managing configuration file templates and making them be watched by the service.
111+
In `conf.sls` we have the configuration states. In most cases, that is just managing configuration file templates and making them to be watched by the service.
110112

111113
```
112114
## /srv/saltstack/salt-formulas/ntp-saltstack-formula/ntp/conf.sls
@@ -126,7 +128,7 @@ Configure NTP:
126128
- pkg: Install NTP package
127129
```
128130

129-
Under `files/default` there's an structure that mimics the one in the minion in order to avoid clashes and confusion on where to put the needed templates. There you can find a mostly standard template for configuration file.
131+
Under `files/default`, there is a structure that mimics the one in the minion in order to avoid clashes and confusion on where to put the needed templates. There you can find a mostly standard template for the configuration file.
130132

131133
```
132134
## /srv/saltstack/salt-formulas/ntp-saltstack-formula/ntp/files/default/etc/ntp.conf.jinja
@@ -155,9 +157,9 @@ restrict 127.0.0.1
155157
restrict ::1
156158
```
157159

158-
With all this, it's easy to install and configure a simple NTP server just running `salt-call state.sls ntp.conf`: the package will be installed, the service will be running and the configuration should be correct for most of cases, even without pillar data.
160+
With all this, it is easy to install and configure a simple NTP server by just running `salt-call state.sls ntp.conf`: the package will be installed, the service will be running and the configuration should be correct for most of cases, even without pillar data.
159161

160-
Alternatively you can define a highstate in `/srv/saltstack/salt/top.sls` and run `salt-call state.highstate`.
162+
Alternatively, you can define a highstate in `/srv/saltstack/salt/top.sls` and run `salt-call state.highstate`.
161163

162164
```
163165
## /srv/saltstack/salt/top.sls
@@ -166,7 +168,7 @@ base:
166168
- ntp.conf
167169
```
168170

169-
**Customizing the formula just with pillar data** we have the option to define the NTP servers.
171+
**Customizing the formula just with pillar data**, we have the option to define the NTP servers.
170172

171173
```
172174
## /srv/saltstack/pillar/top.sls
@@ -189,7 +191,7 @@ ntp:
189191

190192
### Template Override
191193

192-
If the customization based on pillar data is not enough, we can override the template creating a new one in `/srv/saltstack/salt/ntp/files/default/etc/ntp.conf.jinja`
194+
If the customization based on pillar data is not enough, we can override the template by creating a new one in `/srv/saltstack/salt/ntp/files/default/etc/ntp.conf.jinja`
193195

194196
```
195197
## /srv/saltstack/salt/ntp/files/default/etc/ntp.conf.jinja
@@ -209,11 +211,11 @@ This way we are locally **overriding the template files** offered by the formula
209211

210212
### Files Switch
211213

212-
To bring some order into the set of template files included in a formula, as we commented, we suggest have a similar structure to a normal final file system under `files/default`.
214+
To bring some order into the set of template files included in a formula, as we commented, we suggest having a similar structure to a normal final file system under `files/default`.
213215

214-
We can make coexist different templates for different minions, classified by any [grain](http://docs.saltstack.com/en/latest/topics/targeting/grains.html) value, just creating new directories under `files`. This mechanism is based in **using values of some grains as a switch for the directories under `files/`**.
216+
We can make different templates coexist for different minions, classified by any [grain](http://docs.saltstack.com/en/latest/topics/targeting/grains.html) value, by simply creating new directories under `files`. This mechanism is based on **using values of some grains as a switch for the directories under `files/`**.
215217

216-
If we decide that we want `os_family` as switch, then we could provide with the formula template variants for `RedHat` and `Debian` families.
218+
If we decide that we want `os_family` as switch, then we could provide the formula template variants for both the `RedHat` and `Debian` families.
217219

218220
```
219221
/srv/saltstack/salt-formulas/ntp-saltstack-formula/ntp/files/
@@ -228,7 +230,7 @@ If we decide that we want `os_family` as switch, then we could provide with the
228230
ntp.conf.jinja
229231
```
230232

231-
To make this work we need a `conf.sls` state file that takes a list of possible files as configuration template.
233+
To make this work we need a `conf.sls` state file that takes a list of possible files as the configuration template.
232234

233235
```
234236
## /srv/saltstack/salt-formulas/ntp-saltstack-formula/ntp/conf.sls
@@ -284,7 +286,7 @@ Configure NTP:
284286
- pkg: Install NTP package
285287
```
286288

287-
We can simplify the `conf.sls` with a new `files_switch` macro to use in `source` parameter for the `file.managed` function.
289+
We can simplify the `conf.sls` with the new `files_switch` macro to use in the `source` parameter for the `file.managed` state.
288290

289291
```
290292
## /srv/saltstack/salt-formulas/ntp-saltstack-formula/ntp/conf.sls

0 commit comments

Comments
 (0)