hi all, a comment up front, I'm using salt 0.14.0-1. I want a pillar file providing a default value for 'all' and specific values for certain hosts, in the example below for the sshd_config file.
riet@ux0515 - none > cat ssh.sls
ssh:
MaxStartups:
all: '10'
ux0112: '50'
ux7080: '100'
PermitRootLogin:
all: 'no'
ux0936: 'yes'
state file
riet@ux0515 - none > cat test.sls
{% from 'lib.jinja' import attribute_val with context %}
/tmp/foobar:
file.managed:
- source: salt://fs/tmp/foobar
- template: jinja
- context:
MaxStartups: {{attribute_val('ssh', 'MaxStartups')}}
PermitRootLogin: {{attribute_val('ssh', 'PermitRootLogin')}}
template include
riet@ux0515 - none > cat lib.jinja
{%- macro attribute_val(key, attr) -%}
{%- if grains['id'] in pillar[key][attr] -%}
{{ salt['pillar.get'](key ~ ':' ~ attr ~ ':' ~ grains['id'], 'yes') }}
{%- else -%}
{{pillar[key][attr]['all']}}
{%- endif -%}
{%- endmacro %}
/tmp/foobar
riet@ux0515 - none > cat fs/tmp/foobar
First line
{%- if grains['id'] == 'ux0933' %}
Hallo ux0933
{%- endif %}
Hallo Hans
MaxStartups {{MaxStartups}}
PermitRootLogin {{PermitRootLogin}}
The problem I'm having, in the expanded /tmp/foobar file 'MaxStartups' does receive a number (10, 50 or 100 depending on hostname) but 'PermitRootLogin' ends up with values of 'True' and 'False', depending on whether the pillar data resolves to yes or no. The strange thing is, if I run the pillar module from the command line it works:
[root]# salt 'ux0936' pillar.get ssh:PermitUserEnvironment:ux7086
ux0936:
yes
[root]# salt 'ux0936' pillar.get ssh:PermitUserEnvironment:all
ux0936:
no