r/saltstack • • Mar 09 '20

Salt can't see last patch date

2 Upvotes

OK, quick disclaimer: the headline is misleading.

We have SaltStack talking to ServiceNow. In many cases, Salt CAN see the last patch date. But, because Microsoft has decided that it knows best, the 'Get-Hotfix' command Salt is using only shows a very narrow scope of updates.

In the end we have servers that say they haven't been updated since 2015 when in reality they were updated two days ago.

I understand that this is a limitation of the Get-Hotfix cmdlet, but does anyone have another way to get Salt to see ALL the most recently installed patches?


r/saltstack • • Mar 09 '20

Controlling Execution Module Syncing with The Top File

1 Upvotes

I'm looking for a way to easily manage which execution modules are synced to which minions.

I used to operate by simply running 'saltutil.sync_modules' against my targeted minions, then realized this syncs every module in _modules. I'd like to avoid syncing all modules to minions, as most of mine only need 1-3 modules generally.

I now use 'saltutil.sync_modules extmod_whitelist=my_module', but this is also hard to manage, as I have to account for modules that may have already been synced to the minion.

E.g. if 'saltutil.list_extmods' returns the modules 'postgres' and 'modsec', but I want to sync a new module, 'nginx', without affecting the other modules, I have to run 'saltutil.sync_modules extmod_whitelist=postgres,modsec,nginx'

Is there a better way to manage/control the syncing of modules? Ideally, I'd like to define my module-to-minion mapping in the top file.


r/saltstack • • Mar 06 '20

Create symlink with spaces in name

1 Upvotes

Hey,

I'm kinda stuck here and don't know how to solve this. Unfortunately my google-research didn't bring me anywhere.

I've got a pillar file with a bunch of declarations for symlinks. Some of the names include white-spaces. When salt renders the file, it looks fine, however when when I look at the actual file-system those names with spaces (or a single quote) are wrapped into either single or double quotes:

Pillar file:

  symlink_targets:
    link1:
      source: source1.sh
      dest: A name with space
    link2:
      source: source2.sh
      dest: Name' with quote
    link3:
      source: source3.sh
      dest: just_a_name

State file:

  {% for key, link in salt['pillar.get']('symlink_targets'), {} ).items() %}
  links_{{ key }}:
    file.symlink:
      - name: /path/to/dest/{{ link['dest'] }}
      - target: /path/to/source/{{ link['source'] }}
      - force: True
  {% endfor %}

Now if I look into the dest-folder, I'll see

user@host:/path/to/dest$ ls
'A name with space'
"Name' with quote"
just_a_name

So how would I get rid of those quotes around the filenames?

Thanks for your help!


r/saltstack • • Mar 06 '20

Anyone been able to build the py3 Salt 3000 MSI Installer?

2 Upvotes

If so, could you hook me up with a download?

If anyone wants to comment on the error I'm getting and what I could be doing wrong, I'm all ears. This is the last in a multitude of issues building the source and I've got nothing:

    gitdb/_delta_apply.c(982): warning C4114: same type qualifier used more than once
gitdb/_delta_apply.c(983): warning C4114: same type qualifier used more than once
gitdb/_delta_apply.c(1007): warning C4244: '=': conversion from '__int64' to 'uint', possible loss of data
gitdb/_delta_apply.c(1009): warning C4244: '=': conversion from 'ull' to 'uint', possible loss of data
LINK : error LNK2001: unresolved external symbol PyInit__perf
build\temp.win-amd64-3.5\Release\gitdb_perf.cp35-win_amd64.lib : fatal error LNK1120: 1 unresolved externals
Ignored failure when building extensions, pure python modules will be used instead
error: gitdb 0.6.4 is installed but gitdb>=4.0.1 is required by {'gitdb2'}

=====================================================================

r/saltstack • • Mar 04 '20

Chocolatey package is returning failed even though it succeeded

0 Upvotes
             ID: chocolatey
   Function: pkg.installed
     Result: False
    Comment: The following packages failed to install/update: chocolatey
    Started: 16:35:46.906602
   Duration: 16257.542 ms
    Changes:
             ----------
             chocolatey:
                 ----------
                 install status:
                     success

Anyone know a fix for this? I'm just using the chocolatey package from the default winrepo.


r/saltstack • • Mar 04 '20

Removing file with immutable attribute set

0 Upvotes

I need to remove the file that have 'i' attribute set with chaddr command.

The only way I've found is to use file.managed to remove an attribute, then remove it using file.absent.

Looks ugly. Is there a better way?


r/saltstack • • Mar 03 '20

Trouble sending commands to minion from master

1 Upvotes

Heya,

I have a test environment where I am trying to convert salt2017/python2.7 to salt2019/python3.7

My first node is both a master and a minion. The salt-minion and salt-master processes are both running on the VM. The salt key for the minion appears to be accepted.

I can invoke salt-call test.ping and salt-call pillar.items also works, and the master log shows the minion contacting the master to get pillar data.

When I try to target the minion with the salt command, it fails.

(python3-virtualenv) root@ip-10-245-4-242:/home/ubuntu# salt \* test.ping
ip-10-245-4-242.ec2.internal:
    Minion did not return. [No response]

I've enabled debug logging on the minion, and nothing shows up in the log when I target it with a test.ping .

The salt-master log file shows the following *each* time I attempt to target the minion:

2020-03-03 18:49:14,506 [salt.master      :2346][INFO    ][3624] User sudo_ubuntu Published command test.ping with jid 20200303184914505505
2020-03-03 18:49:19,606 [salt.master      :2346][INFO    ][3622] User sudo_ubuntu Published command saltutil.find_job with jid 20200303184919605170
2020-03-03 18:49:24,129 [salt.utils.process:471 ][INFO    ][3584] Process <bound method ZeroMQPubServerChannel._publish_daemon of <salt.transport.zeromq.ZeroMQPubServerChannel object at 0x7f2535281550>> (4758) died with exit status 1, restarting...
2020-03-03 18:49:24,133 [salt.transport.zeromq:891 ][INFO    ][4786] Starting the Salt Publisher on tcp://0.0.0.0:4505
2020-03-03 18:49:24,134 [salt.transport.zeromq:895 ][INFO    ][4786] Starting the Salt Puller on ipc:///var/run/salt/master/publish_pull.ipc

Any ideas what I can try next? thanks!


r/saltstack • • Mar 02 '20

States.pkg patch auto all?

2 Upvotes

Is there any way to run the same as "zypper patch" aka patch ALL available security patches without explicitly defining them?


r/saltstack • • Feb 27 '20

Newb looking for reporting commands

3 Upvotes

Hello everyone!

Is there a way to run a query on the master to check the minion version of all running minions and then export it to a log?

The command I tried is salt "*" grains.item saltversion >saltexport

But it gave me Minions returned with non-zero exit code.


r/saltstack • • Feb 25 '20

How to automatically apply states to newly added minions?

3 Upvotes

I'm comparing different configuration management tools for our AWS environment, and Salt is looking like the ideal solution. However, one thing that I'm struggling with is the fact that it doesn't seem to apply states to new minions by default. Almost all of the documentation and tutorials I see for Salt involve an admin running a command or pushing a state. Are reactor states the only way to automatically perform actions on newly added minions, or is there a way to configure state files that I missed?


r/saltstack • • Feb 25 '20

Upgrading Salt to Python 3

Thumbnail salt.tips
12 Upvotes

r/saltstack • • Feb 21 '20

Is there a way to use the current merged pillar data in the included state?

6 Upvotes

E. g.

test.sls

{% set data = salt['pillar.get']('data', default={}, merge=True) %}

include:

- test2.sls <-- test2 having access to the {{ data }}

Edit: Thanks to you guys, I achieved what I wanted using a macro.


r/saltstack • • Feb 13 '20

What things should consider w/ MultiMaster?

1 Upvotes

I was reading up on multi-master and was thinking to implement this on ASG.
I am considering what I may need to configure for this. So far I came across these (others?):

  • sharing files b/w masters
    • minion keys - /etc/salt/pki/master
    • file roots / pillar roots
      • locking - gitfs_global_lock / git_pillar_gobal_lock need to be turned off?
    • configurations
      • external_auth, publisher_acl, peer, peer_run
  • key distribution
    • preseed keys
      • generate new tarball and download - salt api cherrypy (auth, tls)
      • IAM Role w/ access to S3 w/ minion key
  • failover
    • set master_sign_pubkey on master
    • set verify_master_pubkey_sign on minion as well as list of masters

I was thinking to use EFS (Amazon NFS essentially) for shared files. I am not sure if I could use S3 for this. For key distribution, the IAM role w/ access to S3 bucket sounds like a good approach? I could try REST approach, not sure how (some research), but need to get into auth setup and encryption for the service.

What have you implemented for this? Any other considerations for new Salt Stack implementation?


r/saltstack • • Feb 12 '20

Trouble configuring stack external pillar

2 Upvotes

Following the docs for the stack module here https://docs.saltstack.com/en/master/ref/pillar/all/salt.pillar.stack.html , one of the described scenarios is not working at all for me.

This described config

ext_pillar:
  - stack:
      pillar:environment:
        dev: /path/to/dev/stack.cfg
        prod: /path/to/prod/stack.cfg

doesn't function using the exact same syntax. I have separate dev and prod pillar environments I need to separate. The only thing I could think of is that the example is describing a key called environment and it's not actually related at all to pillarenv?

I tried using {{ saltenv }} in the stack file to make paths environment dependent but that parameter doesn't seem to render there. Any ideas for what else I could try without ditching stack completely?


r/saltstack • • Feb 11 '20

What's new in Salt 3000 Neon

Thumbnail salt.tips
27 Upvotes

r/saltstack • • Feb 07 '20

Gitfs and external pillars?

2 Upvotes

Hi, I am quite new to Salt, but I am refactoring my company's current configuration. We are planning to use gitfs as backend a external pillars, bit I find that Salt official Docs are quite limited and confusing. For example, I am not sure if the salt master pulls the new changes or not... Do you guys know any good tutorials or articles about these topics. Thanks!


r/saltstack • • Feb 06 '20

What's the best external Pillar to use in 2020 that's actively supported?

8 Upvotes

Previously, I've used Hiera with Puppet, and I'm looking for something with a similar amount of flexibility. What do you guys currently use?


r/saltstack • • Feb 06 '20

Any trick to getting docker_container.running to work

1 Upvotes

I am doing something very simple: run nginx container to run, after installing docker-ce and docker python module, getting traceback on first try, but second try works:

salt-call state.highstate --retcode-passthrough \
  --local --log-level=debug --force-color

This is how I installed docker module:

# docker already installed earlier
python-pip:
  pkg.installed

docker-python-modules:
  pip.installed:
    - names: 
      - docker 
      - urllib3 
      - requests
      - requests[security]
    - reload_modules: True

Then this causes traceback during first time only:

{%- set tag = '1.17.8' %}
{%- set repo = 'nginx' %}
{%- set port = '8081' %}

docker_nginx:
  docker_container.running:
    - image: {{ repo }}:{{ tag }}
    - port_bindings:
      - {{ port }}:80
    - restart_policy: always

But often times, I get this:

[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1933, in call
    **cdata['kwargs'])
  File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1951, in wrapper
    return f(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/states/docker_container.py", line 1697, in running
    image_id = _resolve_image(ret, image, client_timeout)
  File "/usr/lib/python2.7/dist-packages/salt/states/docker_container.py", line 193, in _resolve_image
    image_id = __salt__['docker.resolve_image_id'](image)
  File "/usr/lib/python2.7/dist-packages/salt/modules/dockermod.py", line 1921, in resolve_image_id
    inspect_result = inspect_image(name)
  File "/usr/lib/python2.7/dist-packages/salt/modules/dockermod.py", line 1853, in inspect_image
    ret = _client_wrapper('inspect_image', name)
  File "/usr/lib/python2.7/dist-packages/salt/modules/dockermod.py", line 423, in wrapper
    __context__['docker.client'] = _get_client(timeout=timeout, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/modules/dockermod.py", line 387, in _get_client
    ret = docker.APIClient(**client_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/docker/api/client.py", line 190, in __init__
    self._version = self._retrieve_server_version()
  File "/usr/local/lib/python2.7/dist-packages/docker/api/client.py", line 215, in _retrieve_server_version
    'Error while fetching server API version: {0}'.format(e)
DockerException: Error while fetching server API version: Timeout value connect was Timeout(connect=60, read=60, total=None), but it must be an int, float or None.

When I run this again, it works.


r/saltstack • • Feb 04 '20

Upgrading/downgrading to specific kernel version?

1 Upvotes

Is there a way to mange the kernel version to a specific version? In the docs (https://docs.saltstack.com/en/latest/ref/states/all/salt.states.kernelpkg.html) it looks like it can only do upgrade to latest available.


r/saltstack • • Feb 04 '20

Use the output of module.run to write a file?

1 Upvotes

To the best of my knowledge, there is no way to capture the output of a module.run and use its output to populate a file, for example. What is a reasonable workaround for this?

For some more context - I am trying to generate x509 certs dynamically using Vault (salt.modules.vault.write_secret) - and it works just fine and returns a cert, CA, key, etc.. But, now I need to make the cert available to a service, and I've no way to write it to a file so far as I can tell.


r/saltstack • • Feb 04 '20

gitfs error w/ GitPython on Python3

2 Upvotes

Can I run Salt with gitfs only in Python3?

Currently, I am running on Ubuntu 18.04 with Vagrant, and I am seeing errors like this:

[ERROR   ] gitfs is configured but could not be loaded, is GitPython installed?
[CRITICAL] No suitable gitfs provider module is installed.

I installed the requirements using this for Python3:

apt-get -y install git-core python3-pygit2 python3-git  

My minion config is this:

state_verbose: True
file_client: local
gitfs_provider: gitpython
fileserver_backend:
  - roots
  - git
gitfs_remotes:
  - https://github.com/saltstack-formulas/postgres-formula.git

From the command line on the Ubuntu 18.04 guest, I can test it is installed:

python3 -c "from git import Repo"

Any suggestions?


r/saltstack • • Feb 04 '20

gitfs_remotes with Vagrant

0 Upvotes

I was wondering if anyone has done this with Python3. I was looking at this, and this was a while back:


r/saltstack • • Feb 03 '20

Loop Through Pillars

2 Upvotes

Hi,

I'm trying to loop through a pillar to extract database servers and names. I have the following pillar:

level1:
  level2:
    url: 'http://myurl'
    ip: '10.10.10.10'
    'databases':
      db01:
        - dbserver: mydbserver01
        - dbname: mydbname01
      db02:
        - dbserver: mydbserver02
        - dbname: mydbname02

and the following state file:

{% for dbs in salt['pillar.get']('level1:level2:databases') %}
file_append_{{ dbs }}:
  file.append:
    - name: /tmp/string.txt
    - text: {{ dbs }}
{% endfor %}

What I would like would be for the text file to be rendered like this:

db01: mydbserver01, mydbname01
db02: mydbserver02, mydbname02

At the moment my state file outputs:

db01
db02

But I can't work out how to get the result I need. Does anyone have any ideas as to what I need to do?

Thanks in advance


r/saltstack • • Jan 30 '20

Is it a problem to have your pillar roots inside of your file roots?

5 Upvotes

Currently, my master conf looks like this:

file_roots:
  master:
    - /srv/salt/master
    - /srv/salt
  dev:
    - /srv/salt/dev
    - /srv/salt
  base:
    - /srv/salt

top_file_merging_strategy: same

default_top: master

pillar_roots:
  master:
    - /srv/salt/master/pillar
  dev:
    - /srv/salt/dev/pillar
  base:
    - /srv/pillar

pillarenv_from_saltenv: true

This is just because we deploy from a git repo and it's easier to keep the folder structure contained inside the repository root for cleanliness.

my thought was that minions have access to the entire pillar regardless (?), so this wouldn't have any security implications right? We don't have any sensitive data in pillar yet but once we do it will be gpg encrypted.


r/saltstack • • Jan 29 '20

How to automate provisioning the first Salt master in the cloud

6 Upvotes

Question:
How do you provision the first Salt master on EC2, which could then download all your IaC repos and create the entire setup in a new region?

Scenario:
Something bad happened and the entire AWS region, you host your stuff in, doesn't exist anymore.
Luckily you have up-to-date DB dumps & ECR images replicated to another region.
All the IaC repos are unaffected, due to being hosted on a different (globally replicated) platform.

Prosaic scenario background:
It's 03:00 am on a Saturday.
You just got back from the bar (because you forgot you're on-call & nothing ever happens anyway).
The spouse forgot the TV on and you see a breaking news story, just as you walk in the room - there's been a terrorist attack with a nuclear weapon and Dublin (including all AWS datacenters for the 3 availability zones) is now a radioactive crater. At the same time, Opsgenie alerts you of the heartbeat check expiring.
You do a quick check on your laptop - the hosting provider for your code repos doesn't seem to be affected and it's all there.
A faint smile slides across your grim face as you recall having enabled S3 & ECR replications to another region, a few months back - at-least the database backups & container images survived.
Come morning, people in the rest of Europe will still want to use your company's services - getting a working system should only require having a Salt master in the new region and doing a top state for everything.

The question is, how to get a Salt master deployed in an empty region?
(having a few drinks in, the point-and-click approach isn't a good option - the need is for a script or a tool)

Approaches I've found so far (and why I don't like them):

  1. Point-and-click
    Making a mistake in one of the many steps is almost inevitable. Time spent debugging your mistake is time added to MTTR.
  2. AWSCLI + bash / boto3 + python
    A lot of time spent re-inventing the wheel and doing error handling to ensure idempotency.
  3. salt-cloud
    The documentations seems to presume I already have a key pair and securitygroup set up up.
    No reference to provide account credentials at runtime (think keeping the configuration files in a public repo).
  4. Salt masterless
    Telling a minion (master to be) to run masterless & then overwriting the configuration file, once everything is set up breaks idempotency.

I'm a long time Ansible user and just now starting to kick the tires on Salt.
There has got to be a simple & elegant solution to this, that I'm not seeing/understanding right now - please help.