Share
Embed
Ansible in action : le provisionning au bon niveau d'abstraction
Vous êtes DevOps dans l'âme ? ou vous montez un produit sur le cloud qui doit être scalable de base ? mais vous trouvez définitivement Chef ou Puppet trop complexes pour le service rendu, alors vous aller aimer Ansible !
Cette présentation sera l'occasion de découvrir, Ansible, un outil de provisioning avec le "juste niveau d'abstraction" au travers des bonnes pratiques et d'un réel retour d'expérience.
Olivier Girardot
April 16, 2014
Transcript
65 slides
-
@ogirardot #devoxxAnsible Qui, que, c’est qui parle ? Me, Myself
& I : • Dev (Java, Scala, Python) • Ops (Linux… what else ?) • Entrepreneur (LateralThoughts) • Consultant • … Olivier Girardot @ogirardot -
@ogirardot #devoxxAnsible Once upon a time… une startup 12+ changements
de stack du coté Infrastructure -
@ogirardot #devoxxAnsible Once upon a time… une startup Mutualisé VPS
Dédié x 3.5 changements de machines 12+ changements de stack du coté Infrastructure Django PostgreSQL PostGIS Memcached RabbitMQ Redis Apache Nginx FastCGI WSGI Gunicorn GeoDjango pg_dumpall Duplicity PAASs Play2 Play stage HAProxy -
@ogirardot #devoxxAnsible Soft/Hard - ware •On utilise des librairies, des
normes, des JSRs ! ! •On utilise des Caches, des Queues, des Databases -
@ogirardot #devoxxAnsible Soft/Hard - ware •On utilise des librairies, des
normes, des JSRs ! ! •On utilise des Caches, des Queues, des Databases Modulaire et Remplacable -
@ogirardot #devoxxAnsible Il faut pouvoir changer - Les besoins évoluent
- Les performances doivent s’améliorer - D’autres outils conviennent mieux - On doit utiliser moins d’argent/CPU/RAM - Le monitoring devient primordial -
@ogirardot #devoxxAnsible Il faut pouvoir changer - Les besoins évoluent
- Les performances doivent s’améliorer - D’autres outils conviennent mieux - On doit utiliser moins d’argent/CPU/RAM - Le monitoring devient primordial Tout devrait pouvoir changer sans être dur, imprévisible et dangereux -
@ogirardot #devoxxAnsible Provisionning Mettre en place de manière déterministe et
reproductible une machine Conduire le changement d’une machine Industrialiser l’ops -
@ogirardot #devoxxAnsible Quelles sont les options ?? Ansible Chef Puppet
Sous-Chef Chef Solo Fabric CfEngine 3 Blueprint LittleChef FoodCritic Capistrano Spatula Soloist Facter Sprinkle -
@ogirardot #devoxxAnsible Quelles sont les options ?? Ansible Chef Puppet
Sous-Chef Chef Solo Fabric CfEngine 3 Blueprint LittleChef FoodCritic Capistrano Spatula Soloist Facter Sprinkle -
@ogirardot #devoxxAnsible Ansible Basé sur SSH Simple - dès le
début Python YAML -
@ogirardot #devoxxAnsible patate # file:production [web] google.com 132.64.12.207 ! [dbservers]
www[01:50].example.com ! Inventory -
@ogirardot #devoxxAnsible patate # file:playbook.yml # file:production [web] google.com 132.64.12.207
! [dbservers] www[01:50].example.com ! Inventory -
@ogirardot #devoxxAnsible patate # file:playbook.yml - host: web # file:production
[web] google.com 132.64.12.207 ! [dbservers] www[01:50].example.com ! Inventory -
@ogirardot #devoxxAnsible patate # file:playbook.yml - host: web vars:… #
file:production [web] google.com 132.64.12.207 ! [dbservers] www[01:50].example.com ! Inventory -
@ogirardot #devoxxAnsible patate $ ansible-playbook -i production playbook.yml # file:playbook.yml
- host: web vars:… # file:production [web] google.com 132.64.12.207 ! [dbservers] www[01:50].example.com ! Inventory -
@ogirardot #devoxxAnsible patate $ ansible-playbook -i production playbook.yml # file:playbook.yml
- host: web vars:… # file:production [web] google.com 132.64.12.207 ! [dbservers] www[01:50].example.com ! Inventory $ ansible web -i production -a ‘ls -la /home/’ -
@ogirardot #devoxxAnsible Tasks •Définir l’état vers lequel la machine doit
être ! ! •Exécuter des commandes Tasks -
@ogirardot #devoxxAnsible tasks : - apt: pkg=ntp state=present Task installer
« ntp » - minimum Tasks -
@ogirardot #devoxxAnsible tasks : - name: "Installation du service ntp"
apt: pkg=ntp state=present user: root Task nommée en « root » Tasks -
@ogirardot #devoxxAnsible tasks : - name: "Installation du service ntp"
apt: pkg=ntp state=present sudo: true Task - avec « sudo » Tasks -
@ogirardot #devoxxAnsible tasks: - name: Create a directory for java
installations file: state=directory path=/usr/java/ ! - name: Create the default symlink for java 1.8 file: src=/usr/lib/jvm/jdk-8u20-ea-qui-rocks/jre/ state=link path=/usr/java/default Task - « file » Tasks -
@ogirardot #devoxxAnsible tasks: - name: install all basic survival packages
apt: pkg={{ item }} state=latest with_items: - git - nginx - postgresql - build-essential Boucle(s) Tasks -
@ogirardot #devoxxAnsible Handlers •Comme des tasks, mais appelés via «
notify » lors de changements Handlers -
@ogirardot #devoxxAnsible tasks: - name: Activates our virtualhost command: a2ensite
awesome-app notify: - restart apache ! handlers: - name: restart apache service: name=apache2 state=restarted Handlers Handlers Tasks -
@ogirardot #devoxxAnsible Variables •Facts : si elles viennent de la
machine cible ! •Variables, sinon : •En sortie de commandes/actions ou •En configuration de Tasks/Roles Variables -
@ogirardot #devoxxAnsible Facts •Tout le temps accessibles : "ansible_os_family": "Debian",
"ansible_pkg_mgr": "apt", "ansible_processor": [ "Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz" ], "ansible_processor_cores": 1, "ansible_processor_count": 1, "ansible_processor_threads_per_core": 1, "ansible_processor_vcpus": 1, "ansible_product_name": "VMware Virtual Platform », … Variables -
@ogirardot #devoxxAnsible # file:playbook.yml vars: http_port: 80 server_name: jememarre.com !
tasks - name: check web server is running command: curl -v ‘http://localhost:{{ http_port }}/’ Vars Variables Tasks -
@ogirardot #devoxxAnsible # file:tasks.yml - name: retrieve the list of
home directories command: ls /home register: home_dirs # home_dirs.stdout et stdout_lines ignore_errors: true ! - name: some action after ls action: … when: home_dirs|success Register variable Variables Tasks -
@ogirardot #devoxxAnsible # file:playbook.yml vars: http_port: 80 https_port: 443 tasks:
- name: install iptables template: src=iptables.j2 dest=/etc/sysconfig/iptables ! # file:iptables.j2 : # {{ ansible_managed }} -A INPUT -p tcp -m tcp --dport {{ http_port }} -j ACCEPT -A INPUT -p tcp -m tcp --dport {{ https_port }} -j ACCEPT Templates Variables Tasks -
@ogirardot #devoxxAnsible # file:playbook.yml - host: web vars: http_port: 80
max_clients: 200 tasks : - name: install packages apt: pkg={{ item }} state=latest with_items: - git - nginx notify: restart nginx ! - include: load_balancers.yml - include: webservers.yml - include: dbservers.yml Tous ensemble Variables Tasks Handlers Hosts Include -
@ogirardot #devoxxAnsible En résumé - Playbook •Inventory et Hosts (Host
Pattern) ! •Tasks = Etat cible ! •Handlers = Action lors de changements ! •Templates Jinja2 avec Variables/Facts ! •Include pour d’autres tasks/vars/… -
@ogirardot #devoxxAnsible ah oui et les Tags # file:tasks/main.yml -
name: install jdk apt: … tags: - java - tomcat $ ansible-playbook -i production -t tomcat site.yml -
@ogirardot #devoxxAnsible Modularisation : les Roles Role Tasks Variables Handlers
Templates Meta Dependencies Exemples : • Nginx • Java • <mon application backend> Files -
@ogirardot #devoxxAnsible Projet = Module(s) Application web servers db servers
search servers Inventory files Role web Role common Role database Role search site.yml -
@ogirardot #devoxxAnsible Convention over configuration project |—site.yml |—production |—staging |—dev
|—roles/ | |—webtier/ | | |—meta/ | | | |—main.yml | | |—vars/ | | |—tasks/ | | |—handlers/ | | |—templates/ | | |—files/ … -
@ogirardot #devoxxAnsible Avant - Après # file:playbook.yml - host: web
vars: http_port: 80 max_clients: 200 tasks : - name: install packages apt: pkg={{ item }} state=latest with_items: - git - nginx notify: restart nginx ! - include: load_balancers.yml - include: webservers.yml - include: dbservers.yml # file:site.yml - hosts : all roles : - common ! - hosts : webservers roles : - { role: webtier, port: 80, server_name: www.lateral-thoughts.com } -
@ogirardot #devoxxAnsible NEW : meta/main.yml # file:meta/main.yml --- dependencies: -
{ role: common } - { role: apache, port: 80 } - { role: postgres, dbname: blah, other_parameter: 12 } project |—site.yml |—production |—staging |—dev |—roles/ | |—webtier/ | | |—meta/ | | | |—main.yml | | |—vars/ | | |—tasks/ | | |—handlers/ | | |—templates/ | | |—files/ … -
@ogirardot #devoxxAnsible For devs : Vagrant Vagrant.configure("2") do |config| config.vm.provision
"ansible" do |ansible| ansible.playbook = "playbook.yml" end end -
@ogirardot #devoxxAnsible Ansible à la carte •Ansible Galaxy : •421
Roles réutilisables; •Librement utilisables; $ ansible-galaxy install <user>.<role> -
@ogirardot #devoxxAnsible Individuals and interactions Over ! Processes and Tools
c.f. Agile Manifesto -
@ogirardot #devoxxAnsible Ansible •un langage commun simple entre Dev et
Ops ! •Infrastructure as Code : Simple/Forkable ! •Zero mise en place du coté « cible » -
@ogirardot #devoxxAnsible Merci •Pour aller plus loin : ‣ https://github.com/leucos/ansible-tuto
‣ http://docs.ansible.com/ ‣ http://docs.ansible.com/modules_by_category.html -
@ogirardot #devoxxAnsible Crédits photo •https://www.flickr.com/photos/yetti/17446701/ •https://www.flickr.com/photos/schluesselbein/4157426778/in/ photostream/ •https://www.flickr.com/photos/nathanielstern/221228470 •http://upload.wikimedia.org/wikipedia/commons/8/87/Vagrant.png •https://galaxy.ansible.com
•http://julien.ponge.org/blog/scalable-and-understandable- provisioning-with-ansible-and-vagrant/ ! !