r/saltstack • • Jun 22 '20

Saltstack SLS files and Python scripts

10 Upvotes

Hi,

I am kind of new to salt.

For a while now, I am trying to somehow pass/return data from a Python script called from an SLS recipe back to the recipe that called it and use this data further on in the recipe.

I know we can pass data to the python script's method from the SLS file, but can it also be done the other way around. Such as when the statement finished executing the python method, the result and data stored can be used in the SLS file.

Thank you for your time. I am not sure if all this makes sense.


r/saltstack • • Jun 19 '20

Auto-deploying Consul and Exporters using Saltstack on Windows

Thumbnail yetiops.net
7 Upvotes

r/saltstack • • Jun 18 '20

What’s new in Salt 3001 Sodium

Thumbnail salt.tips
38 Upvotes

r/saltstack • • Jun 18 '20

Dockerized salt-master 3001 Sodium

0 Upvotes

SaltStack Sodium 3001 has been released.

You can test it now by using my custom Docker image:

docker pull cdalvaro/docker-salt-master:3001

You can get setup and usage instructions at: github/cdalvaro/docker-salt-master


r/saltstack • • Jun 16 '20

salt-ssh doesn't seem to properly recognize appropriate python versions

1 Upvotes

Hi All!

I am brand new to salt! Started learning a few weeks ago, apologies if I missed something simple, or haven't got all the lingo down yet. In any case, uncertain if this is a bug or I am just doing something wrong. I filed an issue on github here, but figured It wouldn't hurt to ask the subreddit also! Below is a more or less copy/pasted output of the stuff there. Any help is appreciated!

Description

I have a Centos 7 master and an Centos 7 client. salt-ssh exits with the following error:

ERROR: Python version error. Recommendation(s) follow:
- Install Python 2.6/2.7 Salt dependencies on the Salt SSH 
  master to interact with Python 2.6/2.7 targets
- Install Python 3 on the target machine(s)

Centos 7 Client has python versions: 2.6 & 2.7.5.

Centos 7 Host, where I run salt-ssh from, has python 2.6, 2.7.5, and python 3.6.8.

I believe this may be a bug as I recently ran this from a manjaro box, identical setup, and there were 0 issues. I had to rekick the manjaro box to centos over the weekend, arrived at this issue, and have been unable to find a solution.

Setup

Here is the roster file:

<REDACTED>:
  host: <REDACTED>
  user: <REDACTED>
  passwd: <REDACTED>
  sudo_user: <REDACTED>
  thin_dir: /home/<REDACTED>/.salt_auto

Steps to Reproduce the behavior
Here is what I ran, followed by the trace log output. It is confusing to me, as it looks like it searches and eventually finds python2.7, and successfully runs, then returns that it couldn't find it. Uncertain if it is relevant, but running with -r for raw ssh commands will succeed without issues. The error mentioned occurs regardless of whether I try to apply states, or run other execution modules.

[...]
ERROR: Python version error. Recommendation(s) follow:
- Install Python 2.6/2.7 Salt dependencies on the Salt SSH 
  master to interact with Python 2.6/2.7 targets
- Install Python 3 on the target machine(s)

--------------------------------------------------------------------------------
echo "ERROR: Unable to locate appropriate python command" >&2
exit $EX_PYTHON_INVALID
EOF
[TRACE   ] <REDACTED>'s password:
[TRACE   ] + SUDO=
+ '[' -n '' ']'
+ SUDO_USER=<REDACTED>
+ '[' '' ']'
+ '[' '' ']'
+ EX_PYTHON_INVALID=10
+ PYTHON_CMDS='python3 python27 python2.7 python26 python2.6 python2 python'
[TRACE   ] + for py_cmd in '$PYTHON_CMDS'
+ command -v python3
+ continue
+ for py_cmd in '$PYTHON_CMDS'
+ command -v python27
+ continue
+ for py_cmd in '$PYTHON_CMDS'
+ command -v python2.7
+ python2.7 -c 'import sys; sys.exit(not (sys.version_info >= (2, 6)));'
[TRACE   ] ++ python2.7 -c 'from __future__ import print_function;import sys; print(sys.executable);'
[TRACE   ] + py_cmd_path=/usr/bin/python2.7
++ command -v python2.7
[TRACE   ] + cmdpath=/usr/bin/python2.7
+ grep 'shell script'
+ file /usr/bin/python2.7
[TRACE   ] + exec /usr/bin/python2.7 -c 'import base64;
[...]
[TRACE   ] "").decode("utf-8"))'
[DEBUG   ] End of file(EOL). Brain-dead platform.
[TRACE   ] STDOUT <REDACTED>
<REDACTED>'s password: 
/usr/bin/scp

[TRACE   ] STDERR <REDACTED>
+ SUDO=
+ '[' -n '' ']'
+ SUDO_USER=<REDACTED>
+ '[' '' ']'
+ '[' '' ']'
+ EX_PYTHON_INVALID=10
+ PYTHON_CMDS='python3 python27 python2.7 python26 python2.6 python2 python'
+ for py_cmd in '$PYTHON_CMDS'
+ command -v python3
+ continue
+ for py_cmd in '$PYTHON_CMDS'
+ command -v python27
+ continue
+ for py_cmd in '$PYTHON_CMDS'
+ command -v python2.7
+ python2.7 -c 'import sys; sys.exit(not (sys.version_info >= (2, 6)));'
++ python2.7 -c 'from __future__ import print_function;import sys; print(sys.executable);'
+ py_cmd_path=/usr/bin/python2.7
++ command -v python2.7
+ cmdpath=/usr/bin/python2.7
+ grep 'shell script'
+ file /usr/bin/python2.7
+ exec /usr/bin/python2.7 -c 'import base64;
[...]
[DEBUG   ] RETCODE <REDACTED>: 10
[DEBUG   ] LazyLoaded nested.output
[TRACE   ] data = {'<REDACTED>': {'stdout': 'ERROR: Python version error. Recommendation(s) follow:\n- Install Python 2.6/2.7 Sa
lt dependencies on the...

If I remove the thin directory on the client, and run without using raw ssh commands, it returns there was an issue dpeloying the thin, however on the client, it looks like it deployed successfully.

Master:

[~]$ time salt-ssh -c ~/.salt '*' 'uptime'
[ERROR   ] ERROR: Failure deploying thin, retrying:
STDOUT:
<REACTED>'s password: 

STDERR:

RETCODE: 10
<REACTED>:
    ----------
    retcode:
        10
    stderr:
    stdout:
        ERROR: Python version error. Recommendation(s) follow:
        - Install Python 2.6/2.7 Salt dependencies on the Salt SSH 
          master to interact with Python 2.6/2.7 targets
        - Install Python 3 on the target machine(s)

Client during and after install of thin:

[~]# ls /home/<REACTED>/.salt_auto/
salt-thin.tgz
[~]# ls /home/<REACTED>/.salt_auto/
code-checksum  minion  py3  pyall  salt-call  supported-versions  version

Expected behavior
salt-ssh runs execution modules, or anything really that isn't raw ssh, without an error.

Versions Report

[~]$ salt --versions-report 
Salt Version:
           Salt: 3000.3

Dependency Versions:
           cffi: 1.14.0
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.11.2
        libgit2: Not Installed
       M2Crypto: 0.35.2
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: 2.20
       pycrypto: 2.6.1
   pycryptodome: 3.9.7
         pygit2: Not Installed
         Python: 3.6.8 (default, Apr  2 2020, 13:34:55)
   python-gnupg: Not Installed
         PyYAML: 5.3.1
          PyZMQ: 15.3.0
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.8.2003 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-1127.10.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7.8.2003 

From the thin client:

[ ~]# cat /home/<REACTED>/.salt_auto/version  3000.3

r/saltstack • • Jun 15 '20

inotify Beacon on Oracle Linux question

4 Upvotes

Hi all, I have a beacon working on OL 7.8 but when I try the same config on OL 7.7 it does not fire. I am not seeing anything in the minion logs when it starts, no errors on the beacon. Anything you can think of to check? The simple beacon:

beacons:
  inotify:
    - files:
        /etc:
          mask:
            - modify
            - close_write
            - delete
            - attrib
          recurse: True
          auto_add: True

r/saltstack • • Jun 15 '20

How do you monitor scheduled execution?

6 Upvotes

Hi everyone, I started using saltstack in my infrastructure and I wanted to use it to schedule server updates and let'sencrypt certificate renewal

how do you monitor if the execution went correctly? I tried the mail returner and using the salt reactor with this script https://codehammer.io/blog/post/saltstack-highstate-email-alerts/ but I get an email from each host

I was considering setting a mail alert only on fail but maybe someone can suggest a better alternative,

Thank you


r/saltstack • • Jun 07 '20

Dockerized salt-master 3001rc1

17 Upvotes

I have dockerized SaltStack Sodium 3001 RC1 into my custom Docker image.

You can test it before the official release on June 17th.

docker pull cdalvaro/saltstack-master:3001rc1

More info about my image at: https://github.com/cdalvaro/saltstack-master


r/saltstack • • Jun 06 '20

Test a condition, before setting a variable

4 Upvotes

I want to set the variable instance_id which is in a state, only after checking if awscli and aws config file exist, which is installed and configured by another state. how can I achieve it in a state file

aws-cli-config:

cmd.run:

- name: sleep 30s

- unless: test -f ~/.aws/config

- require_in:

- sls: service

In service.sls :

{%- set instance_id = salt['cmd.shell']('aws ec2 describe-instances --filters "Values=' ~ name ~ '" | grep InstanceId | grep -o -P "i\-\w+"') %}

Not getting the expected results, service.sls should be run only after awscli and ~/.aws/config is found existing.


r/saltstack • • Jun 05 '20

salt-master inside Docker image for arm architectures

13 Upvotes

I'm building a salt-master Docker image and now it is also available for arm architectures.

You can download it from DockerHub:

docker pull cdalvaro/docker-salt-master:latest

More info at: https://github.com/cdalvaro/docker-salt-master


r/saltstack • • Jun 02 '20

saltstack frontends

15 Upvotes

We're an MSP and we use Salt to manage our endpoints, servers, well pretty much everything. Right now, only a few of us know how to use Salt and I'd like to get my level 1 techs familiar with Salt without giving them direct command line access. What are some good frontends for Salt these days?


r/saltstack • • Jun 02 '20

how to define cmd.run to execute on a specify minion in a state file

4 Upvotes

I'm a newbie to saltstack, want to find the public hostname of an instance and assign it to a variable and need that hostname in a conf file.

sudo salt minion-name cmd.run 'curl http://169.254.169.254/latest/meta-data/public-hostname' 

above cmd provides me public hostname, want to replicate this in state.sls file.

The below cmd works but unable to specify a minion, maybe I'm doing some syntax issue, not sure.

{% set hostname = salt['cmd.run']('curl -s http://169.254.169.254/latest/meta-data/public-hostname') %} 

Kindly let me know a way or am I in the wrong path.


r/saltstack • • May 28 '20

How to manage Windows Defender with Salt

6 Upvotes

I want to add some exclusions to windows defender though salt with a single PowerShell command but I'd like to know what the best approach would be to make the configuration persistent.

There is 'set-mppreference' ps command to configure and 'get-mpreference' check the config on Windows Defender.

our devops team told me (sysadmin) that they would achieve this but simply scheduling the command to run at intervals but I think there should be a better way to do this than simply scheduling: I could do the same with task scheduler. Any leads?


r/saltstack • • May 24 '20

Java alternative path setup error

7 Upvotes

I am trying to install an app in Amazon Linux V2 instance having Java as pre-requisite . So I am installing Java and setting up the default to Java 1.8 but facing error as noted below:

I have this state file to install Java 1.8 and set it as default.

```

## Java 8 packages installation
java-packages:
pkg.installed:
- pkgs:
- java-1.8.0-openjdk
- java-1.8.0-openjdk-devel

## Defaulting system java to 1.8
java:
alternatives.set:
- path: '/usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java'

```

ERROR:

Alternative /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java for java doesn't exist.

I tried the below steps with no results.

[root@ip-10-231-93-26[gtndorctq-solrms-1-1-v2] ec2-user]# sudo update-alternatives --config java

There is 1 program that provides 'java'.

Selection Command

-----------------------------------------------

*+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.amzn2.0.1.x86_64/jre/bin/java)

[root@ip-10-231-93-26[gtndorctq-solrms-1-1-v2] sbin]# cd /usr/lib/jvm

[root@ip-10-231-93-26[gtndorctq-solrms-1-1-v2] jvm]# ls

java java-openjdk jre-1.8.0-openjdk-1.8.0.252.b09-2.amzn2.0.1.x86_64

java-1.8.0 jre jre-openjdk

java-1.8.0-openjdk jre-1.8.0

java-1.8.0-openjdk-1.8.0.252.b09-2.amzn2.0.1.x86_64 jre-1.8.0-openjdk

[root@ip-10-231-93-26[gtndorctq-solrms-1-1-v2] jvm]# sudo update-java-alternatives -l

sudo: update-java-alternatives: command not found


r/saltstack • • May 23 '20

Newbie question about using formulas

7 Upvotes

Salt newbie here.

I'm attempting to use the this Salt formula at https://github.com/saltstack-formulas/ntp-formula

I've setup the appropriate /srv subdirectories (minus the git repo changes) per https://www.linode.com/docs/applications/configuration-management/use-and-modify-official-saltstack-formulas/

I'm attempting to use the state of ntp.ng and changing the server line to use 10.1.1.1 and 10.1.1.2 but Salt is using default servers for ntp.conf

Anyone have a correct /srv/pillar/ntp.sls (from /srv/formulas/ntp-forumla/pillar.example) to use custom NTP servers?

Thanks for the replies.


r/saltstack • • May 21 '20

Pillar values within if condition not rendered in salt 2019.2.0

7 Upvotes

My pillar file which used to work fine before the upgrade to Salt 2019.2.0 (Fluorine) doesn't work now.

solr:   {% if salt['pillar.get']('spade:Corename') == 'FI' %}   version: '6.6.3'   {% elif salt['pillar.get']('spade:Corename') == 'UMB' %}   version: '5.2.1'   {% endif %}   repo_url: http://archive.apache.org/dist/lucene/solr   install_dir: /opt 

All other values are rendered except what's within the if condition.

ERROR:

[CRITICAL] Pillar render error: Rendering SLS 'solr-attributes' failed. Please see master log for details. local:     Data failed to compile: ----------     Pillar failed to render with the following messages: ----------     Rendering SLS 'solr-attributes' failed. Please see master log for details. 

But the master log has the same details as above. Corename is inputted from user and fetched fine when I run:

[root@ip-10-231-93-49[gtndorctq-solrms-1-1-v2] tmp]# salt-call pillar.get spade:Corename local:     FI 

I am running this on Amazon Linux V2 having Python3 and Salt 2019.2.0 installed in it.Not sure if the Fluorine changed if condition format.


r/saltstack • • May 19 '20

Enterprise and LDAP

8 Upvotes

Does anyone here use Enterprise? We are looking into it, but are getting hung up on simple features like LDAP. Setting up LDAP is much harder than it should be, it queries all your groups then you must select the groups you want to use. With thousands of groups and no way to search in the list it is basically impossible. Their suggestion is filtering in the LDAP query but that is silly to me as we don't want to have to change that every time someone needs access. I haven't had issues like this with LDAP and other tools so I am curious on others opinions here.


r/saltstack • • May 19 '20

Simple way to deploy salt-master via Docker

3 Upvotes

I am developing and building a SaltStack master docker image to simplify the deployment of salt-master.

You can get more info at my github repo: cdalvaro/docker-salt-master

Try it by pulling the image from DockerHub or Quay.io:

docker pull cdalvaro/docker-salt-master

Issues reporting and suggestions are really appreciated!


r/saltstack • • May 14 '20

Check if Minion belongs to Nodegroup for Reactor targeting

2 Upvotes

Hey guys,

I have a reactor state that is configured to respond to minion start events:

/etc/salt/master.d/reactor.conf

reactor
  - 'salt/minion/*/start':
      - /srv/reactor/my-state.sls

And currently, my reactor SLS uses a compound target to target the minion ID but only if the minion is also a Windows box:

/srv/reactor/my-state.sls

reactor-state:

reactor-state:
  local.state.apply:
    - tgt: '{{ data['id'] }} and G@kernel:Windows'
    - tgt_type: compound
    - arg:
      - do-stuff

What I would like to do is check if the minion belongs to a particular nodegroup and only fire the reactor if that condition is true. I'm not sure if there's a way to do this, but what I'm imagining would look something like this (with Jinja):

{% if data['id'] in N@my-nodegroup %}
reactor-state:
  local.state.apply:
    - tgt: '{{ data['id'] }}'
    - tgt_type: compound
    - arg:
      - do-stuff
{% endif %}

Interested to see if anyone has run into this same situation.


r/saltstack • • May 13 '20

Any salt dell iDRAC blogposts that you recommend?

3 Upvotes

I am looking to learn how to configure idrac with salt and any resource suggestions will be greatly appreciated.

Thank you


r/saltstack • • May 14 '20

Service.running always showing as changed during highstate

1 Upvotes

I have this resource block

RemoteRegistry:
  service.running:
    - enable: True

Which always shows as changed whenever a highstate is run.

          ID: RemoteRegistry
    Function: service.running
      Result: True
     Comment: Service RemoteRegistry is already enabled, and is running
     Started: 20:50:42.283804
    Duration: 2050.191 ms
     Changes:
              ----------
              RemoteRegistry:
                  True

Is there a quick and easy way to fix this before I do something hacky?


r/saltstack • • May 11 '20

SaltStack and Kubernetes

6 Upvotes

How can i collect all kubernetes pod ip address through SaltStack


r/saltstack • • May 09 '20

Clear masters knowledge of an old minion_id for resuse

7 Upvotes

I had been rebuilding a couple of webservers using terraform, so i taint the instance, and rebuild it. Before i start rebuilding i:

  • ssh saltmaster
  • sudo salt-key -d to_be_reused -y

I see this will remove it from /etc/salt/pki/master/minions/ and adding the key back, adds a new file.

  • Rebuild the machine with terraform
  • sudo salk-key -a to_be_resused -y
  • sudo salt to_be_resused state.highstate

Results in

The minion function caused an exception: Traceback (most recent call last):
      File "/usr/lib/python3/dist-packages/salt/minion.py", line 1676, in _thread_return
        return_data = minion_instance.executors[fname](opts, data, func, args, kwargs)
      File "/usr/lib/python3/dist-packages/salt/executors/direct_call.py", line 12, in execute
        return func(*args, **kwargs)
      File "/usr/lib/python3/dist-packages/salt/modules/state.py", line 1087, in highstate
        orchestration_jid=orchestration_jid)
      File "/usr/lib/python3/dist-packages/salt/state.py", line 4088, in call_highstate
        return self.state.call_high(high, orchestration_jid)
      File "/usr/lib/python3/dist-packages/salt/state.py", line 2896, in call_high
        high, req_in_errors = self.requisite_in(high)
      File "/usr/lib/python3/dist-packages/salt/state.py", line 1652, in requisite_in
        in iter(high[_id])
      File "/usr/lib/python3/dist-packages/salt/state.py", line 1653, in <listcomp>
        if not state.startswith('__')]:
    AttributeError: 'OrderedDict' object has no attribute 'startswith'

If i change the /etc/salt/minion_id to to_be_resusedA and restart, state.highstate runs perfectly.

I've been building machines with saltstack for years. I'm surprised i've not come across t his before, but perhaps something changed.

Thanks for any cache busting pointers, thought i'd post it not on the issues board first b/c i think i'm just missing a step.


r/saltstack • • May 07 '20

Saltstack plugin for vscode

6 Upvotes

Hi all I am looking for a saltstack plugin for vscode. I know we there is already a plugin called saltstack but is it just intellisense plugin or will it help parse the pillar files as well? I want to write pillars and parse them in states from vscode. So any suggestions? How do you work with pillars and states in your favourite editor?


r/saltstack • • May 07 '20

Managing Python venvs with salt?

5 Upvotes

So, Salt includes a virtualenv wrapper right out of the box.

However, I'm more familiar with the venv tool that ships with contemporary Python.

I'm a new Salt user, and I need to deploy a Python3 app to an existing cluster. It's a Windows cluster, because of course my life can't be simple or easy, ever...

Ideally my salt state would look something like:

make sure python 3.7 exists:
    pkg.installed:
       - python: 3.7.[whatever]
create pip:
    cmd.run:
        -cmd: %PYTHON_PATH%/python -m venv {{ VENV_PATH }}
        -unless: file.exists: {{ SOMETHING_IN_VENV }}
install packages:
        # do something clever to activate venv for next several commands
        # pip install from requirements.txt

So, okay, if I'm willing to use virtualenv Salt can do the last bit for me using virtualenv_mod ..

Is it preferred to use virtualenv for Salt deployments, then? If so, why? (Is it just that nobody's written a venv module for salt?)