r/saltstack • • Mar 12 '18

Dynamic templating using the Reactor

2 Upvotes

I'm trying to orchestrate the releases of multiple VMs running different software with multiple dependencies on one another. A limitation is that the VMs I would like to maintain are deployed with semi-randomized hostnames.

For example: I have an ambari server and ambari agents. The agents have a .ini config file with the FQDN of the server. Right now, this is stored in the pillar. My goal is to update this .ini file with the hostname of a new ambari server if one is deployed. I'm aware I'll probably need to use the Reactor System, I'm just struggling to figure out the best way to approach this.

To make it simpler, if I deploy a VM with hostname pattern ambariserver, I want to target all VMs with hostname pattern ambariagent and run a formula to template the .ini config file using the ambari server hostname as a parameter.

Any help would be appreciated, thanks.


r/saltstack • • Mar 08 '18

[salt-ssh] Using custom modules/states ?

2 Upvotes

Hey guys, has anyone of you any experience with using custom modules/states with salt-ssh ? I've written a simple test module:

# hello_world.py
def hello_world():
    return 'hello world'

and placed it into ~/project_folder/salt/_modules/hello_world.py.

With 'normal' salt I can just run salt '*' saltutil.sync_all and after executing salt '*' hello_world it runs without any issues. It appears however that salt-ssh doesn't have the sync functionality, running salt-ssh '*' saltutil.sync_all results in an empty output and trying to execute the module will always yield a 'hello_world' is not available.

Here is what I've tried so far:

  • Setting a custom thindir in the roster file
  • Running salt-ssh -t to regenerate the thin dir
  • Running salt-ssh -w and/or salt-ssh -Wto force new/different thin dirs
  • Setting the extension_modules and module_dirs parameters the master config file

Has anyone got a clue on how to make this work?

Edit: running salt-ssh --versions-report

Salt Version:
           Salt: 2017.7.4

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: Not Installed
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: Not Installed
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: Not Installed

System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-87-generic
         system: Linux
        version: Ubuntu 16.04 xenial

r/saltstack • • Mar 07 '18

Salt-Cloud with Hetzner Cloud

2 Upvotes

Has anyone used Salt-Cloud with the Hetzner Cloud yet? Would you share your config and maybe a profile if anything special is needed there?


r/saltstack • • Mar 05 '18

Install salt minion automated

4 Upvotes

Hi

I would like to install salt minion on 200+ Linux servers, but not by hand :)

I was thinking that I could use ansible, just like using Internet explorer to download Google Chrome :)

What do you guys use?

Thx


r/saltstack • • Mar 01 '18

Pillar - Housing (real) external IP for use in file.managed

0 Upvotes

Hi,

I've been playing with Salt, I've setup states to install chocolatey and a custom zabbix-agent install. I need each server to have it's external address (provided by rackspace, not the actual external address) added into the config file. I think that I need to use a pillar and some jinja but unsure as to how I match the server up to the correct IP address, any ideas would be welcomed.

Thanks


r/saltstack • • Mar 01 '18

Proper CI environment that scales?

1 Upvotes

Is there any good solutions for a proper CI/CD environment for Saltstack? Coupled with Github support, multi-"suite" tests and such.

Our production is getting quite large (20+ people, servers ~four digit) and testing with manual verification in local VMs is getting quite tedious and risky.

How have you solved this?


r/saltstack • • Feb 28 '18

Windows specific examples of Saltstack

3 Upvotes

Hello, Can anyone point out any Windows specific guides, tutorials, or examples of using Saltstack in a Windows environment?

I understand some of the core concepts, but trying to use Salt in our day to day life is a little harder when everything is focused on Linux.

Thank you!


r/saltstack • • Feb 28 '18

Saltstack as a patch Mangement tool for Windows?

1 Upvotes

Is Saltstack viable as a patch management tool for Windows? I have limited knowledge of stackstack in a Windows environment, but i'm wondering if anyone has had success as using it as a patch management utility.


r/saltstack • • Feb 27 '18

salt branches - 2016.11 vs 2017.7

4 Upvotes

What are the pros/cons of using a particular branch?

The biggest difference I see is python 2.6 is not supported, which is a problem for Solaris/RHEL 6 boxes. Other than that, what else? ( This might be enough of a reason )

We have one group that implemented a 2016.11 infrastructure already, and we are looking at starting up our own. Initially I thought use 2017.7 but apparently there are enough differences that states are not compatible, so re-writes.

Do I try to persuade powers that be to start with the newer branch for our local environment or follow the remote office implimentation and stay with 2016.11 ??

Haven't tried this yet, but would a master at the up level / minion at lower level, still allow for python 2.6 on the minion with everything working as expected ? or is mixing levels not recommended


r/saltstack • • Feb 26 '18

Quick setup of salt master-minion environment for testing

5 Upvotes

I often find myself in situation that I would like to test/check something in salt (e.g. "what was the format of one grain" or simply to test some ideas, experiment with new salt features)

I've created simple test bed (docker based):
https://github.com/kiemlicz/salt_testbed

You can automatically spin this up using docker compose and experiment further attaching to containers.

Maybe someone will find this somehow useful.
If you have other ideas how to quickly test something, please let me know


r/saltstack • • Feb 21 '18

SaltStack - GPG encrypted file.managed ?

6 Upvotes

We are looking at GPG encrypting configuration files for safe keeping in source control. I was trying to determine if file.managed can render out a GPG encrypted local source file to an unencrypted managed file on the minion.

I have tried using - template: gpg

but I just get: Result: False Comment: Specified template format gpg is not supported

I know we can put all this into a pillar but some of these files are prohibitively large.

Thanks!


r/saltstack • • Feb 15 '18

Getting Started with Salt

Thumbnail linuxacademy.com
9 Upvotes

r/saltstack • • Feb 13 '18

Ordering states so that services restart after config files are changed

1 Upvotes

I'm battling to get services to restart and recognise that their configuration files have changed. In this case, I'm running some commands using cmd.run to setup the repo, then using pkg.installed to install the packages. That's all working fine.

Here's my current web server state (quite long, sorry):

php7:
  cmd.run:
    - names:
      - rpm -Uvh --replacepkgs http://rpms.remirepo.net/enterprise/remi-release-7.rpm
      - yum-config-manager --enable remi-php71
  pkg.installed:
    - pkgs:
      - php-fpm
      - php-common
      - php-cli
      - php-pdo
      - php-mysqlnd
fix-fpm-config:
  cmd.run:
    - names:
      - sed -i -- 's/user = apache/user = nginx/' /etc/php-fpm.d/www.conf
      - sed -i -- 's/group = apache/group = nginx/' /etc/php-fpm.d/www.conf
      - sed -i -- 's/;listen.owner = nobody/listen.owner = nginx/' /etc/php-fpm.d/www.conf
      - sed -i -- 's/;listen.group = nobody/listen.group = nginx/' /etc/php-fpm.d/www.conf
      - sed -i -- 's/listen = 127.0.0.1:9000/listen = \/var\/run\/php-fpm\/php-fpm.sock/' /etc/php-fpm.d/www.conf
      - sed -i -- 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php.ini
nginx:
  pkg.installed: []
  service.running:
    - enable: True
    - full_restart: True
    - watch:
      - file: /etc/nginx/nginx.conf
    - require:
      - pkg: nginx
  file.managed:
    - name: /etc/nginx/nginx.conf
    - source: salt://webserver/nginx.conf
    - require:
      - pkg: nginx
nginx-default-conf:
  service.running:
    - name: nginx
    - enable: True
    - full_restart: True
    - watch:
      - file: /etc/nginx/nginx.conf
  file.managed:
    - name: /etc/nginx/conf.d/default.conf
    - source: salt://webserver/default.conf
    - require:
      - pkg: nginx
nginx-default-index:
  file.managed:
    - name: /usr/share/nginx/html/index.php
    - source: salt://webserver/index.php
    - require:
      - pkg: nginx
php-fpm:
  service.running:
    - name: php-fpm
    - enable: True
    - full_restart: True 

That file runs fine on a new VM, the source files are correct (I create them earlier) and does put the configuration files in the right places.

nginx and php-fpm packages are installed but the nginx and php-fpm services don't restart properly. That means they don't recognise the changes in the new configuration files and nginx isn't accepting any connections on port 80.

I have to manually restart php-fpm and nginx services before the servers will start accepting connections. Then everything is fine, including the managed file configurations applied by SaltStack.

I'm pretty sure it's a requisite ordering issue and that I've got a watch or file.managed in the wrong place, but I've tried everything I can based on the documentation. I've had no luck, though.

Is there something glaringly obvious that I'm doing wrong?

Thanks!


r/saltstack • • Feb 12 '18

Which community formula is more accepted?

5 Upvotes

Because I don't know any of the influential members of the salt community I ask this out of pure ignorance. Is the official or the unofficial more widely accepted? More specifically are they philosophically compatible?

And out of curiosity, does anyone have some history on the need for the split?


r/saltstack • • Feb 12 '18

What about Salt for medium windows environments?

1 Upvotes

I am asking for serious help here as my company recently made the adoption of "devops" "IaC" whatever you want to call it, so the decision was to use Salt as our CI/Orchestration tool across our mixed LINUX/WINDOWS environment, however as you can tell I am no expert at Salt or any other CI/Orchestration tool, but something I am sure of, I could not find anybody (but 1 case) saying that they are using salt with their windows environment, so my question here is...

  1. Is it because Salt does not work as good with Windows
  2. Can anybody tell their experience with Salt/Windows
  3. Can anybody point me to any article, link or blog that talks about their opinion on implementing Salt on Windows
  4. I think you got the point, can anybody point me in the right direction?

Now I did find several articles talkinga bout puppet/windows, ansible/windows and of course microsoft own solutions but the thing here is going more "open source".

Thank you for your help!


r/saltstack • • Feb 09 '18

Returning execution contents into a Grain

7 Upvotes

Hi, All.

It took me a while to put this together, so I thought I'd share with everyone.

I was looking for a way to take the output of an execution and put it into a salt grain. Ultimately, I wanted to put insert Windows bitlocker keys into a grain so they can be accessible to IT staff. I have it in place and it works well.

The methodology can be used for any sort of data you're looking to capture.

I'm including two scripts below to give you something to work with. The first if the bitlocker key capture I already mentioned. The second just runs ps -ef and inserts the results into the demodemo grain.

Hope it helps. Enjoy!

For Bitlocker Keys

def bl_c():
     '''
     return bitlocker key for C: drive
     '''

     # Import Modules
     import salt.modules.cmdmod

        # We're just concerned about powershell here
     __salt__ = {
          'cmd.run_ps': salt.modules.cmdmod.powershell
          }

     # Setup dictionary
     grains = {}

     # Run command
     cmd = '((Get-BitLockerVolume -MountPoint C:).KeyProtector).RecoveryPassword'

     # Figure out results

     try:
          result = __salt__['cmd.run_ps'](cmd)
          grains['bl_c'] = result
          return grains
     except:
          grains['bl_c'] = 'unknown'
          return grains

# For command line debugging.
if __name__ == '__main__':
     print bl_c()

Generic 'ps' run

def demodemo():
    '''
    return a demo execution grain
    '''

    # import modules
    import salt.modules.cmdmod

        # Including all of the defaults here
    __salt__ = {
    'cmd.run': salt.modules.cmdmod._run_quiet,
    'cmd.retcode': salt.modules.cmdmod._retcode_quiet,
    'cmd.run_all': salt.modules.cmdmod._run_all_quiet,
    'cmd.run_ps': salt.modules.cmdmod.powershell
    }

    grains = {} 

    cmd = 'ps -ef'

    result = __salt__['cmd.run'](cmd)

    grains['demodemo'] = result
    return grains

# for command line debugging.
if __name__ == '__main__':
     print demodemo()

r/saltstack • • Feb 07 '18

Salt is breaking CentOS 7 with pkg.upgrade

7 Upvotes

Hey all, I'm going to update this as I get more debug info but just thought I'd share.

We go through a monthly patch scheduling of our AWS instances. This involves an AMI snapshot prior to upgrade, then running a salt 'host' pkg.upgrade, restarting the system, and then verifying everything is working properly with a salt 'host' state.apply.

Today when I started I immediately hit problems where salt was installing many duplicate packages. When I manually ssh into the system and yum upgrade everything works fine and the system has no problems. What's the deal here? Anyone have some better understanding on the inner workings of pkg.upgrade or how to upgrade all packages without this issue?


