Skip to content

Instantly share code, notes, and snippets.

@yanatan16
Last active January 11, 2020 22:54
Show Gist options
  • Save yanatan16/6d1ed08b5aacc9b5690f to your computer and use it in GitHub Desktop.
Save yanatan16/6d1ed08b5aacc9b5690f to your computer and use it in GitHub Desktop.
Making Clean and Reusable Salt States Lessons - Jinja Imports
{%- from 'macros.jinja' import mongocfg with context -%}
{
"mongo": {{mongocfg_json()}}
}
{% from 'global_vars.jinja' import dev, env with context %}
# Do stuff with global vars
{% set pillarget = salt['pillar.get'] %}
{% set mineget = salt['mine.get'] %}
{% set dev = pillarget('dev', False) %}
{% set env = 'staging' if 'staging' in grains['id'] else 'production' %}
{% set ip_addresses = mineget('network.ipaddrs', '*.%s.domain.tld' % env) %}
{% set mongo = pillarget('mongo', {}) %}
{% from 'global_vars.jinja' import mongo with context %}
{% macro mongocfg_json() %}
{
"host": "{{mongo.get('host', 'localhost')}}",
"port": {{mongo.get('port', 6379)}},
"db": "{{mongo.get('db', 'test'}}"
}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment