Last active
August 29, 2015 14:21
-
-
Save bradthurber/cd9c3bd647711940e2ed to your computer and use it in GitHub Desktop.
Reference jinja var in jinja for salt mine string
This file contains hidden or 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
## | |
## Using the mine data, we are trying to find the IP address of all servers | |
## with roles: mod-cluster-node in the same environment as this minion. | |
## | |
# EXAMPLE A: THIS WORKS - but we are hard-coding the minion's environemt (development). We don't want to hard-code | |
{%- for server, addrs in salt['mine.get']('G@roles:mod-cluster-node and G@environment:development', 'network.ip_addrs', expr_form='compound').items() %} | |
# ... do stuff... | |
{%- endfor %} | |
# get this minion's environment (examples: development, test, stage, production) | |
# Used for the following examples | |
{% set minion_environment = grains['environment'] %} | |
# EXAMPLE B: THIS DOESN'T WORK - how can I reference var "minion_environment" value here? | |
{%- for server, addrs in salt['mine.get']('G@roles:mod-cluster-node and G@environment:{{ minion_environment }}', 'network.ip_addrs', expr_form='compound').items() %} | |
# ... do stuff... | |
{%- endfor %} | |
# EXAMPLE C: Doesn't work either | |
{%- for server, addrs in salt['mine.get']('G@roles:mod-cluster-node and G@environment:minion_environment', 'network.ip_addrs', expr_form='compound').items() %} | |
# ... do stuff... | |
{%- endfor %} | |
# EXAMPLE D: - now we're talkin'! | |
{%- for server, addrs in salt['mine.get']('G@roles:mod-cluster-node and G@environment:'~minion_environment, 'network.ip_addrs', expr_form='compound').items() %} | |
{%- for addr in addrs %} | |
Allow from {{ addr }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment