Skip to content

Instantly share code, notes, and snippets.

@hemebond
hemebond / new_instance.sls.jinja
Created August 25, 2018 03:21
Reactor system for initialising new minions (jinja extensions just for formatting)
{#
Requires Salt 2016.11 as the syntax changes for these functions
https://docs.saltstack.com/en/2016.11/topics/orchestrate/orchestrate_runner.html
Using salt.function instead of salt.state for highstate because of bug https://github.com/saltstack/salt/issues/26448
#}
{% set tag = salt.pillar.get('event_tag') %}
{% set data = salt.pillar.get('event_data') %}
{# minion IDs start with a three-letter code that is their environment #}
@hemebond
hemebond / autoexec.cfg
Last active September 27, 2018 05:21
Quake configuration for rtlights editing
gl_finish 1
bind q "exec default.cfg"
bind e "exec rtlights.cfg"
@hemebond
hemebond / check_nginx.py
Last active January 31, 2018 04:04
Nginx Status monitoring plugin script
#!/usr/bin/env python3
"""
Parse the Nginx Status output and return as monitoring plugin data.
"""
import nagiosplugin
from http.client import HTTPConnection
@hemebond
hemebond / salt_python_renderer_example1.py
Created March 27, 2017 11:00
Render a YAML file using the Saltstack Python renderer
#!py
# test.sls
import yaml
def run():
config = {}
map_file = __salt__.cp.cache_file("salt://formula/map.yaml")
@hemebond
hemebond / icinga2_return.py
Last active July 1, 2017 05:28
Saltstack Icinga2 API returner
# -*- coding: utf-8 -*-
'''
Return salt data to Icinga2 via the API
The following fields can be set in the minion conf file::
icinga2.url (required)
icinga2.service (optional)
icinga2.username (optional)
icinga2.password (optional)
@hemebond
hemebond / salt_api_examples.rst
Last active March 3, 2017 01:21
Saltstack API (netapi) Examples

rest_cherrypy

First authenticate against the API:

curl -si $HOST:$CHERRY_PORT/login' -H 'Accept: application/json' -H 'Content-type: application/json' -d "{"username": "$USER", "password": "$PASS", "eauth": "pam"}"

Request data from Salt Mine using the token given by the login:

curl -sS -i -H "Accept: application/json" -H "Content-type: application/json" -H "X-Auth-Token: $TOKEN" -d "[{"username": "$USER", "password": "$PASS", "eauth": "pam", "client": "runner", "fun": "mine.get", "tgt": "*", "kwargs": {"tgt": "db9svc*", "fun": "grains.items"}}]" $HOST:$CHERRY_PORT
@hemebond
hemebond / __init__.py
Last active March 24, 2017 03:38
NSCA Saltstack Returner
'''
Return data to an NSCA server
This returner requires the following individual files
from the https://github.com/Yelp/send_nsca repo
* send_nsca/nagios.py
* send_nsca/nsca.py
Place those files, and this `__init__.py` file into your
state returners directory, e.g.:
@hemebond
hemebond / etc_salt_master.d_reactor.conf
Last active January 11, 2017 12:09
Sync grains every start and highstate once automatically.
reactors:
# Run this script every time an abc instance starts
- 'salt/minion/abc*/start':
- '/srv/salt/reactors/abc/start.sls'
# Run this script every time an abc instance returns from a job
- 'salt/job/*/ret/abc*':
- '/srv/salt/reactors/abc/ret.sls'
@hemebond
hemebond / awspsv.py
Last active March 24, 2019 20:31
A passive AWS EC2 wrapper for the salt-cloud profile function
#!/usr/bin/env python
# 2019-03-22 Updated to be compatible with Salt 2018.3.3
# Import python libs
import logging
import os.path
import time
import boto3
@hemebond
hemebond / 0_article.md
Last active March 13, 2022 11:51
A SaltStack AWS Auto Scaling Solution

A SaltStack AWS Auto Scaling Solution

Overview

The AWS Auto Scaling Goup, configured with a customised Cloud-Init file, sends a notification to an SNS Topic, which in turn passes it onto an SQS queue that the Salt Master is subscribed to. A Reactor watches for the auto scaling events and pre-approves the new minion based on its Auto Scaling group name and instance ID.

Salt Master Configuration