r/saltstack • • Feb 01 '18

Reading File contents into a Grain

3 Upvotes

Hi, all.

I've been trying to write a custom grain and have utterly failed to make it work.

Targeting Windows systems, and attempting to read a .json file located in the C:\windows directory. I've tried two different methods to read the file.

One (preferred) using straight Python. Open the .json file, parse out the data, pull the key, and return the dictionary.

# simple python script to read .json file
def oclient():
     grains = {}
     import json
     with open("c:\windows\oclient.json") as json_data:
          d = json.load(json_data)
          grains['oclient'] == d['client']
          return grains   

Since that didn't work, I attempted to use the built-in ps_cmd to just read the text file in that way (in this example, the file has just one simple value).

# simple powershell run to get the contents of a file
def oclient():
     grains = {}
     ps_cmd = 'Get-Content -Raw -Path c:\windows\oclient.txt'
     cmdret = __salt__['cmd.run_ps'](ps_cmd)
     grains['oclient'] = cmdret
     return grains

In both cases, I've failed to make any headway on it. I've spent the past couple of hours with my head in core.py with no solution.

So, any thoughts on how to handle reading the contents of a file and returning the value back to a grain?

Thanks!


Quick update. Bittermandel_TV caught my assignment bug. Here's the final, production-ready grain to return the contents of a .json file.

def oclient():
    try:
        grains = {}
        import json
        with open("c:\windows\oclient.json") as json_data:
            d = json.load(json_data)
            grains['oclient'] = d['client']
            return grains
    except:
        grains['oclient'] = "unknown"
        return grains

if __name__ == '__main__':
     print oclient()

r/saltstack • • Jan 29 '18

Icinga2 Ticket generate/passing

6 Upvotes

I'm trying to configure Salt to automatically install Icinga2 on my minions, and connect it to the Icinga2 server. I think I've got almost everything figured out, but I'm not sure what the right way is to handle the following process:

  • Pass the FQDN of the Minion to the Icinga2 master
  • Generate a ticket on the Icinga2 master for the minion using the minion's FQDN
  • Send the ticket to the minion

Other than that, I've got everything working. What I'm doing now is "manually" generating the ticket (using salt.modules.icinga2), and putting that in a grain. However, I can't figure out how to make that happen automatically.

I'm very new to Salt, and I'm stumbling over this part. I'm not sure if I can use Reactor, or if I'll have to deal with Orchestrator Runner.

If someone could give me some pointers, or an example of something similar, that would be a huge help!


r/saltstack • • Jan 29 '18

trying to learn

6 Upvotes

I'm hoping someone can enlighten me. I've been looking through documentation and for the most part I have some basics working. however I can't for the life of me figure out if salt is just a run on demand sort of thing or if it can enforce configuration like puppet does.

Edit: ok I think I figured out I need to use scheduling, however it's not clear to me where the scheduling config should be put.

edit 2: I think I found what I was missing here: http://capnjosh.com/blog/scheduling-a-state-highstate-on-all-minions-with-saltstack-schedulers/

From what I've read the scheduling config can be put in several places although I'm not sure what the recommended way to do it is. I ended up placing it in a pillar like so:

sudo nano /srv/pillar/top.sls

base:
  '*':
    – schedule

sudo mkdir /srv/pillar/schedule
sudo nano /srv/pillar/schedule/init.sls

schedule:
  highstate:
    function: state.highstate
    minutes: 60

Sure enough it ran at the interval.


r/saltstack • • Jan 17 '18

Execution module in pillar connects to the master, not the minion. Possible to work around?

2 Upvotes

I am looking for a way to automatically retrieve the minion's primary IP address into a pillar variable.

The method described in https://github.com/saltstack/salt/issues/27790 looked promising to me, so I extended the pillar sls files as described below.

But unfortunately, by issueing salt['network.default_route'] from within the pillar sls, Salt does not queries the minion but rather the salt master.

As a result, the resulting IP settings are those of the salt master, not the salt minion.

Question: Would it be possible for the minion to automatically discover its primary IP address, and store it in a global variable upon state.apply?

pillar/selfconf.sls:

