Hi,
On Sun, Jun 22, 2014 at 04:22 -0700, Alex Leonhardt wrote:
> On Sunday, 22 June 2014 11:35:20 UTC+1, Arnold Bechtoldt wrote:
> I took it from the original formula, which I suppose with the map.jinja won't
> work unless I define the values from the map to be accessed differently like
> you did in the httpd formula.
> > here's the sls :
> >
> > {% from "redis/map.jinja" import redis with context %}
> >
> > {% set redis = pillar.get('redis', {}) -%}
> I think that doesn't make sense at all. You are assigning a new value to
> redis.
I think that the original author made a mistake there and wanted to guard
against the case in which values in the map are not defined, which is good
style if you read things from *directly* from the pillar, but doesn't make
much sense if you are simply important a pre-defined map. I would simply
remove the {% set redis ... %} as it doesn't add much.
Another thing I don't like about this formula is that it mixes things the user
genuinely wants to override and values that are, more or less, static such as
package and service names. The current implementation conflates these by
defining all of them in map.jinja and allowing the user to override them in
redis:lookup.
It would be, IMHO, advisable to keep these two things separate in the formula
and would therefore recommend to do the following:
* map.jinja redis should still define:
- home: /var/lib/redis
- user: redis
- port: 6379
- cfg_name: /etc/redis.conf
- pkg_name: redis
- svc_name: redis
These are values that are unlikely to change from one distribution to each
other and lend themselves to being, almost statically, defined in the lookup
map.
* Move the following elsewhere:
- svc_state: stopped
- version: 1.2.3
- bind: 0.0.0.0
- databases: 8
- snapshots:
These are all values users of the formula are likely to override or define
themselves and I would make that explicit by defining that in the "redis"
pillar (i.e. not "redis:lokup") directly.
Some people might say that one would *also* like to define default values for
these settings, but these should IMHO not be mixed in with the aforementioned
static data. There are two approaches to settings these default values that I
see frequently:
* Inline: salt['pillar.get']('redis:databases', 8)
* By using a macro to look up values:
{% from "redis/map.jinja" import defaults with context -%}
{%- macro get_config_item(item_name) -%}
{%- set default = defaults['config'].get(item_name, None) -%}
{%- salt['pillar.get']('memcached:%s' % (item_name), default) -%}
{%- endmacro -%}
This allows you to have *two* dictionaries in your map.jinja, one "redis" and
one "defaults". You will set distribution specific static data in the former
and allow the user to override those in redis:lookup and reserve the redis
pillar for things the user wants to define.
It happens way too frequently that the whole foo:lookup idiom is blindly
copied from other formulas without even making lookup explicit in
pillar.example or understanding why it is done that way.
--
Wolodja <
bab...@gmail.com>
4096R/CAF14EFC
081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC