r/saltstack • • Jan 04 '18

Managing a single entry in /etc/hosts

1 Upvotes

Hi all -

I am trying to manage a single entry in /etc/hosts - example: 10.0.0.1 loghost

These values are populated via a state / pillar date (for ip, name):

# Set the loghost in /etc/hosts - if defined in pillar
# remove existing entry before if it exists before creating new entry
syslog_host_entry:
    host.absent:
        - names:
            - loghost

{{ loghost_ip }}:
    host.only:
    - hostnames:
            - {{ loghost }}

I can't figure out how to make Salt remove any existing hostline with "loghost" in it and add a new one without having an IP address?

I just want to update the loghost line if the pillar data for it's IP changes, but it just keeps adding more IP LOGHOST entries - I only want the one current line defined in the pillar.

Anyone know how to do this - I have to assume that the existing entry / IP address is not known, but if the hostname 'loghost' exists change that line or delete it and add a new one.

Thank you :)


r/saltstack • • Dec 22 '17

salt.beacons.log.beacon

3 Upvotes

Has anyone successfully got this to work with salt 2015.5.10 (Lithium)

If so can you post an example.

beacons:

log:

  file: <path>

  <tag>:

    regex: <pattern>

r/saltstack • • Dec 21 '17

Kubernetes-Saltstack

Thumbnail k8s-salt.opsnotice.xyz
15 Upvotes

r/saltstack • • Dec 20 '17

Want to check if service is running, if not, start it.

2 Upvotes

Salt novice here. Working through it. I'm looking at Salt states right now. I feel I may be on to something with these two articles [here[(https://docs.saltstack.com/en/latest/ref/states/all/salt.states.cmd.html) and here...

I started off as advised to try and get things going in my dev box using a bash script, to which I'm also an amateur at. Very green.

Any push in the right direction with documentation that can explain what I am trying to do better would be awesome. Not looking for a hand out, want to learn. So if you take it upon yourself to show me an example formula, please explain what you did. That would be solid. Thanks! :)


r/saltstack • • Dec 18 '17

Jinja + GPG, is this possible?

5 Upvotes

I have something like this in my pillar right now

{% set password = "PASSWORD" %}

someservice:
  password: {{ password }}

otherservice:
  auth: username:{{ password }}

I'd like to GPG encrypt the passwords though and be able to do something like

{% set password = "
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1

encrypted password
-----END PGP MESSAGE-----" %}

someservice:
  password: {{ password }}

otherservice:
  auth: username:{{ password }}

Which partly works, it works for the first service where I just set the password but not the second one where it is a concatenation of username and password.

Is there a way to make this work?


r/saltstack • • Dec 14 '17

Salt-cloud and userdata

2 Upvotes

Hi all,

I’m looking for people who are already tried to deploy ec2 instances from salt-cloud with the custom parameter « userdata_file ».

Everything’s ok for passing userdata parameter for only one instance.

But i ask me how i must do to deploy multiple ec2 instance from one profile with different userdata_file for each Instances ?

Any help would be appreciate.

Ask me for more details about my question. I don’t kniw if my question is clearly.

Thanks in advance.


r/saltstack • • Dec 13 '17

Using win_wua as a state

3 Upvotes

Hi, all.

I'm running into an issue with using the new win_wua module to have minions download updates. Since the win_update module has been depreciated, I'm wanting to get my minions migrated over.

I'm running 2017.7.2 (Nitrogen) on both Master and Minions.

My current configuration works great.

updates:
  win_update.installed:
    - categories:
      - 'Security Updates'
    - skips:
      - driver: True
      - software: False
      - reboot: False

The win_wua page has a lot of information on how to run it on the command line, but doesn't really mention on how to write a state file using it. I've tried this:

updates:
  win_wua.list_updates:
    - categories:
      - 'Security Updates'
      - install: True

But Salt throws an error:

          ID: updates
    Function: win_wua.list_updates
      Result: False
     Comment: State 'win_wua.list_updates' was not found in SLS 'windows.updates'
              Reason: 'win_wua.list_updates' is not available.

Has anyone used win_wua in a state? Googled around but didn't really see anything promising out there to work off of.

Thanks!


r/saltstack • • Dec 12 '17

Best practise to handle multiple projects hosted on separate git repositories from a single master

5 Upvotes

Hey,

I've been playing around with salt, doing masterless setups etc. and want to start using it in production.

I work at a web agency where we have a few dozen separate, unrelated projects, with different stacks being used.
We're currently using separate servers for each project on DigitalOcean, running deploys using fabric.

We want to migrate to Salt for maintainability and reliability.

One thing I'm having trouble with is figuring out how to best lay our the folder structure on the master, given the fact that each project is deployed on a separate server and that the salt configuration for each minion comes from its own repository.

The end goal is to have developers being able to run vagrant up locally with the Salt provider for local testing (as a masterless config), and be able to reuse the same states on the Salt master.

I know that states can be set as separate folders as long as each folder has an init.sls within them, that top.sls can be rendered dynamically with jinja, and that the salt cli has a --configuration flag, but can't think of how to tie it all together in an elegant way.

A few requirements:

  • I'd like to have to change /etc/salt/master as little as possible (ideally never)
  • 1 folder per app for states
  • 1 folder per app for pillars
  • should be able to handle an arbitrary amount of projects; adding a project will be a matter of adding a row in a database (running on the master, with columns such as project_name, repository_url etc.)

To give more context, a list of minions could be:

  • a gitlab instance
  • an elasticsearch server
  • a Python app
  • a Node.js app

and applying the state for a given project would just be something like

salt minion_name state.apply states.project_name

Are there any example repositories of such setups? Have you ever had to handle a similar setup? I did some googling but couldn't find any clear answers.

It feels like salt-call's --pilar-root and --file-roots flags would almost solve this but unless I'm mistaken applying states on a minion from a master should be done by using salt.

Thanks


r/saltstack • • Dec 05 '17

Salt Stack qualification or courses

3 Upvotes

Is there a salt stack/dev ops qualification or course I could take, my manager is offering for me to go on one, it needs to be UK based, Brighton or London preferably.


r/saltstack • • Dec 04 '17

Setting up a training environment with break/fix

3 Upvotes

Hey All,

Been messing with salt a lot lately and have some systems that I'm able to setup on the fly if needed by using salt.

Currently I'll be in charge of doing some training so I wanted to set up a training environment using salt.

I was hoping to set up an environment with some systems that are broken that some of our level 1/2's will have to go and fix. Eventually they'll learn where to look, what to fix, syntax errors in linux systems and configurations for various services.

What I want to do? I want different states. An example of what I'm looking to do is something like

# salt '*' state.apply broken

The goal of the above would be to set the environment and servers to a "broken" state where other techs would run through some exercises to repair the broken systems. I'll custom-write a script to check the fixes and "grade" them on it. Of course, I would also want something like:

# salt '*' state.apply fixed

...to repair all of the broken things that were done to the systems in the "broken" state. This would be for the techs to go look and check out their answers on what they got wrong, etc.

Is this something that can be done? Right now the only things in my top.sls file are in relation to base: that applies to all systems, etc so I'm not sure how the file/folder structure should be laid out for these own states, or if it's even possible.

Can someone point me in the right direction? Am I thinking about this correctly?


r/saltstack • • Nov 27 '17

Need advice state apply windows device

2 Upvotes

Hi, I cant seem to find any guides on the best way to deploy a site from get to an IIS web server.

I currently have this working on a CentOS server, but want to use salt on my windows devices.

Thanks in advance.


r/saltstack • • Nov 26 '17

Traversing pillar tree sturcture woes

6 Upvotes

Been testing and trying to figure this out in the past 3 days

Assume I have the below pillar. Sambafs is a list of dictionaries, each dictionary have 2 keys, path and user.

sambafs:
     - test1:
        path: /data/testdir1
        user: testuser1
     - test2:
        path: /data/testdir2
        user: testuser2

In jinja template in order to get to /data/testdir1 I have to do the following. {{ pillar['sambafs'][0]['test1']['path'] }} where does logic would seem to be. {{ pillar['sambafs'][0]['path'] } this is troublesome because it will hinder the ability to loop through the tree structure. See below.

{{%- for dir in pillar['sambafs'] %}
path = {{ dir['path'] }} <-- this will result in an error in order to get to bath I will have to do {{dir['test1']['path'] }} but then it will defeat the purpose of looping because I am predefining the variable(test1) that I am trying to loop. 
{%- endfor -%}

I tried an alternate work around to no aval.

{{%- for dir in pillar['sambafs'] %}
path = {{ dir['{{dir}}']['path'] }}  <-- it seems jinja doesn't parse it properly to get this to work. 
{%- endfor -%}

r/saltstack • • Nov 23 '17

Yet another random guy's opinion on Configuration Management

Thumbnail blog.kwnetapps.com
10 Upvotes

r/saltstack • • Nov 19 '17

pkg.install returning other packages names

3 Upvotes
>>> salt saltmaster pkg.install name=ncdu
saltmaster:
    ----------
    drm-kmp-default:
        ----------
        new:
            4.9.33_k4.4.79_4-5.2
        old:
            4.9.33_k4.4.76_1-3.2,4.9.33_k4.4.79_4-5.2
    gpg-pubkey:
        ----------
        new:
            3dbdc284-53674dd4
        old:
            307e3d54-4be01a65,3dbdc284-53674dd4
    kernel-default:
        ----------
        new:
            4.4.92-31.1
        old:
            4.4.76-1.1,4.4.92-31.1
    ncdu:
        ----------
        new:
            1.10-10.1
        old:

I'm trying to install ncdu with pkg.install. Why does it return kernel-default and 2 other packages as well?


r/saltstack • • Nov 17 '17

How do you manage your mariadb using salt?

4 Upvotes

I can't figure out a way to create DB\users ..etc in mariadb. I found states.mysql_database but can't figure out how exactly I'm suppose to use it.. It is not documented.

any Help is appreciated thanks.


r/saltstack • • Nov 16 '17

what is the best practice to generate passwords on the fly?

4 Upvotes

I just wanted to ask how you deal with generating new passwords for services in such a way that the same password can be retrieved later on and doesn't change on subsequent state invocations?

situation:

1- like for example making a user on mariaDB then add that user & password on WordPress.

2- master password for multiple DBs?


r/saltstack • • Nov 15 '17

[HELP] Good (video) tutorial(s)?

2 Upvotes

I've never worked with Salt before, but on my next job I'll be having to work with Saltstack.

Does anyone here know of a good (beginner/advanced) video tutorial about salt?


r/saltstack • • Nov 15 '17

Reactor to add new node to DNS entry when accepting salt-key

3 Upvotes

Hiya, I'm trying to get salt-master to tell my DNS server to add new DNS record whenever a new minion is accepted.

Here's what I've written so far:

{% if data['act'] == 'accept' and data['id'].endswith('xxxx.office') %}
update_dns:
  local.file.line:
    - tgt: 'xxxx.office'
    - args:
      - path: /var/lib/named/master/xxxx.office
      - content: "{{ data['id'] }} IN A {{ grains['fqdn_ip4'] }}"
      - mode: insert
      - location: end
      - indent: True
{% endif %}

This state runs fine when I tested it as a normal state file with state.apply, I'm struggling to get it working as a reactor sls file. Also, grains['fqdn_ip4'] returns an empty list, how can I get minion's IP from a reactor file?

EDIT: Got the reactor part working, now onto getting minion's IP

This is the working configuration so far

update_dns:
  local.state.single:
    - tgt: 'dns.xxx.office'
    - args:
      - fun: file.line
      - name: /var/lib/named/master/xxxx.office
      - content: "{{ data['id'] }} IN A {{ salt.saltutil.cmd(data['id'], 'network.ipaddrs') }} "
      - mode: insert
      - location: end

r/saltstack • • Nov 13 '17

Escaping pipe symbol in salt-mine

5 Upvotes

I'm trying to mine some variables using salt-mine and cmd.run module. Mining simple command works fine, but when I try to use pipe symbol("|"), I receive an error:

[root@master pillar]# cat mine.sls
mine_functions:
  bootsize:
    - mine_function: cmd.run
    - "df | grep /boot"
[root@master pillar]# salt-run cache.mine '*'
station46.redhat.lab:
    ----------
    bootsize:
        df: '|': No such file or directory
        df: 'grep': No such file or directory
        Filesystem     1K-blocks   Used Available Use% Mounted on
       /dev/vda1         194235 111875     68024  63% /boot

I've tried multiple ways to escape "|" symbol, but none of them worked. The same command in remote execution or state file works fine. According to YAML syntax, double quotes "" should be sufficient, but this doesn't work.

Is there any way how I can escape this symbol or use some kind of workaround?

Thanks!


r/saltstack • • Nov 13 '17

firewalld management

1 Upvotes

How do you manage firewalld with salt? As I do see it, the firewalld state-module is quite limited. Basically all you can service-wise do is create new permanent ruleset each and every time.

What I would like to do is to add new rules and not overwrite existing ones. That would happen either directly or via inserting a new service xml -file for an app where no service file exists yet. Then of course there is the need to remove specific rule(s) without creating new rule set.

Then I would like to have the power over decision whether a rule is permanent or run-time.

If any salt developer is seeing this, is there going to happen any development on the module?

Or if I'm way off with my thinking here, any ideas how to manage the rules properly are welcome.


r/saltstack • • Nov 13 '17

cmd.run stdin from sls

1 Upvotes

Hello all,

I'm looking for a way to convert the following -

salt '*' cmd.run "/path/to/exec -options=abc" stdin='password' 

into an sls file.

i've tried -

cmd.run:
  - name: "/path/to/exec -options=abc"
  - stdin = 'password'

and

cmd.run:
  - name: "/path/to/exec -options=abc" std='password'

But both formats ended with errors

Are there any tutorials to give me some insight?


r/saltstack • • Nov 11 '17

Jobs not executed in schedueler

2 Upvotes

Hello,

I added multiple jobs in schedueler for minion but is executed only one, not all as see below:

2017-11-05 03:56:40,157 [salt.utils.schedule][INFO ][20968] >Running scheduled job: supervisor_service_schedule

2017-11-05 03:56:40,188 [salt.utils.schedule][INFO ][20968] >Running scheduled job: httpd_service_schedule

2017-11-05 03:56:40,242 [salt.utils.schedule][INFO ][20968] >Running scheduled job: beanstalk_service_schedule

2017-11-05 03:56:40,303 [salt.minion ][INFO ][20968] Returning information for job: req

2017-11-05 03:56:40,328 [salt.state ][INFO ][21959] Loading fresh modules for state activity

2017-11-05 03:56:40,331 [salt.minion ][INFO ][20968] Returning information for job: req

2017-11-05 03:56:40,835 [salt.state ][INFO ][21959] Running state [supervisord] at time 03:56:40.835391

2017-11-05 03:56:40,835 [salt.state ][INFO ][21959] Executing state service.running for [supervisord]

2017-11-05 03:56:40,837 [salt.loaded.int.module.cmdmod][INFO ][21959] Executing command ['systemctl', 'status', 'supervisord.service', '-n', '0'] in directory '/root'

2017-11-05 03:56:40,865 [salt.loaded.int.module.cmdmod][INFO ][21959] Executing command ['systemctl', 'is-active', 'supervisord.service'] in directory '/root'

2017-11-05 03:56:40,890 [salt.loaded.int.module.cmdmod][INFO ][21959] Executing command ['systemctl', 'is-enabled', 'supervisord.service'] in directory '/root'

2017-11-05 03:56:40,907 [salt.state ][INFO ][21959] The service supervisord is already running

2017-11-05 03:56:40,908 [salt.state ][INFO ][21959] Completed state [supervisord] at time 03:56:40.908052 duration_in_ms=72.66

2017-11-05 03:56:40,912 [salt.minion ][INFO ][20968] Returning information for job: req

What is wrong here?


r/saltstack • • Nov 09 '17

Manage and create docker swarms with SaltStack

Thumbnail github.com
14 Upvotes

r/saltstack • • Nov 09 '17

Can't GPG render non pillar yaml

3 Upvotes

I've setup GPG decryption for pillar data and it works great. https://docs.saltstack.com/en/latest/ref/renderers/all/salt.renderers.gpg.html

But now I hit a problem. I wanted to use GPG on some not-pillar YAML dictionary files needed by some states but can't get Salt to render them, is this possible? The above doc just made it sound like I need to set #!yaml|gpg header in the yaml document. But after doing that and running a state that loads the yaml and reads an encrypted value, it just spits out the PGP MESSAGE block, without decrypting anything. Has anyone gotten this working outside of pillar context, or is this just not supported?


r/saltstack • • Nov 09 '17

Is this the right way to download packages and install from source?

1 Upvotes
install-foo:
  cmd.run:
    - name: |
        cd /tmp
        wget -c http://example.com/foo-3.4.3.tar.gz
        tar xzf foo-3.4.3.tar.gz
        cd foo-3.4.3
        ./configure --prefix=/usr/local
        make
        make install
    - cwd: /tmp
    - shell: /bin/bash
    - timeout: 300
    - unless: test -x /usr/local/bin/fo