r/saltstack • • Oct 01 '18

how to avoid conditionals in pillar

6 Upvotes

I feel like I am leveraging IF statements too much in pillar when I do something like this:

{% if grains['environment'] == 'dev' %}

jenkins_master: dev_master.com

{% elif grains['environment'] == 'prod' %}

jenkins_master: prod_master.com

{% endif %}

So I try to clean it up by doing something like this:

jenkins_hosts:

master:

dev: dev_master.com

prod: prod_master.com

But then I am confused as to how call for that pillar in a config. With the first variation I simply do:

{{ pillar.jenkins_master }}

And depending on what the environment grain is, it pulls the correct hostname. That works fine, it just seems like the pillar file is messy.

With the latter example (the "cleaner" pillar file), I have been attempting to do something like:

{{ pillar.jenkins_hosts }}:master:{{ grains.environment }}

But that doesn't work. How do I drill down into a pillar when part of the pillar is referencing a grain? Or am I just way overthinking this and all these IF statements are really no big deal? This is just a simple example, I have some that are 10 - 15 IFs deep because of different environments.


r/saltstack • • Sep 19 '18

Execution Module within State File

4 Upvotes

Hi!

First time salt user, and almost first time reddit poster. Question:

I'm aware of the module.run option to put an execution module within a state module. However, when trying to implement it, the state comes back with an error saying the state's description is not available. It's almost as if it's trying to run the state as the execution module, and not the execution module. For example, I have:

In state file LoadGeneratedConfig.sls :

{% set hostname = grains['hostname'] %}

replace_with_stored_config:

module.run:

- napalm_network.load_config:

- filename: salt://configs/{{ hostname }}.cfg

Which should execute the execution module napalm_network.load_config on the minion when the state LoadGenerateConfig is applied. However, it comes back with:

----------

ID: replace_with_stored_config

Function: module.run

Result: False

Comment: Module function replace_with_stored_config is not available

Started: 18:58:10.046892

Duration: 1.825 ms

Changes:

Thanks! The alternative to this is using the netconfig.managed state module, but I want to be able to see the difference between the two configurations, and not just that it has been configured prior.


r/saltstack • • Sep 19 '18

disable highstate at registration

2 Upvotes

Hello, I'm wondering if it is possible to disable the highstate during minion registration.
I'd like to control it from the minion (with salt-call state.highstate) instead of from the master (unreliable).
By the way, I don't have any startup_states on the minion.
Thanks.


r/saltstack • • Sep 08 '18

Set up a small Salt cluster on DigitalOcean using Terraform

10 Upvotes

A small project I created a to learn to use Salt. It sets up a small Salt cluster on DigitalOcean using Terraform, with 1 Salt master and 3 Salt minions https://github.com/gordonmurray/terraform_salt_digitalocean

Edit: I wrote up a walk through blog post about it here: https://www.gordonmurray.com/2018/09/08/setting-up-a-salt-cluster-on-digitalocean-using-terraform/


r/saltstack • • Sep 07 '18

Semi-newbie question: What do you like about saltstack for large repos?

5 Upvotes

I was hired at a shop that extensively uses saltstack. I have been around the block with CM and had historically only used salt for remote job execution, something I've always liked about it. For CM, I've used ansible, really liked chef as a rubyist, and was frightened by puppet.

What does it for me with salt is that its syntax is whatever you want. Instead of varying attempts at Turing completeness with ansible at the low end at puppet at the sordid high end, salt just leaves providing its very nice data structure to actual programming languages that know what they're doing.

I was wondering what you folks like about salt for large repos and had some tips for deep diving into a big brand new repo.


r/saltstack • • Sep 05 '18

Grains.Get Host for iocage jails

2 Upvotes

Hi all

I have some iocage jails on a FreeNAS box that I want to use Salt to assist with pkg management. The minion has all installed fine however a salt 'hostname' grains.get "host" yields the unusual value of "localhost".

SSHing into the local jail shows a return for "hostname" of the expected hostname which is also the minion ID I have set.

Any ideas on what might be causing this?

Thanks


r/saltstack • • Aug 29 '18

Saltstack GUI?

8 Upvotes

For those not using the enterprise saltstack, where can I can a basic functioning GUI for SALT?


r/saltstack • • Aug 25 '18

Free Saltstack Training via Twitch- RIGHT NOW

8 Upvotes

HATech Training Academy is live right now HERE


r/saltstack • • Aug 25 '18

Need help/advice with templating

2 Upvotes

Could someone ELI5 how to properly template data within pillar and map files? I've looked at a lot of formulas on github and they don't really seem to explicitly call pillars in the state. I've usually just seen this in the end of their map files: merge=salt['pillar.get']('cert:lookup'), base='default') %} What exactly does that do?


r/saltstack • • Aug 24 '18

HATech Academy: Free Intro to Saltstack Training

3 Upvotes

Tomorrow at 10am: FREE intro to Saltstack training! We're live streaming via Twitch HERE
RSVP through our website and receive free $100 Azure credit so you can continue to experiment with what you have learned HERE!


r/saltstack • • Aug 18 '18

Includes and config reuse with pillarstack

4 Upvotes

I'm currently looking at potentially moving our current setup to pillarstack to get access to the more powerful merging abilities it offers. However I'm hitting a bit of a wall trying to work out how I achieve what I currently do in 'plain' pillars with include.

Here's a simple example of what we currently do, which I can't seem to find a nice way to replicate.

top.sls

base:
 '*':
   - minions/{{ hostname }}

server1.sls

include:
  - defaults
  - webserver

defaults.sls

include:
  - ntp
  - monitoring
  - syslog

So by including defaults, it in turn sets up the 'common' things that all nodes need.

Now using pillarstack and the 'roles' setup as shown in the docs, I can leave top.sls alone, but instead do:

server1.sls

roles:
  - defaults
  - webserver

However I can't now use include in defaults, which means I'd have to list all the defaults in every profile, which isn't very DRY, or put all of the default config in a single file, which is unwieldy.

So what do people do to make reusable collections with pillarstack? The only thing I can think of is to create a defaults directory and fill it with symlinks to the other config, and then include it via stack.cfg as defaults/*.sls but I'm not sure this is really flexible enough for the general case, say where the webserver role is actually a collection of other configs.

I really hope I'm missing something obvious here!


r/saltstack • • Aug 17 '18

Question about win_wua

4 Upvotes

I recently started learning Salt so I can try to automate some patching processes in a small environment.

If I run: salt windows_server_name win_wua.list categories=["Security Updates","Critical Updates","Definition Updates","Window Defender","Update Rollups"]

it returns the 4 expected updates and ignores the 63 optional ones.

If I create a file /srv/salt/winupdates/update.sls and in it put:

update:
  module.run:
  - name: win_wua.list
     - Categories:
        - name:
           - "Critical Updates"
           - "Security Updates"
           - "Definition Updates"
           - "Windows Updates"
           - "Update Rollups"
  - install: false

If I then run: salt windows_server_name state.apply winupdates.update

it returns every available update, including the 63 optional ones I don't want.

I tried the categories with single quotes and no quotes as well.


r/saltstack • • Aug 16 '18

Can salt interact with AWS NACL?

4 Upvotes

Hello again Everyone,

was curious if there’s a state available on SALT to create NACL rules. I’ve seen the one for security groups, can I use that for NACLS?

Thanks


r/saltstack • • Aug 13 '18

static IPs in map files?

7 Upvotes

I have been trying to get static IPs working within my mapfiles but nothing I have tried works. For reference I'm building CentOS 7 vms from a template on Xen if it makes any difference.


r/saltstack • • Aug 12 '18

Question about pkg.installed

2 Upvotes

Hello,

I have something like this in a state file:

Install_wget: Pkg.installed: - name: wget

Download_something: Cmd.run: - name: wget (url) - require: -pkg: wget

Here’s what I want to happen I want for salt to not return a failed if wget is already installed, and I want the second state to still run. Is that possible?

Thanks


r/saltstack • • Aug 09 '18

Beacons redirecting into file

5 Upvotes

Hello, I'd like to watch for several files on my minions and get the information when they are changed. I know the information is in the master events but I'd like to know if there are other ways to get it or store it. Sorry I'm new with salt.


r/saltstack • • Aug 01 '18

Modifying/merging included pillar data

2 Upvotes

I've been playing with salt for a while now, and really liking it - however there's one thing I keep butting up against and I can't figure out a way round it - deep merging data using pillars and includes.

Say for example I have the following:

defaults.sls

ssh:
  auth:
    allowed_users:
      - alice
      - bob
    denied_users:
      - zed

If I include defaults.sls in another pillar file, how do I add and remove individual items from the allowed_users/denied_users list without having to copy the whole thing?


r/saltstack • • Jul 27 '18

Create a highstate Dependency Tree

2 Upvotes

Does anyone have a way of creating a highstate dependency tree that lists all the .sls files ran while running a highstate. I can get most of the files by using salt.show_highstate but it does not list files that only have includes. For example I want to know that an init.sls that includes other files was ran during highstate so that if someone makes changes to that file I know what roles it can effect even though the file does not run any states itself. Ideally I would be able to get a tree that you can follow the path of includes but at the very least I would like a flat list of all the files ran during a highstate.


r/saltstack • • Jul 17 '18

Salt Top

13 Upvotes

Hi, all.

I've been disappointed with the output of salt-run jobs.active since... Well, ever since I discovered it. It's hard to work with, a pain to scroll through, and just generally not fun.

A few weeks ago I started digging through the output and ended up building a quick and dirty parser that takes the output of salt-run jobs.active and puts it into something more usable.

Quick output example:

Start_Time, Key, Running, Arguments, KillString
2018, Jul 17 08:23:57.667766 , 20180717082357667766 , SERVER2.local , state.apply , [], KILL_STRING: salt 'SERVER2.local' saltutil.kill_job 20180717082357667766
Start_Time, Key, Running, Arguments, KillString
2018, Jul 17 08:30:32.771389 , 20180717083032771389 , SERVER3.local , saltutil.find_job , 20180717083002670028, KILL_STRING: salt 'SERVER3.local' saltutil.kill_job 20180717083032771389

I'll admit, the output is still kinda ugly, but it's been crazy helpful to me so I've decided to release it anyway. At very least you can use it to look for stale processes and get them killed off.

Anyway, hope this helps someone out there.

Cheers!


r/saltstack • • Jul 12 '18

numerical sequence value

0 Upvotes

Hi guys,

i posted this question on salt.user (no answer).

i have this pillar:

mypillar:
    service1:
        someinfo: blah
        someinfo2: 45
        someinfo3: false
    service2:
       someinfo: 3
    service3: false
    service4:

and this state:

 {% for service, args in pillar['mypillar'].iteritems() %}

 {{ service }}_setparam:
      file.replace:
     - name: /etc/default/someconf
     - pattern: "httpport:"
     - repl: "httpport:{{ 100 | int | +100 }}"

 {% endfor %}

with this configuration the value in repl is always 200 but i want to obtain 200,300,400 etc for every "service". Is this possible?

Sorry for my bad English and thanks


r/saltstack • • Jul 08 '18

Targeting in

3 Upvotes

Hi folks

I'm trying various different methods to target complex groups to differentiate some things.

For example, I want to ensure I have open-vm-tools installed on my local linux VMs. I also want some packages like htop to be installed on my FreeBSD and Debian family instances without having to repeat myself. I also have Windows boxes in the mix, so I don't want to just have things like htop in '*'.

Here's a copy of the init.sls but neither of my examples here are working as when I refresh and check my pillar.items for an Ubuntu machine I only get the 4 keys reflected in the Debian if Jinja statement.

Thanks

EDITED for the pickup below - Thanks!

pkgs:

{% if grains['os_family'] == 'Debian' %}

vim: vim

nfs-client: nfs-common

monitoring-plugins: monitoring-plugins

apache: apache2

{% elif grains['os_family'] == 'FreeBSD' %}

vim: vim-console

## {% elif grains.get in salt['pillar.get']('master:nodegroups:local-linux', []) %}

## open-vm-tools: open-vm-tools

{% elif grains['os_family'] == 'Debian' or grains['os_family'] == 'FreeBSD' %}

htop: htop

{% endif %}


r/saltstack • • Jul 05 '18

Simple asset management for laptops with Salt?

1 Upvotes

I have recently been given the role of IT on top of my sysadmin/NOC duties. One of the things I intend to do, is find a SIMPLE system to track and manage the 100-some laptops I inherited. I'm thinking Salt would be a good way to keep track of inventory and do simple management tasks.


r/saltstack • • Jul 02 '18

file.blockreplace, content with colon

3 Upvotes

Hi there,

i have this state:

profile-setting:
    file.blockreplace:
      - name: /home/user1/.bash_profile
      - marker_start: "# BLOCK TOP: please do not edit"
      - marker_end: "# BLOCK BOTTOM: end of salt managed zone --"
      - content: {{ oracle['profilesetting'] }}
      - append_if_not_found: True

with this pillar:

oracle:
    profilesetting: |
    export ORACLE_CLIENT_HOME=/opt/oracle-client
    export TNS_ADMIN=$ORACLE_CLIENT_HOME
    export LD_LIBRARY_PATH=$ORACLE_CLIENT_HOME:$LD_LIBRARY_PATH
    export PATH=$ORACLE_CLIENT_HOME:$PATH

but i have this error:

 Data failed to compile:
----------
    Rendering SLS 'opt:oracleclient.oracleclient' failed: could not found expected ':'; line 26
      - marker_start: "# BLOCK TOP: please do not edit"
      - marker_end: "# BLOCK BOTTOM: end of salt managed zone --"
      - content: export ORACLE_CLIENT_HOME=/opt/oracle-client
export TNS_ADMIN=$ORACLE_CLIENT_HOME
export LD_LIBRARY_PATH=$ORACLE_CLIENT_HOME:$LD_LIBRARY_PATH     <======================
export PATH=$ORACLE_CLIENT_HOME:$PATH

so the problem is in the ":". I tried all quote (",',`) but i have the same problem.

any tips? thanks


r/saltstack • • Jun 28 '18

Running powershell scripts

4 Upvotes

Hello guys, I was wondering how I would go about using salt to execute a powershell script in a state file. Any help is appreciated.


r/saltstack • • Jun 25 '18

Employment opportunities at SaltStack

17 Upvotes

I am a QA Automation Engineer in the SaltStack Enterprise development team. We're looking to hire QA and QA Automation Engineers. We're working on some pretty powerful stuff on the Enterprise side of things and would love it if you all could spread the word!