Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Getting the purpose of a node on webplatform.org
#!/usr/bin/env python
# /srv/salt/_grains/purpose.py
import socket
from string import digits
hostname = socket.gethostname().translate(None, digits)
def roles():
'''
Parse the host hostname and creates a list of roles
Based on the hostname (without domain name), should return:
salt -> grain:roles: ["salt"]
redis-jobs1 -> grain:roles: ["redis","jobs"]
'''
dataObject = {'roles': hostname.split('-')}
return dataObject
# /srv/salt/reactor/reactions/minion_start.sls
{#
# Sync grains, modules and al.
#
# This reactor isn’t run as a state,
# make sure this file is called from /etc/master.d/reactor.conf
# as a salt://salt/reactor/reaction/foo.sls instead.
#}
sync_all:
local.saltutil.sync_all:
- tgt: {{ data['id'] }}
- ret: syslog
# /srv/salt/reactor/reactions/new_minion.sls
{#
# Upgrade packages
#
# This reactor isn’t run as a state,
# make sure this file is called from /etc/master.d/reactor.conf
# as a salt://salt/reactor/reaction/foo.sls instead.
#
# data looks like:
#
# {id: 'foo', act: 'accept'};
#
# act key can be one of: [accept,pend,reject]
#
# `cmd.foo` and `local.foo` are aliases. In other words `cmd.pkg.upgrade`
# is the same as `local.pkg.upgrade`.
#}
{% if data['act'] == 'accept' %}
upgrade_pkgs:
cmd.pkg.upgrade:
- tgt: {{ data['id'] }}
- ret: syslog
send_ip_addrs:
local.mine.send:
- tgt: '*'
- arg:
- 'network.ip_addrs'
- ret: syslog
{% endif %}
{% if data['act'] == 'reject' %}
delete_ip_addrs:
cmd.mine.delete:
- tgt: '*'
- arg:
- 'network.ip_addrs'
{% endif %}
# /etc/salt/master.d/reactor.conf
#
# Idea is that if we send an event with a specific tag
# we can trigger a code update (via Salt Reactor) on
# the given project.
#
# The component that sends the event would be a script
# that checks for git changes on remote git repository.
#
# If there are changes on that remote, that script first
# the changes pulls them, and then sends the event.
#
# Reactor would then sync the code to their appropriate
# destination.
#
# Event examples:
#
# salt-call event.send wpdn/changes/app/www
#
# Where:
#
# - `wpdn/changesi` would be namespace for code changes
# - `app` would be the role to target (in roles grain)
# - `www` would be the code repo that had been updated
#
# Ref:
# * [Salt event module](http://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.event.html#module-salt.modules.event)
# * [Salt event system](http://docs.saltstack.com/en/latest/topics/event/index.html)
# * [Salt Reactor](http://docs.saltstack.com/en/latest/topics/reactor/)
#
reactor:
- 'salt/key':
- /srv/salt/reactor/reactions/new_minion.sls
- 'minion_start':
- /srv/salt/reactor/reactions/minion_start.sls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment