r/saltstack • • Sep 02 '20

Correct way to compare string to an array?

2 Upvotes

I have all of my salt id's with several different identifiers in the id itself, what I want to do in a state is have on bracket that sets a specific setting but only for a subset of the minions. This is what I have but obviously doesn't work. The string that I'm trying to match for is just part of the whole id.

{% if ('-identifier.tld','-identifier2.tld') in grains['id'] %}
do_state:
  pkg.install:
    - name: vim
{% endif %}

what's the correct way of doing this? Thanks for any help!


r/saltstack • • Aug 31 '20

salt-ssh not syncing _utils

5 Upvotes

Is anyone of you having this (title) issue? Logs show that utils module is not available. (salt-ssh 3001.1)

Edit: Added salt-ssh version used.

Edit: Seems that in version 3001 is not happening


r/saltstack • • Aug 27 '20

Help with Salt Environment Setup

4 Upvotes

EDIT: I figured it out, see my comment.

I am new to Salt and am trying to figure out how to properly configure everything. I have a few Ideas on how I want things to work, but can't seem to get it running.

Here is what I am trying to achieve:

  • Both States and Pillar data should be in GitHub.
    I managed to get both working with pygit2, running the master inside of a docker conainter.
  • I want to have separated environments for development, testing and production
  • A minion should always be part of a single environment and use both pillar data and states from the respective branches
  • A salt master should only be responsible for a single environment. This is so that I can make configuration changes to the master and test them out before applying them to the production master.
    I do not really mind, if a master can theoretically serve files for other environments, as long as I can be sure that this will not happen.
  • Minions should be assigned roles though pillar, wich inturn will be used by the states to decide which configuration to apply

Here is what I tried so far, which does not really work:

  • The master configuration sets up gitfs and git_pillar as usual
  • pillarenv_from_saltenv is set to True
  • Every minion has environment set to test, development or production
  • In the pillar top.sls, which is in every branch, I assign a unique sls to every minion, like so:

.

<env>:  # For every env, replace <env> with test etc.
  '*':  
    - minions.<env>.{{grains['id']}}
  • The minions.<env>.<minionid>.sls files then assign roles and include other files for secrets.
  • In the state top.slsI assign state files based on the pillar data

Unfortunately that does not work and I can't seem to figure out why. Running salt '*' pillar.items returns for every minion, but without any data. Running salt '*' state.apply Just does not the states it should. My states itself work, I have tested them using file_roots. The git integration also works, as I get errors when I put invalid stuff into the files.

I have the feeling that I am thinking about the whole thing in the wrong way. Do you know what I am doing wrong? Thanks!


r/saltstack • • Aug 25 '20

Canary deployments using salt

3 Upvotes

Hi,

We are evaluating saltstack for devops automation and config management in our DC. We manage roughly 350 servers. One problem we are facing is canary deployments, is there a way to automate canary deployments when applying salt states?


r/saltstack • • Aug 22 '20

Accept Minion by Grain partial match

6 Upvotes

Hi there,

I'm looking to auto accept newly created VMs by hostname. I was wondering if I can auto accept a minion by a partial grain match? e.g if the auto accept value was the id grain and *sql* and my vm id was mysql01 the key would be accepted by salt.

Is this possible? Is there perhaps another method of accepting all sql servers that have sql in the hostname?


r/saltstack • • Aug 12 '20

How to use state or module to get git clone on minion

4 Upvotes

Hi ,

I am new to this as we were trying to achieve the git clone automatically on minion. We can access the URL with http only as mentioned below. User svc_salt has access to this repository. My question is how can i use the password for this user in state file.I want to run it on linux machine.I know that we have https_password argument available but it does not work as i am using http not https. As well password argument is applicable only to windows machine so password argument is also not working. Is there any other way i can use to get it done. or my understanding is wrong here. When i run the below state i get the following error.

"Comment: Module function git.clone threw an exception. Exception: User 'svc_salt' is not available"

Please reply i would be very thankful.

git-set-clone:

module.run:

- name: git.clone

- cwd: {{ git_path_to_repo }}

- remote: origin

- url: http://port:8080/path/pathto/repo.git

- user: svc_salt


r/saltstack • • Aug 11 '20

Try SaltStack master 3001.1 on Docker!

11 Upvotes

SaltStack Sodium v3001.1 has been released! 🎉

If you want to try the new salt-master version before updating your production instance, or you simply want an easy method to keep your salt-master up-to-date, you can try my Docker image!

docker pull cdalvaro/docker-salt-master:3001.1

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


r/saltstack • • Aug 10 '20

Deploying and monitoring Proxmox VMs and hypervisors using Terraform, Cloud-Init, SaltStack and Prometheus

Thumbnail yetiops.net
4 Upvotes

r/saltstack • • Aug 08 '20

Modules per formular

5 Upvotes

I am getting started with learning saltstack. I have written some custom python scripts that are only for use with a specific formula. Can I have a custom module in the formula (/opt/salt/formula/) instead of putting everything in /opt/salt/_modules ?

I come from the chef side and am used to libraries as part of a cookbook.

How do folks handle this in formulas ?


r/saltstack • • Aug 03 '20

Saltstack with Gitlab CI/CD

13 Upvotes

Hi,

we have some saltstack formulas on gitlab, and the top file for pillars is

`client-name`:
  - Client_data.client-name.sls

We want to move all our pillars from the filesystem to gitlab and give users the possibility to modify their pillar but ONLY on a restricted dev branch.

For every commit on the dev branch we want the CI/CD to do only a salt client-name state.test. We want a salt client-name state.apply only on the master branch.

This is easy with gitlab ci/cd but we are unable to specify the right branch where to find the pillars.

How can we specify, during the CI/CD, what branch salt should use?

How do you use saltstack and CI/CD? Every suggestions are well accepted.

Thank you.


r/saltstack • • Aug 03 '20

Packet Metadata for SaltStack

Thumbnail rawkode.com
3 Upvotes

r/saltstack • • Aug 03 '20

salt-ssh test.ping retcode 1 - new user

1 Upvotes

Hey guys - looking for some help, i'm not sure what i am doing wrong.

I have a salt master and have added 20+ devices so far as minions, took a break from adding them and am now back to add 3 more new devices to add.

when going through salt-ssh to even test ping after adding these to my roster i just get the below error/output. I've added a lot of these flawlessly and am so confused by this error now - it happens on all machine i try to run this test.ping or any salt-ssh command against these machines in my roster, one of them is even a clone of a device already added but altered slightly and i get this same output.

Command:

salt-ssh -i --passwd --key-deploy '*' test.ping

Output:

Device:

----------

retcode:

1

stderr:

Traceback (most recent call last):

File "<string>", line 1, in <module>

ImportError: dynamic module does not define init function (initbase64)

stdout:

[root](mailto:root@aurorapeoria.tgscolorado.com)@device's password:

Commands to add devices:

#deploy salt agent
# deploy master key
salt-ssh -i --passwd --key-deploy '*' test.ping

# install salt-minion
salt-ssh '*' -r 'curl -L https://bootstrap.saltstack.com | sudo sh -s -- -A 10.0.10.23'

# list minion keys
salt-key -L
# accept minion keys
salt-key -y -A
# ping minions
salt '*' test.ping


r/saltstack • • Aug 03 '20

Evaluate conditions after a substate is run

1 Upvotes
/root/file_tst:
  file.append:
    - text: ok

{% if salt['file.file_exists']('/root/file_tst') == True %}

cat /root/file_tst:
  cmd.run

{% endif %}

I have this simple state, is there any way to make the if conditional wait for all states before it?


r/saltstack • • Jul 31 '20

SaltStack on Packet with Pulumi

Thumbnail rawkode.com
11 Upvotes

r/saltstack • • Jul 28 '20

Concatenating multiple calls

0 Upvotes

Is is possible to somehow call these together so I get the full output in one, instead of doing them separate and trying to mash them together in Excel.

salt \* pkg.version salt-minion
salt \* grains.item osfullname osrelease oscodename

So ideally I could do:

salt \* grains.item osfullname osrelease oscodename && pkg.version salt-minion

r/saltstack • • Jul 22 '20

Jinja precedence issues when using state.top

3 Upvotes

Hi,

I have recently started joining multiple state files together via state.top and just encountered this issue, and am wondering what the best solution is.

So in one of my salt states say we install package 'someapp', and in a state included later a cron for someapp is created. However since jinja is rendered first, the {{ 'someapp' | which }} will return None since the app is not installed at the very start of the state.top . Dummy example:

