Commit 0621f13a authored by Vincent Mazenod's avatar Vincent Mazenod
Browse files

enhance vagrant slides

parent 0efcd0d9
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
* écrit en ruby * écrit en ruby
* [<i class="fa fa-github" aria-hidden="true"></i> hashicorp/vagrant](https://github.com/hashicorp/vagrant) * [<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é * se voit dans l'hyperviseur utilisé
...@@ -29,27 +29,48 @@ ...@@ -29,27 +29,48 @@
## Installation ## Installation
* gem pré-requis
gem install vagrant
* system ```
$ 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 ## Initialisation du projet
``` ```
mkdir project && cd project $ mkdir project && cd project
vagrant init $ vagrant init
``` ```
génère un Vagrantfile génère un Vagrantfile
``` ```ruby
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
config.vm.box = "base" config.vm.box = "base"
end end
``` ```
Beaucoup de commentaires ... laisser vous guidez Beaucoup de commentaires ... laisser vous guider
## Box ## Box
...@@ -61,44 +82,68 @@ Beaucoup de commentaires ... laisser vous guidez ...@@ -61,44 +82,68 @@ Beaucoup de commentaires ... laisser vous guidez
* nommage à la github "développeur/Box" * nommage à la github "développeur/Box"
``` ```
vagrant box add "ubuntu/xenial64" $ vagrant box add "ubuntu/xenial64"
vagrant box add "http://aka.ms/vagrant-win7-ie11" $ vagrant box add "http://aka.ms/vagrant-win7-ie11"
vagrant box list $ vagrant box list
vagrant box remove "ubuntu/xenial64" $ vagrant box remove "ubuntu/xenial64"
``` ```
* [Creating a Base Box](https://www.vagrantup.com/docs/boxes/base.html) * [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> 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) * [<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 init "ubuntu/bionic64"
vagrant ssh $ vagrant up #--provider=virtualbox
vagrant halt $ vagrant ssh
vagrant suspend $ vagrant halt
vagrant reload $ vagrant suspend
vagrant destroy #--force $ 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 ## 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| Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise32" config.vm.box = "hashicorp/precise32"
config.vm.provision "shell", path: "script.sh" config.vm.provision "shell", path: "script.sh"
...@@ -110,19 +155,41 @@ end ...@@ -110,19 +155,41 @@ end
via [ansible](ansible.html) via [ansible](ansible.html)
``` ```ruby
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise32"
config.vm.provision "shell", path: "script.sh"
config.vm.provision "ansible" do |ansible| config.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml" 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
end end
``` ```
### idéal pour tester les playbooks ### idéal pour tester les playbooks
## mapping de port
## vagrant pour tester apache ## 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!
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment