We have two different environments, dev and production, managed by a single Salt server. Something like this:
base:
'dev-*':
- users-dev
'prod-*':
- users-prod
user-dev
and users-prod
states are pretty much the same, like this:
{% for user, data in pillar['users-dev'].items() %}
{{ user }}-user:
user.present:
< ...something... >
{{ user }}_ssh_auth:
ssh_auth.present:
< ...something... >
{% endfor %}
We did not want to duplicate the code so our initial idea was to do something like this:
{% users = pillar['users'].items() %}
include:
- users-common
and then to refer to users
in users-common
, but this did not work because the proper Jinja syntax was set users = pillar['users'].items()
and this was not intended to work across Salt states includes.
So, the question is how to do it properly?
All jinja is evaluated before any of the states (including the include
statements) are evaluated.
However, I would think you would just be able to refer directly to pillar['users'].items()
inside of users-common
. Is it not allowing you to access pillar from within that state?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With