Salt stack
Upcoming SlideShare
Loading in...5
×
 

Salt stack

on

  • 1,735 views

An introduction about how to use salt-stack and how to improve it developing new modules and states with Python

An introduction about how to use salt-stack and how to improve it developing new modules and states with Python

Statistics

Views

Total Views
1,735
Views on SlideShare
1,689
Embed Views
46

Actions

Likes
3
Downloads
26
Comments
0

2 Embeds 46

http://162.243.226.161 35
http://www.devopsroom.com 11

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Salt stack Salt stack Presentation Transcript

  • salt-stack Jose Ignacio Galarza @igalarzab
  • Index Why it’s so cool? How to use it? Developing for salt-stack
  • python + devops
  • salt-stack
  • infrastructure management
  • master
  • not a polling model, PUSHING
  • instructions send to the minions telling them what to do
  • PUB/SUB system on 4505 REP system on 4506
  • awesome diagram master SUB minion PUB minion REP minion
  • MessagePack to serialize the messages
  • everything is encrypted
  • it uses first public authentication keys for master needs to know public keys of the minions
  • then, it uses AES for communication * (symmetric, faster)
  • how to accept minion keys? $ salt-key Unaccepted Keys: minion_1 ! $ salt-key -a minion_1
  • let’s go! $ salt ‘*’ test.ping ! ! ! minion_1: True
  • minions
  • controlled machines
  • receive instructions via PUB/SUB ZeroMQ
  • masterless configuration * (salt-call)
  • modules
  • they provide the functionality
  • S3 pip apt ssh iptables pam nginx apache aliases mysql mount file upstart quota
  • execute them with the cli! $ salt ‘*’ cmd.run ‘ls /’ ... $ salt ‘*’ state.highstate ...
  • states
  • manage or configure in your hosts what to
  • salt-stack states are just DATA * usually in YAML
  • they usually map to module functions
  • understanding states ! ! ! ! ! ! ! ! ! /etc/init/nginx.conf: file: - managed - template: jinja - user: root - require: - pkg: nginx
  • nginx:   pkg.installed:     - name: nginx   file:     - managed     - name: /etc/init/nginx.conf     - source: salt://nginx.conf     - require:       - pkg: nginx service:     - running     - enable: True - watch:       - file: /etc/nginx/nginx.conf
  • there are a lot of directives require watch extend include
  • returners
  • save the minion output where to
  • mongo stdout redis SQL DB
  • renderers
  • language of the state configuration
  • YAML python JSON ...
  • grains
  • configuration of the machine * read-only data ** populated at the beginning
  • using grains... {% if grains['os'] == 'RedHat' %} httpd: pkg: - installed {% elif grains['os'] == 'Debian' %} apache2: pkg: - installed {% endif %}
  • list the grains $ salt ‘*’ grains.ls ... you can use them everywhere dev: ‘os:Debian’: - match: grain - python_server
  • pillar
  • think of pillar as a variable container
  • it’s data, just as same as the states
  • create a pillar of salt... {% if grains['os'] == 'RedHat' %} apache: httpd git: git {% elif grains['os'] == 'Debian' %} apache: apache2 git: git-core {% endif %}
  • and use it! apache: pkg: - installed - name: {{ pillar['apache'] }}
  • only salt-stack?
  • salt-bootstrap salt-cloud salt-vagrant halite
  • developing for salt-stack
  • developing modules
  • it’s like developing a normal python module! just create a file inside the _modules dir
  • every callable is exported* * (with some exceptions)
  • creating a module (for the pip-tools package) import re! ! import salt.utils! from salt.utils.decorators import memoize! ! REVIEW_RE = re.compile(‘([wd_-]+)==([d.]+) is available (you have ([d.]+))’)! ! ! @memoize! def _detect_install():! return salt.utils.which('pip-review')! ! ! def __virtual__():! return 'piputils' if _detect_install() else False!
  • creating a module (for the pip-tools package) ! def review(autoinstall=False):! command_ret = __salt__['cmd.run'](! 'pip-review {0}'.format('-a' if autoinstall else '')! )! ! packages = command_ret.split('n')! updates = {}! ! for package in packages:! match = REVIEW_RE.match(package)! if match:! name, old_v, new_v = match.groups()! updates[name] = (old_v, new_v)! ! return updates!
  • syncing the modules $ salt-call saltutil.sync_modules ... and use it! $ salt-call piptools.review machine: ---------- Jinja2: - 2.7.1 - 2.6
  • useful variables like: __salt__ __grains__ __outputter__
  • developing states
  • it’s (also) like developing a normal python module! just create a file inside the _states dir
  • every callable is exported* * (with some exceptions)
  • the renderer structure maps directly to the state python module
  • creating a state (for the pip-tools package) def keep_updated(name, min_version=None, max_version=None):! updatable_packages = __salt__['piptools.review']()! pkg_info = updatable_packages.get(name, None)! ! ret = {! 'name': name,! 'result': pkg_info is not None,! }!
  • creating a state (for the pip-tools package) ! if package_info:! ret['comment'] = 'Update {0} from {2} to {1}'.format(! name, *pkg_info! )! ret['changes'] = {!          name: {! 'old': package_info[1],! 'new': package_info[0]! }! }! else:! ret['comment'] = 'Inexistent package {0}'.format(name)! ! if __opts__['test']:! ret['result'] = None!     else:! pass # Perform the update! ! return ret!
  • mapping the file ! Jinja2: pip_package: - keep_updated - min_version: 1.0 # # # # maps maps maps maps to to to to "name" argument pip_package state keep_updated funct min_version arg
  • and that’s all! http://twitter.com/igalarzab http://github.com/igalarzab
  • questions?
  • thank you!