Browse Source

Init Vagrant docs

master
Siroco 7 months ago
parent
commit
2b047d0078
2 changed files with 171 additions and 1 deletions
  1. +32
    -1
      TERRAFORM/index.md
  2. +139
    -0
      VAGRANT/index.md

+ 32
- 1
TERRAFORM/index.md View File

@ -5,7 +5,7 @@ title: Basic Terraform
# ¿ Que es Terraform ?
Vamos a mirar de ir migrando nuestra infraestructura a Infrastructure as Code, es decir, abstraer nuestra infraestrutura para que a partir de recetas ejecutadas por aplicaciones como __Terraform__ podamos constuir, cambair o gestionar una infraestructura compleja de anera segura y replicarla con facilidad.
Vamos a mirar de ir migrando nuestra infraestructura a Infrastructure as Code (IaC), es decir, abstraer nuestra infraestrutura para que a partir de recetas ejecutadas por aplicaciones llamadas CCA [Continuous configuration automation], como __Terraform__, podamos constuir, cambair o gestionar una infraestructura compleja de anera segura y replicarla con facilidad.
En vez de configurar las máquinas y servicios a través de la interfaz de usuario, generamos ficheros que ejecutan esos códigos por nosotor_s.
@ -124,6 +124,35 @@ Aceptamos y limpiamos así el recurso de nuestro sistema
# Cloud Init - Crear esquemas para máquinas virtuales
Antes de empezar, un problema generalizado es que cuando el provider descarga las imagenes, les aplica permisos restrictivos como _root_ y no nos permite realizar los cambios oportunos en la imagen a partir con cloud-init. La solución es desactivar la opción _security_driver_ de la configuración de _qemu_.
$ vim /etc/libvirt/qemu.conf
```
# The default security driver is SELinux. If SELinux is disabled
# on the host, then the security driver will automatically disable
# itself. If you wish to disable QEMU SELinux security driver while
# leaving SELinux enabled for the host in general, then set this
# to 'none' instead. It's also possible to use more than one security
# driver at the same time, for this use a list of names separated by
# comma and delimited by square brackets. For example:
#
# security_driver = [ "selinux", "apparmor" ]
#
# Notes: The DAC security driver is always enabled; as a result, the
# value of security_driver cannot contain "dac". The value "none" is
# a special value; security_driver can be set to that value in
# isolation, but it cannot appear in a list of drivers.
#
#security_driver = "selinux"
security_driver = "none"
```
Ahora, deberemos definir nuestra plantilla _.tf_ de la manera siguiente:
...
# Links
@ -136,3 +165,5 @@ Aceptamos y limpiamos así el recurso de nuestro sistema
* https://github.com/fkpwolf/terraform-provider-libvirt
* https://medium.com/@yping88/building-and-installing-terraform-provider-for-libvirt-a08a29f93135
* https://cloudinit.readthedocs.io/en/latest/topics/boot.html
* https://github.com/dmacvicar/terraform-provider-libvirt/issues/546
* https://en.wikipedia.org/wiki/Infrastructure_as_code

+ 139
- 0
VAGRANT/index.md View File

@ -0,0 +1,139 @@
---
title: Vagrant
---
# About
Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the "works on my machine" excuse a relic of the past.
# Install from Hashicorp
Newer version
$ curl -O https://releases.hashicorp.com/vagrant/2.2.13/vagrant_2.2.13_x86_64.deb
$ sudo apt update
$ sudo apt install ./vagrant_2.2.13_x86_64.deb
$ vagrant --version
# Install from Debian repository
Older version but checked by Debian community
$ sudo apt install vagrant vagrant-libvirt
# Workdir
$ mkdir /tmp/vagrant_getting_started
$ cd /tmp/vagrant_getting_started
$ vagrant init generic/debian10
Read _Vagrantfile_ generated. You can configure your project
Maybe you need to install a provider for useit
# Provider
> While Vagrant ships out of the box with support for VirtualBox, Hyper-V, and Docker, Vagrant has the ability to manage other types of machines as well. This is done by using other providers with Vagrant.
You can configure diferent providers for build vagrant projects
Provider are configured like _plugins_
Show plugins availables:
$ vagrant plugin list
We will use _Libvirt_provider_
## Install libvirt provider
If you dont use repo packages, you need to install via source code libvirt-provider
From Hashicorp:
$ sudo apt-get build-dep vagrant ruby-libvirt
$ sudo apt-get install qemu libvirt-daemon-system libvirt-clients ebtables dnsmasq-base
$ sudo apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev
Install Vagrant provider like a plugin:
$ vagrant plugin install vagrant-libvirt
# Boxes
> These base images are known as "boxes" in Vagrant, and specifying the box to use for your Vagrant environment is always the first step after creating a new Vagrantfile.
When you install a new Vagrant project, you download a box from scratch
I you want to download boxes before:
$ vagrant box add generic/debian10
And then, when you create a new Vagrant project, edit Vagrantfile:
```
Vagrant.configure("2") do |config|
config.vm.box = "generic/debian10"
end
```
Find more boxes [https://vagrantcloud.com/boxes/search]
# Deploy Vagrant environment
Run:
$ vagrant up
Vagrant download box and start environment
You can access via SSH:
$ vagrant ssh
By default, Vagrant shares your project directory (the one containing the Vagrantfile) to the /vagrant directory in your guest machine.
# Write a provisioning script
You can configure bootstrap actions for this environament:
Create a bootstrap script named _bootstrap.sh_
```
#!/usr/bin/env bash
apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
rm -rf /var/www
ln -fs /vagrant /var/www
fi
```
Install Apache and create a symlink to our vagrant sync folder
On Vagrantfile:
```
Vagrant.configure("2") do |config|
config.vm.box = "generic/debian10"
config.vm.provision :shell, path: "bootstrap.sh"
end
```
Update our config or Provisioning
$ vagrant reload --provision
# Links
* https://learn.hashicorp.com/tutorials/vagrant/getting-started-index?in=vagrant/getting-started
* https://linuxize.com/post/how-to-install-vagrant-on-debian-10/
* https://github.com/vagrant-libvirt/vagrant-libvirt
# Next
* float https://git.autistici.org/ai3/float/-/blob/master/docs/quickstart.md

Loading…
Cancel
Save