Last active
September 25, 2015 07:10
-
-
Save mjinks/31267d8e2945b3764011 to your computer and use it in GitHub Desktop.
turning a simple formula into an iterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Starting from: | |
https://github.com/saltstack-formulas/vsftpd-formula | |
vsftpd supports per-user configurations, which the formula doesn't yet cover, so I'm trying to | |
extend it. I'm also really new at this so the basic toolkit is still a challenge for me. | |
vsftpd.conf mostly consists of a list of key = value pairs. The template that produces it | |
is mostly a list of tuples, type_of_key("key", "default"). | |
Per-user configuration looks just like main server configuration, more or less; alongside | |
the main config file, there are per-user config files: | |
/etc/vsftpd/vsftpd_user_conf/[username] | |
...where each 'username' file conforms to the same format as the main server config file, | |
with the same list of options. (A lot don't make sense per-user obviously, but that's the gist.) | |
I'm trying to write a new template by copying and adjusting the existing one. I'm hung up on | |
what seems like a simple enough issue, but I don't know how to express it well enough to hunt | |
down the approach. | |
The original formula populates its main config file wit a pillar: | |
vsftpd: | |
foo: 23 | |
bar: whatever | |
In my pillar, I have: | |
vsftpd_user_conf: | |
tom: | |
- foo: 23 | |
- bar: sometimes | |
dick: | |
- foo: 42 | |
- bar: never | |
My goal is to produce files named for the first layer of elements | |
(tom, dick, etc.) where each files is made from a template pupulated | |
with those elements. You get the idea. | |
I've got the formula extended to the point where it produces the per-user | |
files under /etc/vsftpd/vsftpd_user_conf/[tom, dick, george, ringo], and | |
I've got a pillar of the form: | |
vsftpd_user_configs: | |
tom: | |
- foo: 23 | |
- bar: this | |
dick: | |
- foo: 42 | |
- bar: that | |
[...] | |
...but I haven't figured out the right syntax for fitting a layer | |
into the template so that walks that list of accounts. | |
This is obviously wrong: | |
{%- for user, conf in pillar.get('vsftpd_user_config', {}).items() if user.absent is not defined or not user.absent %} | |
I've had better attempts but they're lost in a sea of edits and deletes. | |
Get the idea? Clue me up? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment