deployment ripetibili e automatizzati con salt
Post on 22-Jun-2015
371 Views
Preview:
DESCRIPTION
TRANSCRIPT
DEPLOYMENT RIPETIBILI EAUTOMATIZZATI CON
SALT
marcobadan.commarcobadan.com
SONDAGGIO!SONDAGGIO!
● Deployment manuale● Shell script● Fabric (e Fabtools)● Paver● Buildout● Puppet● Chef● Ansible● Salt● Altro
DELOYMENT RIPETIBILI DELOYMENT RIPETIBILI E AUTOMATIZZATIE AUTOMATIZZATI
Il deployment dovrebbe essere un'operazione:
● Ripetibile● Semplice● Trasparente● Sicura
(disaster recovery)● Veloce● Di routine
PERCHE SALT?PERCHE SALT?
● SEMPLICITÀ● ESECUZIONE PARALLELA● SICUREZZA
Autenticazione a chiave pubblica + crittografia AES (più veloce);Sono parte integrante di Salt.
● È PYTHON● VELOCE, FLESSIBILE, SCALABILE● APERTO
Licenza Apache 2.0● DOCUMENTAZIONE
metrica: transifex: 19.2K strings● COMUNITÀ● SUPPORTO COMMERCIALE
SALT IN BREVE 1/2SALT IN BREVE 1/2
un sistema distribuito per eseguire comandi e per ottenere informazioni su nodi remoti, singolarmente o in base a criteri di selezione arbitrari.
sudo salt '*' pkg.install openssl refresh=True;sudo salt '*' service.restart nginx;
● http://www.saltstack.com/salt-blog/2014/4/11/some-salt-for-that-heartbleed● http://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.service.html● http://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.aptpkg.html
Executing run on ['django_project']
django_project: ---------- libgnutls-openssl27: ---------- new: 2.12.23-12ubuntu2.1 old: libgnutls26: ---------- new: 2.12.23-12ubuntu2.1 old: openssl: ---------- new: 1.0.1f-1ubuntu2.2 old: 1.0.1f-1ubuntu2.1
django_project: TrueTrue
marco:~/ $marco:~/ $
marco:~/ $ sudo salt G 'os:Ubuntu' batchsize 25% test.ping
django_project Detected for this batch run
Executing run on ['django_project']
django_project: True
marco:~/ $
SALT IN BREVE 2/2SALT IN BREVE 2/2un sistema di gestione della configurazione, in grado di
mantenere nodi remoti in stati definiti (ad esempio facendo in modo che specifici packages siano installati e servizi specifici siano in esecuzione)
sudo salt 'django_project' state.highstate
MasterMasterUn demone centrale dal quale possono essere
lanciati i comandi ai vari minion in ascolto.
MinionMinionUn server su cui gira un demone che ascolta i
comandi del Master ed esegue i compiti richiesti.
STATESTATEUno struttura di dati definita da un ID univoco.Uno struttura di dati definita da un ID univoco.
Descrive uno o più stati del sistema.Descrive uno o più stati del sistema.
Per esempio: assicurare che un utente o una directory siano Per esempio: assicurare che un utente o una directory siano presenti, che una libreria sia installata, che un servizio sia attivo.presenti, che una libreria sia installata, che un servizio sia attivo.
Il cuore del sistema di Stati di Salt è l'SLS (SaLt State file) Il cuore del sistema di Stati di Salt è l'SLS (SaLt State file) L'SLS è una rappresentazione di uno stato desiderato del sistema.L'SLS è una rappresentazione di uno stato desiderato del sistema.
Contiene dati in un semplice formato (YAML).Contiene dati in un semplice formato (YAML).
In realtà I file SLS sono semplicemente dizionari, liste, stringhe, In realtà I file SLS sono semplicemente dizionari, liste, stringhe, numeri.numeri.
ALBERO DEGLI STATIALBERO DEGLI STATIin cui sono memorizzati i file SLS che compongono i possibili stati
dei minion.base: 'django_project': requirements.essentials django_project.django_project 'pippo*': users requirements.essentials nginx
'pippouno': projects.pippo_uno
'pippodue': projects.pippo_due
ssh_dir: file.directory: name: /home/django_user/.ssh user: django_user group: django_group mode: 700
ssh://git@bitbucket.org/my_company/django_project.git: git.latest: rev: master target: /opt/django_project/ user: django_user identity: /home/django_user/.ssh/django_project.id_rsa
Cosa manca?
PILLARPILLAR
Una coppia key-value da utilizzare per dati definiti dall'utente da rendere accessibili al minion.
Sono spesso usati per salvare e distribuire dati sensibili ai minion.
I pillar sono strutture ad albero di dati definiti sul Salt master e passati al minion. Essi consentono di passare dati confidenziali e/o specifici solo al
minion rilevante..
GRAINGRAINUna coppia key-value che contiene un fatto su un
sistema come l'hostname, l'indirizzo di rete.
marco:~/ $ sudo salt 'django_project' grains.items
django_project: biosreleasedate: 12/01/2006 biosversion: VirtualBox cpu_flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc rep_good nopl pni monitor ssse3 lahf_lm cpu_model: Intel(R) Core(TM) i5-2430M CPU @ 2.40GHz cpuarch: x86_64 defaultencoding: None defaultlanguage: None domain: fqdn: example fqdn_ip4: 127.0.1.1 fqdn_ip6: ::1 gpus: {'model': 'VirtualBox Graphics Adapter', 'vendor': 'unknown'} host: example hwaddr_interfaces: {'lo': '00:00:00:00:00:00', 'eth0': '08:00:27:4d:21:be'} id: django_project ip_interfaces: {'lo': ['127.0.0.1'], 'eth0': ['10.0.2.15']} ipv4: 10.0.2.15 127.0.0.1 ipv6: ::1 fe80::a00:27ff:fe4d:21be kernel: Linux kernelrelease: 3.13.0-27-generic localhost: example lsb_distrib_codename: trusty lsb_distrib_description: Ubuntu 14.04 LTS lsb_distrib_id: Ubuntu lsb_distrib_release: 14.04
manufacturer: innotek GmbH master: 192.168.1.100 mem_total: 490 nodename: example num_cpus: 1 num_gpus: 1 os: Ubuntu os_family: Debian osarch: amd64 oscodename: trusty osfinger: Ubuntu-14.04 osfullname: Ubuntu osrelease: 14.04 path: /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin productname: VirtualBox ps: ps -efHww pythonpath: /usr/bin /usr/lib/python2.7 /usr/lib/python2.7/plat-x86_64-linux-gnu /usr/lib/python2.7/lib-tk /usr/lib/python2.7/lib-old /usr/lib/python2.7/lib-dynload /usr/local/lib/python2.7/dist-packages /usr/lib/python2.7/dist-packages pythonversion: 2.7.6.final.0 saltpath: /usr/lib/python2.7/dist-packages/salt saltversion: 2014.1.4 saltversioninfo: 2014 1 4 serialnumber: 0 server_id: 192644357 shell: /bin/sh virtual: VirtualBox zmqversion: 4.0.4marco:django_project/ $
{% if grains['virtual'] != "VirtualBox" %}ssh://git@bitbucket.org/my_company/django_project.git: git.latest: rev: master target: {{ pillar['django']['root_path'] }} user: {{ pillar['sys_users']['user'] }} identity: /home/{{ pillar['sys_users']['user'] }}/.ssh/{{ pillar['django']['project_name'] }}.id_rsa {% endif %}
JINJA2!
{% set sites_available_path = '/etc/nginx/sites-available' %}{% set sites_enabled_path = '/etc/nginx/sites-enabled' %}
include: - nginx
django_project-nginx-conf: file.managed: - name: {{ sites_available_path }}/{{ pillar['nginx']['site_name'] }}.conf - source: salt://{{ pillar['nginx']['source_conf_file'] }} - template: jinja - user: www-data - group: www-data - mode: 755 - require: - pkg: nginx - file: {{ sites_available_path }}
# Symlink and thus enable the virtual hostdjango_project-enable-nginx: file.symlink: - name: {{ sites_enabled_path }}/{{ pillar['nginx']['site_name'] }}.conf - force: false - require: - file: django_project-nginx-conf - file: {{ sites_available_path }} - file: {{ sites_enabled_path }}
MASTER
MINIONDJANGO_PROJECT
STATES
gitfs_remotes: git://github.com/django_project/saltstates.git https://github.com/saltstackformulas/saltformula.git
ext_pillar: git: master https://domain.com/pillar.git
STATES
PILLARS
PILLARS
Esempi di Stati per Django
virtualenv_init: virtualenv.managed: name: {{ pillar['django']['virtualenv'] }} system_site_packages: False distribute: False user: {{ pillar['django']['user'] }} require: pkg: pythonvirtualenv pkg: pythondev pkg: postgresqlserverdev{{ pillar['postgresql']['version'] }} ...
virtualenv_setup: pip.installed: bin_env: {{ pillar['django']['virtualenv'] }} user: {{ pillar['django']['user'] }} requirements: {{ pillar['django']['root_path'] }}/requirements.txt no_chown: True
{% if grains['os'] == 'Ubuntu' and (grains['oscodename'] in ['precise','saucy','trusty']) %}postgresqlrepo: pkgrepo.managed: name: deb http://apt.postgresql.org/pub/repos/apt/ {{ grains['oscodename'] }}pgdg main key_url: http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc refresh: True{% endif %}
postgresql: pkg: installed name: postgresql{{ pillar['postgresql']['version'] }} service.running: watch: file: /etc/postgresql/{{ pillar['postgresql']['version'] }}/main/pg_hba.conf file: /etc/postgresql/{{ pillar['postgresql']['version'] }}/main/postgresql.conf require: pkg: postgresql
pg_hba.conf: file.managed: name: /etc/postgresql/{{ pillar['postgresql']['version'] }}/main/pg_hba.conf source: {{ pillar['postgresql']['pga_hba_conf_source'] }} user: postgres group: postgres mode: 644 require: pkg: postgresql
postgresql.conf: file.managed: name: /etc/postgresql/{{ pillar['postgresql']['version'] }}/main/postgresql.conf source: salt://postgresql/postgresql{{ pillar['postgresql']['version'] }}.conf user: postgres group: postgres mode: 644 template: jinja require: pkg: postgresql
project_init: cmd.script: - user: {{ pillar['sys_users']['user'] }} - template: jinja - require: - virtualenv: {{ pillar['django']['virtualenv'] }} - cwd: {{ pillar['django']['project_path'] }} - name: salt://projects/django_project/django_init.sh
{{ pillar['django']['project_path'] }}/{{ pillar['django']['project_name'] }}/.env: file.managed: - user: {{ pillar['sys_users']['user'] }} - source: salt://projects/chimera/production.env.jinja - mode: 400 - template: jinja
? ! Marco Badan
marcobadan.com
top related