Hot answers tagged

14 votes

How to examine Jinja output in Saltstack?

Given how much time I spent weeks ago struggling with a closely-related issue, I wish I'd figured this out sooner. The solution appears to be to use salt.modules.cp.get_template to have the Salt ...
user avatar
  • 1,015
13 votes
Accepted

How to examine Jinja output in Saltstack?

Check out the slsutil.renderer module. This should do what you want salt my-minion-id slsutil.renderer /srv/salt/network/init.sls 'jinja' This module just calls the compile_template function ...
user avatar
  • 301
7 votes
Accepted

Is it possible to combine jinja templates in ansible like this is possible with erbs in puppet?

Yes, that is possible according to this post. When a second jinja template was created and this was included in the base jinja it was called. {% include "checks/subdue.j2" %}
user avatar
  • 12.6k
4 votes
Accepted

Constructing Dependencies from a Pillar in Saltstack

This templated SLS file works splendidly: {% if 'components' in salt.pillar.items() %} include: {% for component in salt.pillar.get('components').keys() %} - {{ component }} {% endfor %} {% endif ...
user avatar
  • 1,015
3 votes
Accepted

Is it possible to use multiple if statements in a salt state?

You can have more than if statement per state. The issue is that your conditional doesn't seem actually be checking the hostname, it's just passing everything. Try this: {% if grains['host'] in ['dev-...
user avatar
  • 1,345
3 votes

Constructing Dependencies from a Pillar in Saltstack

You can also do it like: {% if pillar['components'] is defined %} include: {% for component in pillar['components'] %} - {{ component }} {% endfor %} {% endif %} {% if pillar['components'] is ...
user avatar
  • 131
3 votes
Accepted

Securely grab minion ID in pillar top file template?

There is currently one safe way to do this. You can use {{opts.id}} as an explicit way to grab the minion ID. opts is technically an implementation detail; the opts dictionary is a Salt internal ...
user avatar
  • 1,015
3 votes

Ansible Jinja template if statement

The syntax failures are caused by the presence of the {{...}} expression blocks (normally used for filling the template output with the corresponding content) inside the {%...%} statement blocks. I ...
user avatar
2 votes

Compare Strings to get Unique values in Jinja2

Yes, this can be done. The following should do the trick: "{%- for ip, az in seed.iteritems() %} {%- if 'us-east-1a' in az %} {%- if firstloop is not defined %} {%- set firstloop = 1 %} {{-...
user avatar
  • 3,674
2 votes
Accepted

Salt State is running against all servers except one, why?

I have found the answer to my own question after some more investigation. The reason the state was skipping the contents of my if statement was because the hostname of the server was in lower-case (...
user avatar
  • 368
2 votes

How do I get the hosts from a specific section of an Ansible `hosts` file in a Jinja2 Template

The magic you need is magic variables, in particular the groups variable, which is a dictionary/map with all the groups in inventory and each group has the list of hosts that belong to it. Then ...
user avatar
2 votes
Accepted

ansible & jinja2: How to reference JSON structure items whose keys are variables?

Don't nest moustaches. Once you're in a Jinja context, you should reference variables by name without any further delimiters. Using standard attribute access syntax can be a lot easier to read than ...
user avatar
2 votes

Jinja syntax error: missing endif, in spite of providing it

There is no error in what you have posted here. The error lies elsewhere in your code which you did not include in the OP. Using the Jinja live parser, when pasting in: {% if spade.corename == 'FI' ...
user avatar
  • 3,674
1 vote
Accepted

How to downgrade Jinja for Ansible?

Since Ansible was installed via Homebrew on macOS, the workaround is to install Ansible using Pip. $ brew remove ansible $ pip3 install ansible $ pip3 list | grep -e ansible -e Jinja2 ansible 2....
user avatar
  • 7,121
1 vote

Ansible playbook fails with: no test named 'success'

You use pretty old ansible, maybe worth to try a new one. Although tests "succeeded" and "success" should be in 2.2 too. But main problem I think it's failed_when: no in your task. It makes test when:...
user avatar
1 vote

Saltstack Jinja template pillar merge

The "saltey" way of doing this is typically in a map.jinja file. This one for example... In that, you would: {%- load_yaml as serverlist %} #Note that a default list could be provided here {%- ...
user avatar
  • 3,674
1 vote

How to add multiple jvm options in a saltstack jinja?

Perhaps a macro might be what you are looking for. Understanding Jinja:Macros In the lib.sls example in the link (pasted below), it sets a value contingent on the value of the if statement. I think ...
user avatar
1 vote

Configuring Zookeeper from Ansible

In lack of a better idea I chose this rather long approach: myid.j2 {% for host in groups['zookeeper'] %} {% if host == inventory_hostname %} {{ loop.index }} {% endif %} {% endfor %} The idea is ...
user avatar
  • 163

Only top scored, non community-wiki answers of a minimum length are eligible