Hot answers tagged

14 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 ...
gtmanfred's user avatar
  • 311
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 ...
Michael Mol's user avatar
  • 1,045
7 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-zero and the state will fail if foobar doesn't exist.
user2640621's user avatar
  • 1,395
5 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 : ...
Bruce Becker's user avatar
  • 3,570
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 ...
Michael Mol's user avatar
  • 1,045
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 ...
gtmanfred's user avatar
  • 311
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 ...
Michael Mol's user avatar
  • 1,045
4 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 ...
kenlukas's user avatar
  • 664
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 ...
A. Z.'s user avatar
  • 76
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-...
user2640621's user avatar
  • 1,395
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 ...
brousch's 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 ...
user54's 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: \" \...
James Shewey's user avatar
  • 3,724
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 ...
Michael Mol's user avatar
  • 1,045
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 ...
James Shewey's user avatar
  • 3,724
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 ...
Michael Mol's user avatar
  • 1,045
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 (...
jto's user avatar
  • 378
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 ...
James Shewey's user avatar
  • 3,724
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 ...
Arcege's user avatar
  • 209
2 votes

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 ...
A. Z.'s user avatar
  • 76
2 votes

Ansible event driven capacity

There's a new Ansible Event-Driven automation. It constantly listens to triggers from variety of sources such as - Altertmanager, Kafka clients etc. Official Site - https://www.ansible.com/use-cases/...
Kenny's user avatar
  • 21
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' ...
James Shewey's user avatar
  • 3,724
2 votes
Accepted

Set umask for an individual salt state

Edit update April 3rd 2023: As of salt 3006 (https://salt.tips/whats-new-in-salt-sulfur/#umask) umask is now a global state argument and can be specified on any state. Original work around for pre ...
bdrx's user avatar
  • 141
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 ...
Pier's user avatar
  • 344
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 ...
Pier's user avatar
  • 344
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 ...
bgdnlp's 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 {%- ...
James Shewey's user avatar
  • 3,724
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 ...
darnold0714's 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/...
A. Z.'s user avatar
  • 76
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 ...
Fearnbuster's user avatar

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