====== Salt&Cloud-Init Presentation ====== ^ Documentation ^| ^Name:| Salt&Cloud-Init Presentation | ^Description:| Salt & Cloud-Init presentation | ^Modification date :|16/11/2018| ^Owner:|dodger@ciberterminal.net & warlock86@gmail.com| ^Notify changes to:|Owner and others| ^Tags:| | ====== Index ====== * Definición de la arquitectura * Ejemplos de comandos * Ejemplo de uso: Que centreon reinicie un windows cuando falla AS2 (ya está hecho) * Grains * Ejemplo de states * jinja * ¿salt-reactor? * ¿pillars? * Bonus track ====== Architecture ====== digraph init { server [shape=polygon,sides=6,label="New Server"]; master [shape=polygon,sides=6,label="salt-master"]; install [shape=parallelogram, label="Install salt-minion"]; minion [shape=polygon,sides=6,label="New Minion"]; final [shape=polygon,sides=6,color=green,label="Fully qualified Minion"]; { rank = same; master;final; } server->install; install->minion; minion->master [label="send new key"]; master->minion [label="Master accepts key"]; minion->final [color=red,label="FINAL"]; } ====== Ejemplos de comandos ====== See internal documentation: [[linux:salt-stack:useful_commands|Useful SALT commands (cheatsheet) and recipes]] ===== Real-life example: Centreon restarts windows on AS2 failure ===== @warlock86@gmail.com -> Eventhandler en centreon: /usr/lib/centreon/plugins/eventhandlers/salt_restart_as2.sh ====== Grains ====== Grains is an interface that provides information specific to a minion. The information available through the grains interface is static and gets loaded then the Salt minion starts. The information that Grains store could be about the running kernel, the operating system or other attributes of the running host. Gran information can be useful for targeting using the ''-G'' parameter. For example, to run a command in every Centos server, you can match the grain ''os'' and it'ts content ''Centos'' like this: salt -G 'os:Centos' test.ping To get a list of the available grains run: salt '*' grain.ls Or to get the content of the items: salt '*' grain.items There are two type of grains: * **Core**: that are those included by default by salt * **Custom**: that can be set by including them in ''/etc/salt/grains'' or the minion configuration. Here you can set something like the location, the virtualization cluster, the environment... Example: sudo salt -G 'location:equinix' test.ping Grains may also be used in jinja expressions. ====== States ====== This section is a document inclusion of [[linux:salt-stack:salt_states|SALT states]] {{page>linux:salt-stack:salt_states#quick_description}} ===== Examples of states ===== * [[linux:salt-stack:add_bofher_user|[SLS] Add bofher user]] * [[documentation:dba:redis:master_slave_deployment|Deploy a Master-Slave (pseudo)cluster of Redis]] * [[documentation:dba:postgres:deploy_new_instance_with_salt|Deploy new postgresql instance with salt-stack]] ===== top state ===== digraph top { compound=true; master [shape=polygon,sides=6,label="salt-master"]; final [shape=polygon,sides=6,color=red,label="Fully qualified Minion"]; install [shape=parallelogram, label="salt 'minion' state.apply"]; standard [shape=polygon,sides=6,color=green,label="Standardised Minion"]; master->install [label="run"]; install->final [label="target"]; subgraph cluster0 { top [shape=rect,label="top.sls"]; bash [shape=rect]; vim [shape=rect] tmux [shape=rect]; snmpd [shape=rect]; top->bash; top->vim; top->tmux; top->snmpd; } final->top [ltail=cluster0]; top->standard [color=red,label="Finished"]; } ===== Platataformation ===== digraph top { compound=true; master [shape=polygon,sides=6,label="salt-master"]; run [shape=parallelogram, label="salt 'minion' state.apply redis"]; standard [shape=polygon,sides=6,color=red,label="Standardised Minion"]; plataformed [shape=polygon,sides=6,color=green,label="Plataformed Minion"]; subgraph cluster0 { redis [shape=rect,label="redis.sls"]; config [shape=parallelogram, label="setup files"]; install [shape=parallelogram, label="install packages"]; service [shape=parallelogram, label="enable service"]; redis->config; redis->install; redis->service; } master->run [label="run"]; run->standard [label="target"]; standard->redis [ltail=cluster0]; redis->plataformed [label="becomes"]; } ====== Jinja ====== Jinja is a standard template language.\\ SaltStack support Jinja for templating :-) AND scripting\\ \\ Using Jinja we're able to use grains to match //whatever// and execute commands as consequence.\\ For example, install different package on different linux distros:\\ vimrc: pkg.installed: {% if grains['os'] == 'Ubuntu' or grains['os'] == 'Debian' %} - name: vim {% else %} - name: vim-enhanced {% endif %} file.managed: {% if grains['os'] == 'Ubuntu' or grains['os'] == 'Debian' %} - name: /etc/vim/vimrc {% else %} - name: /etc/vimrc {% endif %} - source: salt://bofher_defaults/vimrc ====== salt-reactor ====== The best example:\\ [[https://www.centreon.com/en/blog/tutorial-how-to-automate-your-centreon-monitoring-with-salt/]] ====== pillars ====== Quote from the [[https://docs.saltstack.com/en/latest/topics/tutorials/pillar.html|official documentation]]:\\ //Pillars are tree-like structures of data defined on the Salt Master and passed through to minions. They allow confidential, targeted data to be securely sent only to the relevant minion.// \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ ====== Bonus track ====== [[linux:cloud-init:project_clonewars|{{https://media.giphy.com/media/l0ExtDUaUDoQeTnag/giphy.gif|}}]]