From 0621f13a628f1dc8177280dee20b4c214f616d11 Mon Sep 17 00:00:00 2001 From: Vincent Mazenod <vmazenod@gmail.com> Date: Fri, 14 Dec 2018 21:24:08 +0100 Subject: [PATCH] enhance vagrant slides --- content/slides/cri/md/vagrant.md | 131 +++++++++++++++++++++++-------- 1 file changed, 99 insertions(+), 32 deletions(-) diff --git a/content/slides/cri/md/vagrant.md b/content/slides/cri/md/vagrant.md index bad6cb9..6b50e4c 100644 --- a/content/slides/cri/md/vagrant.md +++ b/content/slides/cri/md/vagrant.md @@ -11,9 +11,9 @@ * écrit en ruby * [<i class="fa fa-github" aria-hidden="true"></i> hashicorp/vagrant](https://github.com/hashicorp/vagrant) - * [<i class="fa fa-gavel" aria-hidden="true"></i> The MIT Licens](https://github.com/hashicorp/vagrant/blob/master/LICENSE) + * [<i class="fa fa-gavel" aria-hidden="true"></i> The MIT License](https://github.com/hashicorp/vagrant/blob/master/LICENSE) -* outil ligne de commande +* outil en ligne de commande * se voit dans l'hyperviseur utilisé @@ -29,27 +29,48 @@ ## Installation -* gem - gem install vagrant -* system +pré-requis + +``` +$ sudo apt install virtualbox +``` + +via gem + +``` +$ sudo apt install rubygems-integration +$ sudo gem install vagrant +``` + +via apt + +``` +$ sudo apt install vagrant +``` + +afficher la version de vagrant + +``` +$ vagrant --version +``` ## Initialisation du projet ``` -mkdir project && cd project -vagrant init +$ mkdir project && cd project +$ vagrant init ``` génère un Vagrantfile -``` +```ruby Vagrant.configure("2") do |config| config.vm.box = "base" end ``` -Beaucoup de commentaires ... laisser vous guidez +Beaucoup de commentaires ... laisser vous guider ## Box @@ -61,44 +82,68 @@ Beaucoup de commentaires ... laisser vous guidez * nommage à la github "développeur/Box" ``` -vagrant box add "ubuntu/xenial64" -vagrant box add "http://aka.ms/vagrant-win7-ie11" -vagrant box list -vagrant box remove "ubuntu/xenial64" +$ vagrant box add "ubuntu/xenial64" +$ vagrant box add "http://aka.ms/vagrant-win7-ie11" +$ vagrant box list +$ vagrant box remove "ubuntu/xenial64" ``` * [Creating a Base Box](https://www.vagrantup.com/docs/boxes/base.html) * [<i class="fa fa-github" aria-hidden="true"></i> veewee](https://github.com/jedi4ever/veewee) * [<i class="fa fa-github" aria-hidden="true"></i> How to Create a CentOS Vagrant Base Box](https://github.com/ckan/ckan/wiki/How-to-Create-a-CentOS-Vagrant-Base-Box) -## Premier pas +## cycle de vie ``` -vagrant up #--provider=virtualbox -vagrant ssh -vagrant halt -vagrant suspend -vagrant reload -vagrant destroy #--force +$ vagrant init "ubuntu/bionic64" +$ vagrant up #--provider=virtualbox +$ vagrant ssh +$ vagrant halt +$ vagrant suspend +$ vagrant reload +$ vagrant destroy #--force ``` -## shared folders +## points de montage -$ ll /vagrant +montage automatique de `.` dans `/vagrant` -montage automatique de . +``` +$ vagrant ssh +$ ll /vagrant +total 60 +drwxr-xr-x 1 vagrant vagrant 4096 Dec 14 19:46 ./ +drwxr-xr-x 24 root root 4096 Dec 14 19:47 ../ +drwxr-xr-x 1 vagrant vagrant 4096 Dec 14 19:46 .vagrant/ +-rw-r--r-- 1 vagrant vagrant 155 Dec 14 19:49 Vagrantfile +-rw------- 1 vagrant vagrant 44198 Dec 14 19:47 ubuntu-bionic-18.04-cloudimg-console.log +``` -autre possibilité à parir du vagrant file +autre possibilité à partir de `Vagrantfile` -config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig" +```ruby +Vagrant.configure("2") do |config| + ... + config.vm.provision "file", source: "~/.gitconfig", destination: "~/.gitconfig" + ... +end +``` ## provisioning -via un simple script +via l'entrée standard +```ruby +config.vm.provision "shell", inline: <<-SHELL + sudo apt install -y python openssh-server + SHELL ``` + +via un script + +```ruby Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise32" config.vm.provision "shell", path: "script.sh" @@ -110,19 +155,41 @@ end via [ansible](ansible.html) -``` +```ruby Vagrant.configure("2") do |config| - config.vm.box = "hashicorp/precise32" - config.vm.provision "shell", path: "script.sh" - config.vm.provision "ansible" do |ansible| ansible.playbook = "playbook.yml" + ansible.host_key_checking = false + ansible.playbook = "vault.yml" + ansible.extra_vars = { is_vagrant: true } + ansible.tags = ['initialize'] + ansible.skip_tags = ["vagrant_context"] + ansible.inventory_path = "./my-inventory" + ansible.raw_arguments = ["--private-key=~/.ssh/id/id_rsa"] + ansible.verbose = "vvv" end end ``` - ### idéal pour tester les playbooks -## mapping de port ## vagrant pour tester apache + +```ruby +Vagrant.configure("2") do |config| + config.vm.box = "ubuntu/bionic64" + config.vm.network "forwarded_port", guest: 80, host: 8000 + config.vm.provider "virtualbox" do |vb| + vb.gui = false + vb.memory = "4096" + end + config.vm.provision "shell", inline: <<-SHELL + sudo apt install -y apache2 + SHELL +end +``` + + +## conclusion + +### laissez un petit Vagrantfile dans vos playbooks est toujours une bonne idée! -- GitLab