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
6 votes
Accepted

Check a process is running with Salt Stack?

It's a bit hacky, but you can always do something like: check_process: cmd.run: name: ps aux | grep '[f]oobar' The exit code will be non-0 and the state will fail if foobar doesn't exist.
user avatar
  • 1,345
5 votes
Accepted

Using requisite injection to order states

This turns out to be a known issue: The require_in requisite does not support everything that require does, mainly id does not support sls or state_id without specifying a state module. So by ...
user avatar
  • 1,015
4 votes
Accepted

How to insert a minion Powershell variable into Salt Pillar or Mine?

You can only insert the return into the mine. Just specify the cmd.run (or possibly cmd.script) in your mine_functions and you will get the whole return back. If you want to have a script that sets ...
user avatar
  • 301
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
4 votes

Jenkins Groovy to parse console output and mark build failure

This question seems similar to another on StackOverflow, but seems to be a close, but not exact duplicate of https://stackoverflow.com/questions/37018509/jenkinsfile-build-log To quote those : ...
user avatar
  • 3,058
3 votes

What is a glob in salt-stack?

Globbing is a term used for matching file name patterns with wild cards. You can see a more detailed definition here https://searchsecurity.techtarget.com/definition/globbing As it relates to Salt ...
user avatar
  • 594
3 votes

Where are dunder dictionaries stored in salt?

There are currently 5 dunder dictionaries. They are available at runtime and generally not stored statically. __opts__ - Master or Minion configuration options; stored in configuration files of ...
user avatar
  • 66
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

Best method of retrieving environment information via Salt Stack?

SaltStack provides a method for modifying grains and adding additional information to the grains dictionary in several different ways by either setting them in the /etc/salt/minion config and/or ...
user avatar
  • 593
3 votes

Salt Stack Reporting - Executing commands based on environment

The answer is that you can't directly. You have to set a grain on the minions first by doing something similar to: salt '*' cmd.run 'grep environment /etc/salt/minion | awk "{print \"environment: \" \...
user avatar
  • 3,674
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
2 votes

Salt Stack environments ignoring saltenv

State and pillar environments are set independently. Specifing environment: prod in the minion configuration will force the minion to use the prod state, but it will still use the default pillar ...
user avatar
  • 3,674
2 votes

How can I share a (global) variable between salt states?

When I encountered a related problem, I wound up having Jinja run execute Salt modules. In my case, it was cmd.run to run mktmp (and, at the end of the template, rm for cleanup), with file.append and ...
user avatar
  • 1,015
2 votes

salt-stack: capture group for regex include_pat

A capture group is a type of backreference. Saltstack, being python based, uses the re.match object to do regular expression matching, which appears to support backreferences, so these backreferences ...
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

Ansible event driven capacity

I can't say that I've used SaltStack, but I have a good deal of experience with Ansible. The two are different approaches. Event based use is not hidden, it is just not there by itself. Ansible is ...
user avatar
  • 209
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

Why is IF failing with satl state file from Jenkins?

The jinja syntax error is caused by the {{ around your job var. Those curly braces are not required as you are already inside jinja block, noted by the {%. So to get your code working just replace ...
user avatar
  • 332
1 vote

How to assign saltstack pillar values from Jenkins comma separated input parameters?

You didn't say how the sls file is executed. One way would be to pass pillars on command line: salt '*' state.apply ftpsync pillar='{"ftpusername": "test", "ftppassword": "0ydyfww3giq8"}' Or you ...
user avatar
  • 253
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

SaltStack states pattern and replace for multiple files under directory and for multiple line matches

You should use Jinja to loop over a list of files and pattern/replacement pairs. {% set files = ['/a/foo.sh', '/b/bar.sh', '/b/baz.sh'] %} {% for file in files %} {% for p, r in [('/aaa/bbb', '/aaa/...
user avatar
  • 66
1 vote

Jenkins Groovy to parse console output and mark build failure

I solved this problem by following this answer on StackOverflow. You can use currentBuild.rawBuild.getLog(10) (the 10 specifies that you want the last 10 lines) to get the last few lines of the log ...
user avatar
1 vote

How to create AWS application load balancer using saltstack

Please follow official doc to create LB Please create a IAM role or mentioned secret and access key as below elb.keyid: HHTYHLSHDJFJFJFJFJFJFFSVJS elb.key: basjbsdfbdsfdsjfbkgbsfbdsjfbfdgdfgdfs ...
user avatar
1 vote

Why unable to find the exact path for grains storage in master?

These are built-in grains, which are collected at minion startup. Here's the code responsible for generating them. You cannot remove them, but you can overwrite them, for example to an empty value in ...
user avatar
  • 66
1 vote

saltstack: archive.extracted template jinja

There is no much choices regarding your situation, I see two of them : You ask your dev dpt to add your jinja templating to their builds (which may be hard or even impossible) You can use salt module ...
user avatar
  • 332
1 vote
Accepted

SaltStack Reactor fails with exception

I was able to find the root of issue. The problem was in the configuration of salt master. After every change of reactor config, I must run salt-call state.highstate command on master to sync reactor ...
user avatar
  • 593

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