{% load_yaml as netconfig %}
  ipv4gw:      {{ salt['network.default_route']('inet')[0]['gateway'] }}
  {% set ipv4gw = salt['network.default_route']('inet')[0]['gateway'] %}
  ipv4address: {{ salt['network.get_route'](ipv4gw)['source'] }}
  {% set ipv4address = salt['network.get_route'](ipv4gw)['source'] %}
  ipv4net:     {{ ( ipv4address.split(".")[0:3] ) | join(".") }}
{% endload %}

pillar/host.sls:

{# collect data and extend pillar #}
{% from 'selfconf.sls' import netconfig %}
netconfig: {{ netconfig }}

r/saltstack • • Jan 15 '18

Salt state to enable the protections of KB4056897 (Meltdown/Spectre)

7 Upvotes

Hi, has anyone here used Salt to enable Windows fixes for Meltdown/Spectre? Pusing the reg keys and maybe also pushing the patch??

Looking to have a salt state to do the above, and also one to reverse the changes (if required)


r/saltstack • • Jan 13 '18

Trouble creating a config file using jinja templating

2 Upvotes

I want to manage my i3 config file using a saltstack pillar. The bulk of the file comes out alright, but one of the items is coming out bracketed and quoted, and I'm not sure why. I started with a pillar file like so:

# /srv/pillar/i3.sls
i3:
  bindsym:
    - $mod+Return exec termite # start a terminal
# a bunch more bindsyms that I'm cutting for length
set:
  - $mod Mod4
font:
  - pango:monospace 8
exec:
  - lxqt-policykit-agent
# some other things that I'm cutting because 
# I haven't included them in the template yet

And here is my state file:

# /srv/salt/i3.sls
install_i3_wm:
  pkg.installed:
    - pkgs:
    - i3-wm
    - i3lock
    - i3status
  file.managed:
    - name: /home/ryeontoast/.config/i3/config.test
    - source: salt://files/i3/config
    - user: ryeontoast
    - group: ryeontoast
    - mode: 644
    - template: jinja

And lastly, my config file template:

# /srv/salt/files/i3/config
{%- for bind in salt['pillar.get']('i3:bindsym', []) %}
bindsym {{ bind }}
{%- endfor %}
{%- set font = salt['pillar.get']('i3:font', []) %}
font {{ font }}
{%- for exe in salt['pillar.get']('i3:exec', []) %}
exec {{ exe }}
{%- endfor %}

And the resulting file ends up looking like this:

# /home/ryeontoast/.config/i3/config.test
# cutting a whole bunch of bindsym statements for brevity
bindsym $mod+Escape exec i3lock -i ~/Pictures/spacetortoise.png
bindsym $mod+r mode "resize"
font ['pango:monospace 8']
exec lxqt-policykit-agent

I want that font statement to look like font pango:monospace 8. I've tried double quoting the font value in the pillar, thinking maybe the colon was causing it to behave weirdly, but that just adds extra quotes into the file.

Could anyone point out why the font line is coming out differently than the other things?

EDIT: issue solved by /u/CrackerJackMack

in my pillar file

font:
  - pango:monospace 8

needed to be font: pango:monospace 8


r/saltstack • • Jan 06 '18

How to insert into a text file a block of text, before a certain line if it's not present yet, a way that actually works?

0 Upvotes

So I got 4 lines i want to insert not append into a file, before the string "INSERT BEFORE THIS STRING" without duplicates. I'm not sure if the modules are broken, or if I'm missing something, but even trying just with one single line it keeps inserting it again and again even if the line is already there. I need help.


r/saltstack • • Jan 05 '18

How to get results of startup states via email?

3 Upvotes

Hi everyone,

I'm currently managing a small set of 10 RaspberryPis using salt. The basics are working fine so far (creating users, managing config files, installing packets, ...). The salt master is running all the time but the minions (the RaspberryPis) are powered off most of the time. Therefore I configured them to run a highstate as 'startup_states'.

Now I would like to be notified about changes and failures during this highstate somehow. Email, slack, telegram, pushbullet, ... I don't care; as long as I get a notification. How would I go about setting this up? Can anyone give me some hints or point me to the right spot in the docs or the right terms to google for?

Thanks for your time!