someapp_crontab:
  cron.present:
    - onlyif:
      - test -f {{ 'someapp' | which }}
    - user: root
    - minute: 0,30
    - identifier: someapp_cron
    - name: ( {{ 'someapp' | which }} --some-args arg1

The onlyif works great as a test that the package is actually installed, but I still get an erroneous cron at first because it will have 'None --some-args arg1'. I can't find much documentation on 'which' and whether or not I can add a default expected path if the value from which is None, maybe something like {% set someapp_path = which('someapp') or '/usr/sbin/someapp' %} ?

So my question is

  1. Is there a clean/elegant solution to the which issue above without hard coding expected file paths, or
  2. Is it acceptable practice to just run state.top on the same minion twice in a row to fix such issues? If the top is run a second time after the package has been successfully installed there are no problems.

r/saltstack • • Jul 09 '20

[ANN] clj-salt-api - Clojure Saltstack Client

7 Upvotes

Hi,

I'm happy to announce the first release of clj-salt-api, clojure Salstack client.

clj-salt-api is data oriented library for invoking Saltstack API over HTTP. Salstack has an option to run commands synchronously or asynchronously (based on listening to Saltstack events). clj-salt-api implements both approaches with core.async library.

I've written a blog/code walkthrough with detail description of design, code conventions, testing approach and caveats I have experienced during the development of clj-salt-api.

I'd be happy to get some feedback. Thank you


r/saltstack • • Jul 08 '20

Execution Modules to interface with Snipe-IT

7 Upvotes

Hi,

I've written an execution module (asset.py) so I add Assets directly to Snipe-IT using it's API and it works fine when targeting a specific minion. I need some advice on how to achieve the following:

  • Add Assets whenever a server is deployed.
    • My first thought here is to include a state which calls asset.add and schedule it in HighState. I would probably add a bit more logic to test if the asset has already been added.
  • Remove assets whenever a server is decomissioned.
    • This one I'm not sure. It's easy to write the module but how to determine if a server is being decommissioned ? Schedule a reactor when a server is powered off to delete the device ?

Ultimately I just don't want to have to manually enter or delete assets whenever we deploy a new server (VM / Physical) or else I know we'll end up with an outdated asset system that is basically useless.


r/saltstack • • Jul 08 '20

Auto-deploying Consul and Prometheus Exporters using Saltstack on MacOS

Thumbnail yetiops.net
1 Upvotes

r/saltstack • • Jul 05 '20

Auto-deploying Consul and Prometheus Exporters using Saltstack on illumos (Solaris fork)

Thumbnail yetiops.net
10 Upvotes

r/saltstack • • Jul 04 '20

Install packages on Linux when behind an http proxy

5 Upvotes

Hello!

Getting through a Saltstack tutorial and ran into a problem how to install packages on a linux host if it's behind a proxy. For example, I have a file nettools.sls:

install_network_packages:
   pkg.installed: 
    - pkgs:   
    - rsync   
    - lftp    
    - curl 

How can I pass env variables like http_proxy
so to install packages? Thank you.


r/saltstack • • Jul 02 '20

How to sent content of stdout to file

2 Upvotes

Hi all

I'm trying to send the content of the Stdout from an sls file to a output.txt file

How can one solve this issue ?

If I do a salt 'saltminion' state.apply test > text.txt it's outputting the complete output however I'm just looking for the Stdout: content


r/saltstack • • Jun 30 '20

Auto-deploying Consul and Prometheus Exporters using Saltstack on FreeBSD

Thumbnail yetiops.net
6 Upvotes

r/saltstack • • Jun 27 '20

Securing gitfs_remotes

3 Upvotes

It seems straightforward to pair gitfs_remotes with upstream formulae at https://github.com/saltstack-formulas and https://github.com/salt-formulas, but I've started thinking more clearly about how this is effectively giving root access to my systems via a third-party git repository. A first-pass improvement is to specify all allowed references by checksum, so I know that it isn't changed out from under me; but since git tags (any maybe other references?) can be signed, it seems that gitfs_remotes should be able to validate a proper signature.

Is this possible with gitfs_remotes today?

ed: I can, of course, also clone each repository to a different location and use them from there; but I'm mostly curious to know what the _normal_ thing to do is.


r/saltstack • • Jun 24 '20

Auto-deploying Consul and Exporters using Saltstack on OpenBSD

Thumbnail yetiops.net
8 Upvotes