Last active
August 29, 2015 14:10
Revisions
-
renoirb revised this gist
May 4, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ # Getting the role list under SaltStack based on the instance name Idea is that once a VM is instantiated it knows what services he’ll handle. ## Canonical -
renoirb revised this gist
May 4, 2015 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ # Getting the role list under SaltStack based on the instance name ## Canonical * https://gist.github.com/WebPlatformDocs/563cb12326b92b22a452 * https://gist.github.com/renoirb/b2e0222ad52e5d453298 -
renoirb revised this gist
May 4, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ #!/usr/bin/env python # /srv/salt/_grains/purpose.py import socket from string import digits -
renoirb revised this gist
May 4, 2015 . 4 changed files with 89 additions and 19 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,22 +17,3 @@ def roles(): ''' dataObject = {'roles': hostname.split('-')} return dataObject This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ # /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 This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ # /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 %} This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ # /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 -
renoirb created this gist
Nov 7, 2014 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ #!/usr/bin/env python 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 def level(): ''' Returns environment level based on the host FQDN salt.staging.wpdn -> grains:level: "staging" redis-jobs1.staging.wpdn -> grains:level: "staging" memcache1.production.wpdn -> grains:level: "production" This function fills the grain with key "level", default value is "production" ''' dataObject = {} fqdn = socket.getfqdn() if 1 <= len(fqdn.split('.')): dataObject['level'] = fqdn.split('.')[1] else: dataObject['level'] = "production" return dataObject