SlideShare uma empresa Scribd logo
1 de 43
Baixar para ler offline
Create Development and Production
Environments with Vagrant
Brian P. Hogan
Twitter: @bphogan
Hi. I'm Brian.
— Programmer (http://github.com/napcs)
— Author (http://bphogan.com/publications)
— Engineering Technical Editor @ DigitalOcean
— Musician (http://soundcloud.com/bphogan)
Let's chat today! I want to hear what you're working on.
Roadmap
— Learn about Vagrant
— Create a headless Ubuntu
Server
— Explore provisioning
— Create a Windows 10 box
— Create boxes on
DigitalOcean
Disclaimers and Rules
— This is a talk for people new
to Vagrant.
— This is based on my personal
experience.
— If I go too fast, or I made a
mistake, speak up.
— Ask questions any time.
— If you want to argue, buy me
a beer later.
Vagrant is a tool to provision development environments in virtual
machines. It works on Windows, Linux systems, and macOS.
Vagrant
A tool to provision development environments
— Automates so!ware virtualization
— Uses VirtualBox, VMWare, or libvirt for
virtualization layer
— Runs on Mac, Windows, *nix
Vagrant needs a virtualization layer, so we'll use VirtualBox, from Oracle, cos it's free.
Vagrant uses SSH and if you're on Windows, you'll need PuTTY to log in, and PuTTYgen
to generate keys if you don't have public and private keys yet.
Simplest Setup - Vagrant and VirtualBox
— Vagrant: https://www.vagrantup.com
— VirtualBox: https://virtualbox.org
— On Windows
— PuTTY to log in to SSH
— PuTTYgen for SSH Keygeneration
Using Vagrant
$ vagrant init ubuntu/xenial64
Creates a config file that will tell Vagrant to:
— Download Ubuntu 16.04 Server base image.
— Create VirtualBox virtual machine
— Create an ubuntu user
— Start up SSH on the server
— Mounts current folder to /vagrant
Downloads image, brings up machine.
Firing it up
$ vagrant up
Log in to the machine with the ubuntu user. Let's demo
it.
Using the machine
$ vagrant ssh
ubuntu@ubuntu-xenial:~$
While the machine is provisioning let's look at the
configuration file in detail.
Configuration with Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
# ...
end
Vagrant automatically shares the current working directory.
Sharing a folder
config.vm.synced_folder "./data", "/data"
Forward ports from the guest to the host, for servers and
more.
Forwarding ports
config.vm.network "forwarded_port", guest: 3000, host: 3000
Creating a private network is easy with Vagrant. This
network is private between the guest and the host.
Private network
config.vm.network "private_network", ip: "192.168.33.10"
This creates a public network which lets your guest machine
interact with the rest of your network, just as if it was a real machine.
Bridged networking
config.vm.network "public_network"
The vm.privder block lets you pass configuration options for the provider. For
Virtualbox that means you can specify if you want a GUI, specify the amount of
memory you want to use, and you can also specify CPU and other options.
VirtualBox options
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = true
# Customize the amount of memory on the VM:
vb.memory = "1024"
end
We can set the name of the machine, the display name in Virtualbox, and the
hostname of the server. We just have to wrap the machine definition in a
vm.define block.
Naming things
Vagrant.configure("2") do |config|
config.vm.define "devbox" do |devbox|
devbox.vm.box = "ubuntu/xenial64"
devbox.vm.hostname = "devbox"
config.vm.network "forwarded_port", guest: 3000, host: 3000
devbox.vm.provider "virtualbox" do |vb|
vb.name = "Devbox"
vb.gui = false
vb.memory = "1024"
end
end
end
Provisioning
— Installing so!ware
— Creating files and folders
— Editing configuration files
— Adding users
Vagrant Provisioner
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y apache2
SHELL
Demo: Apache Web Server
— Map local folder to server's /
var/www/html folder
— Forward local port 8080 to
port 80 on the server
— Install Apache on the server
The Vagrantfile
Vagrant.configure("2") do |config|
config.vm.define "devbox" do |devbox|
devbox.vm.box = "ubuntu/xenial64"
devbox.vm.hostname = "devbox"
devbox.vm.network "forwarded_port", guest: 80, host: 8080
devbox.vm.synced_folder ".", "/var/www/html"
devbox.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y apache2
SHELL
end
end
Configuration Management with
Ansible
— Define idempotent tasks
— Use declarations instead of
writing scripts
— Define roles (webserver,
database, firewall)
— Use playbooks to provision
machines
An Ansible playbook contains all the stuff we want to do to
our box. This one just installs some things on our server.
Playbook
---
- hosts: all
become: true
tasks:
- name: update apt cache
apt: update_cache=yes
- name: install Apache2
apt: name=apache2 state=present
- name: "Add nano to vim alias"
lineinfile:
path: /home/ubuntu/.bashrc
line: 'alias nano="vim"'
When we run the playbook, it'll go through all of the steps and
apply them to the server. It'll skip anything that's already in place.
Playbook results
PLAY [all] *********************************************************************
TASK [Gathering Facts] *********************************************************
ok: [devbox]
TASK [update apt cache] ********************************************************
changed: [devbox]
TASK [install Apache2] *********************************************************
changed: [devbox]
TASK [Add nano to vim alias] ***************************************************
changed: [devbox]
PLAY RECAP *********************************************************************
devbox : ok=4 changed=3 unreachable=0 failed=0
Vagrant has support for playbooks with the ansible
provisioner.
Provisioning with Ansible
Vagrant.configure("2") do |config|
config.vm.define "devbox" do |devbox|
# ,,,
devbox.vm.provision :ansible do |ansible|
ansible.playbook = "playbook.yml"
end
end
end
Demo: Dev box
— Ubuntu 16.04 LTS
— Apache/MySQL/PHP
— Git/vim
The Vagrantfile has the same setup we had last time, but we'll use the ansible provisioner this
time. Ansible uses Python 2 but Ubuntu 16.04 doesn't include Python2. We can tell Ansible
to use Python 3 using the ansible_python_interpreter option for host_vars.
The Vagrantfile
Vagrant.configure("2") do |config|
config.vm.define "devbox" do |devbox|
devbox.vm.box = "ubuntu/xenial64"
devbox.vm.hostname = "devbox"
devbox.vm.network "forwarded_port", guest: 80, host: 8080
devbox.vm.synced_folder ".", "/var/www/html"
devbox.vm.provision :ansible do |ansible|
ansible.playbook = "playbook.yml"
ansible.host_vars = {
"devbox" => {"ansible_python_interpreter" => "/usr/bin/python3"}
}
end
end
end
Our playbook installs a few pieces of software including
Ruby, MySQL, Git, and Vim.
Playbook
---
- hosts: all
become: true
tasks:
- name: update apt cache
apt: update_cache=yes
- name: install required packages
apt: name={{ item }} state=present
with_items:
- apache2
- mysql-server
- ruby
- git-core
- vim
Vagrant Boxes
Get boxes from https://app.vagrantup.com
Useful boxes:
— scotch/box - Ubuntu 16.04 LAMP server ready to go
— Microso!/EdgeOnWindows10 - Windows 10 with
Edge browser
You can get more Vagrant boxes from the Vagrant Cloud web site, including boxes
that have a bunch of tooling already installed. You can even get a Windows box.
Demo: Windows Dev box
— Test out web sites on Edge
— Run so!ware that only works on Windows
— Run with a GUI
— Uses 120 day evaluation license, FREE and direct
from MS!
Here's how we'd configure a Windows box. We tell Vagrant we're using Windows instead
of Linux, and we specify that we're using WinRM instead of SSH. Then we provide
credentials.
The Vagrantfile
$ vagrant init
Vagrant.configure("2") do |config|
config.vm.define "windowstestbox" do |winbox|
winbox.vm.box = "Microsoft/EdgeOnWindows10"
winbox.vm.guest = :windows
winbox.vm.communicator = :winrm
winbox.winrm.username = "IEUser"
winbox.winrm.password = "Passw0rd!"
winbox.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "2048"
end
end
end
Vagrant and the Cloud
— Provides
— AWS
— Google
— DigitalOcean
— Build and Provision
Creating virtual machines is great, but you can use Vagrant to
build machines in the cloud using various Vagrant providers.
First, we install the Vagrant plugin. This will let us use a new
provider. We need an API key from DigitalOcean.
Demo: Web Server on DigitalOcean
Install the plugin
$ vagrant plugin install vagrant-digitalocean
Get a DigitalOcean API token from your account and
place it in your environment:
$ export DO_API_KEY=your_api_key
We'll place that API key in an environment variable
and reference that environment variable from our
config. That way we keep it out of configurations we
The config has a lot more info than before. We have to specify our SSH key for
DigitalOcean. We also have to specify information about the kind of server we want to set
up. We configure these through the provider, just like we configured Virtualbox.
Demo: Ubuntu on DigitalOcean
Vagrant.configure('2') do |config|
config.ssh.private_key_path = '~/.ssh/id_rsa'
config.vm.box = 'digital_ocean'
config.vm.box_url = "https://github.com/devopsgroup-
io/vagrant-digitalocean/raw/master/box/digital_ocean.box"
config.vm.define "webserver" do |box|
box.vm.hostname = "webserver"
box.vm.provider :digital_ocean do |provider|
provider.token = ENV["DO_API_KEY"]
provider.image = 'ubuntu-16-04-x64'
provider.region = 'nyc3'
provider.size = '512mb'
provider.private_networking = true
end # provider
end # box
end # config
We can also use provisioning to install stuff on the server.
Provisioning works too!
Vagrant.configure('2') do |config|
# ...
config.vm.define "webserver" do |box|
#...
provider.private_networking = true
box.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
ansible.host_vars = {
"webserver" => {"ansible_python_interpreter" => "/usr/bin/python3"}
}
end # ansible
end # box
end # config
Immutable infrastructure
— "Treat servers like cattle, not
pets"
— Don't change an existing
server. Rebuild it
— No "Snowflake" servers
— No "configuration dri#" over
time
— Use images and tools to
rebuild servers and redeploy
apps quickly
Spin up an infrastructure
— Vagrantfile is Ruby code
— Vagrant supports multiple
machines in a single file
— Vagrant commands support
targeting specific machine
— Provisioning runs on all
machines
We define a Ruby array with a hash for each server. The
hash contains the server info we need.
The Vagrantfile
Vagrant.configure('2') do |config|
machines = [
{name: "web1", size: "1GB", image: "ubuntu-16-04-x64", region: "nyc3"},
{name: "web2", size: "1GB", image: "ubuntu-16-04-x64", region: "sfo1"}
]
config.ssh.private_key_path = '~/.ssh/id_rsa'
config.vm.box = 'digital_ocean'
config.vm.box_url = "https://github.com/devopsgroup-io/vagrant-
digitalocean/raw/master/box/digital_ocean.box"
We then iterate over each machine and create a vm.define block. We assign the
name, the region, the image, and the size. We could even use this to assign a
playbook for each machine.
The Vagrantfile
Vagrant.configure('2') do |config|
# ...
machines.each do |machine|
config.vm.define machine[:name] do |box|
box.vm.hostname = machine[:name]
box.vm.provider :digital_ocean do |provider|
provider.token = ENV["DO_API_KEY"]
provider.image = machine[:image]
provider.size = machine[:size]
end
box.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
ansible.host_vars = {
machine[:name] => {"ansible_python_interpreter" => "/usr/bin/python3"}
}
end # ansible
end # box
end # loop
end # config
Usage
— vagrant up brings all machines online and provisions
them
— vagrant ssh web1 logs into the webserver
— vagrant provision would re-run the Ansible
playbooks.
— vagrant ssh web1 logs into the db server
— vagrant rebuild rebuilds machines from scratch and
reprovisions
— vagrant destroy removes all machines.
Puphet is a GUI for generating Vagrant configs with provisioning. Pick your
OS, servers you need,. programming languages, and download your bundle.
Puphet
https://puphpet.com/
Terraform, by Hashicorp, is the production solution for building out cloud environments and provisioning them. Docker
Machine can also spin up cloud environments and then install Docker on them, which you can use to host apps
hosted in containers. And Ansible, with a little bit of code and plugins, can create and provision your infrastructure.
Alternatives to Vagrant
— Terraform
— Docker Machine
— Ansible
Summary
— Vagrant controls virtual
machines
— Use Vagrant's provisioner to
set up your machine
— Use existing box images to
save time
— Use Vagrant to build out an
infrastructure in the cloud
Questions
— Slides: https://bphogan.com/presentations/
vagrant2017
— Twitter: @bphogan
— Say hi!
```

Mais conteúdo relacionado

Mais procurados

OpenNMS introduction
OpenNMS introductionOpenNMS introduction
OpenNMS introductionGuider Lee
 
44CON 2014 - Meterpreter Internals, OJ Reeves
44CON 2014 - Meterpreter Internals, OJ Reeves44CON 2014 - Meterpreter Internals, OJ Reeves
44CON 2014 - Meterpreter Internals, OJ Reeves44CON
 
PHPCon China 2016 - 從學徒變大師:談 Laravel 框架擴充與套件開發
PHPCon China 2016 - 從學徒變大師:談 Laravel 框架擴充與套件開發PHPCon China 2016 - 從學徒變大師:談 Laravel 框架擴充與套件開發
PHPCon China 2016 - 從學徒變大師:談 Laravel 框架擴充與套件開發Shengyou Fan
 
NGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX, Inc.
 
alphorm.com - Formation SQL Server 2012 (70-462)
alphorm.com - Formation SQL Server 2012 (70-462)alphorm.com - Formation SQL Server 2012 (70-462)
alphorm.com - Formation SQL Server 2012 (70-462)Alphorm
 
用 Go 語言實戰 Push Notification 服務
用 Go 語言實戰 Push Notification 服務用 Go 語言實戰 Push Notification 服務
用 Go 語言實戰 Push Notification 服務Bo-Yi Wu
 
PGEncryption_Tutorial
PGEncryption_TutorialPGEncryption_Tutorial
PGEncryption_TutorialVibhor Kumar
 
[1A7]Ansible의이해와활용
[1A7]Ansible의이해와활용[1A7]Ansible의이해와활용
[1A7]Ansible의이해와활용NAVER D2
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to AnsibleCoreStack
 
OpenNMS - My Notes
OpenNMS - My NotesOpenNMS - My Notes
OpenNMS - My Notesashrawi92
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction Robert Reiz
 
An Introduction to TensorFlow architecture
An Introduction to TensorFlow architectureAn Introduction to TensorFlow architecture
An Introduction to TensorFlow architectureMani Goswami
 
Desarrollo código mantenible en WordPress utilizando Symfony
Desarrollo código mantenible en WordPress utilizando SymfonyDesarrollo código mantenible en WordPress utilizando Symfony
Desarrollo código mantenible en WordPress utilizando SymfonyAsier Marqués
 
NGINX Unit: Rebooting our Universal Web App Server
NGINX Unit: Rebooting our Universal Web App ServerNGINX Unit: Rebooting our Universal Web App Server
NGINX Unit: Rebooting our Universal Web App ServerNGINX, Inc.
 
Networking in Docker Containers
Networking in Docker ContainersNetworking in Docker Containers
Networking in Docker ContainersAttila Kanto
 
Operating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with KubernetesOperating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with KubernetesJonathan Katz
 
Fairies, Fakers and Factories: Boost your tests with better test data
Fairies, Fakers and Factories: Boost your tests with better test dataFairies, Fakers and Factories: Boost your tests with better test data
Fairies, Fakers and Factories: Boost your tests with better test dataJaap Coomans
 
Sop makmal komputer 1
Sop makmal komputer 1Sop makmal komputer 1
Sop makmal komputer 1Kamal Salam
 

Mais procurados (20)

OpenNMS introduction
OpenNMS introductionOpenNMS introduction
OpenNMS introduction
 
44CON 2014 - Meterpreter Internals, OJ Reeves
44CON 2014 - Meterpreter Internals, OJ Reeves44CON 2014 - Meterpreter Internals, OJ Reeves
44CON 2014 - Meterpreter Internals, OJ Reeves
 
PHPCon China 2016 - 從學徒變大師:談 Laravel 框架擴充與套件開發
PHPCon China 2016 - 從學徒變大師:談 Laravel 框架擴充與套件開發PHPCon China 2016 - 從學徒變大師:談 Laravel 框架擴充與套件開發
PHPCon China 2016 - 從學徒變大師:談 Laravel 框架擴充與套件開發
 
NGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX: High Performance Load Balancing
NGINX: High Performance Load Balancing
 
alphorm.com - Formation SQL Server 2012 (70-462)
alphorm.com - Formation SQL Server 2012 (70-462)alphorm.com - Formation SQL Server 2012 (70-462)
alphorm.com - Formation SQL Server 2012 (70-462)
 
Ansible
AnsibleAnsible
Ansible
 
用 Go 語言實戰 Push Notification 服務
用 Go 語言實戰 Push Notification 服務用 Go 語言實戰 Push Notification 服務
用 Go 語言實戰 Push Notification 服務
 
PGEncryption_Tutorial
PGEncryption_TutorialPGEncryption_Tutorial
PGEncryption_Tutorial
 
[1A7]Ansible의이해와활용
[1A7]Ansible의이해와활용[1A7]Ansible의이해와활용
[1A7]Ansible의이해와활용
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
 
OpenNMS - My Notes
OpenNMS - My NotesOpenNMS - My Notes
OpenNMS - My Notes
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
 
An Introduction to TensorFlow architecture
An Introduction to TensorFlow architectureAn Introduction to TensorFlow architecture
An Introduction to TensorFlow architecture
 
Desarrollo código mantenible en WordPress utilizando Symfony
Desarrollo código mantenible en WordPress utilizando SymfonyDesarrollo código mantenible en WordPress utilizando Symfony
Desarrollo código mantenible en WordPress utilizando Symfony
 
NGINX Unit: Rebooting our Universal Web App Server
NGINX Unit: Rebooting our Universal Web App ServerNGINX Unit: Rebooting our Universal Web App Server
NGINX Unit: Rebooting our Universal Web App Server
 
Networking in Docker Containers
Networking in Docker ContainersNetworking in Docker Containers
Networking in Docker Containers
 
Operating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with KubernetesOperating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with Kubernetes
 
Introduction to Vagrant
Introduction to VagrantIntroduction to Vagrant
Introduction to Vagrant
 
Fairies, Fakers and Factories: Boost your tests with better test data
Fairies, Fakers and Factories: Boost your tests with better test dataFairies, Fakers and Factories: Boost your tests with better test data
Fairies, Fakers and Factories: Boost your tests with better test data
 
Sop makmal komputer 1
Sop makmal komputer 1Sop makmal komputer 1
Sop makmal komputer 1
 

Semelhante a Create Development and Production Environments with Vagrant

Vagrant - Version control your dev environment
Vagrant - Version control your dev environmentVagrant - Version control your dev environment
Vagrant - Version control your dev environmentbocribbz
 
Vagrant - Team Development made easy
Vagrant - Team Development made easyVagrant - Team Development made easy
Vagrant - Team Development made easyMarco Silva
 
Create your very own Development Environment with Vagrant and Packer
Create your very own Development Environment with Vagrant and PackerCreate your very own Development Environment with Vagrant and Packer
Create your very own Development Environment with Vagrant and Packerfrastel
 
Making Developers Productive with Vagrant, VirtualBox, and Docker
Making Developers Productive with Vagrant, VirtualBox, and DockerMaking Developers Productive with Vagrant, VirtualBox, and Docker
Making Developers Productive with Vagrant, VirtualBox, and DockerJohn Rofrano
 
Quick & Easy Dev Environments with Vagrant
Quick & Easy Dev Environments with VagrantQuick & Easy Dev Environments with Vagrant
Quick & Easy Dev Environments with VagrantJoe Ferguson
 
Vagrant introduction for Developers
Vagrant introduction for DevelopersVagrant introduction for Developers
Vagrant introduction for DevelopersAntons Kranga
 
Puppet and Vagrant in development
Puppet and Vagrant in developmentPuppet and Vagrant in development
Puppet and Vagrant in developmentAdam Culp
 
Vagrant-Overview
Vagrant-OverviewVagrant-Overview
Vagrant-OverviewCrifkin
 
NetDevOps Developer Environments with Vagrant @ SCALE16x
NetDevOps Developer Environments with Vagrant @ SCALE16xNetDevOps Developer Environments with Vagrant @ SCALE16x
NetDevOps Developer Environments with Vagrant @ SCALE16xHank Preston
 
Cooking Perl with Chef: Hello World Tutorial
Cooking Perl with Chef: Hello World TutorialCooking Perl with Chef: Hello World Tutorial
Cooking Perl with Chef: Hello World TutorialDavid Golden
 
Minicurso de Vagrant
Minicurso de VagrantMinicurso de Vagrant
Minicurso de VagrantLeandro Nunes
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierCarlos Sanchez
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Carlos Sanchez
 
Node.js, Vagrant, Chef, and Mathoid @ Benetech
Node.js, Vagrant, Chef, and Mathoid @ BenetechNode.js, Vagrant, Chef, and Mathoid @ Benetech
Node.js, Vagrant, Chef, and Mathoid @ BenetechChristopher Bumgardner
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)Soshi Nemoto
 

Semelhante a Create Development and Production Environments with Vagrant (20)

Vagrant - Version control your dev environment
Vagrant - Version control your dev environmentVagrant - Version control your dev environment
Vagrant - Version control your dev environment
 
Intro to vagrant
Intro to vagrantIntro to vagrant
Intro to vagrant
 
Vagrant - Team Development made easy
Vagrant - Team Development made easyVagrant - Team Development made easy
Vagrant - Team Development made easy
 
Create your very own Development Environment with Vagrant and Packer
Create your very own Development Environment with Vagrant and PackerCreate your very own Development Environment with Vagrant and Packer
Create your very own Development Environment with Vagrant and Packer
 
Making Developers Productive with Vagrant, VirtualBox, and Docker
Making Developers Productive with Vagrant, VirtualBox, and DockerMaking Developers Productive with Vagrant, VirtualBox, and Docker
Making Developers Productive with Vagrant, VirtualBox, and Docker
 
Vagrant For DevOps
Vagrant For DevOpsVagrant For DevOps
Vagrant For DevOps
 
Quick & Easy Dev Environments with Vagrant
Quick & Easy Dev Environments with VagrantQuick & Easy Dev Environments with Vagrant
Quick & Easy Dev Environments with Vagrant
 
Vagrant introduction for Developers
Vagrant introduction for DevelopersVagrant introduction for Developers
Vagrant introduction for Developers
 
Puppet and Vagrant in development
Puppet and Vagrant in developmentPuppet and Vagrant in development
Puppet and Vagrant in development
 
Vagrant-Overview
Vagrant-OverviewVagrant-Overview
Vagrant-Overview
 
Vagrant
VagrantVagrant
Vagrant
 
NetDevOps Developer Environments with Vagrant @ SCALE16x
NetDevOps Developer Environments with Vagrant @ SCALE16xNetDevOps Developer Environments with Vagrant @ SCALE16x
NetDevOps Developer Environments with Vagrant @ SCALE16x
 
Cooking Perl with Chef: Hello World Tutorial
Cooking Perl with Chef: Hello World TutorialCooking Perl with Chef: Hello World Tutorial
Cooking Perl with Chef: Hello World Tutorial
 
Vagrant
VagrantVagrant
Vagrant
 
Vagrant Up in 5 Easy Steps
Vagrant Up in 5 Easy StepsVagrant Up in 5 Easy Steps
Vagrant Up in 5 Easy Steps
 
Minicurso de Vagrant
Minicurso de VagrantMinicurso de Vagrant
Minicurso de Vagrant
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
 
Node.js, Vagrant, Chef, and Mathoid @ Benetech
Node.js, Vagrant, Chef, and Mathoid @ BenetechNode.js, Vagrant, Chef, and Mathoid @ Benetech
Node.js, Vagrant, Chef, and Mathoid @ Benetech
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)
 

Mais de Brian Hogan

Creating and Deploying Static Sites with Hugo
Creating and Deploying Static Sites with HugoCreating and Deploying Static Sites with Hugo
Creating and Deploying Static Sites with HugoBrian Hogan
 
Automating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleAutomating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleBrian Hogan
 
Getting Started Contributing To Open Source
Getting Started Contributing To Open SourceGetting Started Contributing To Open Source
Getting Started Contributing To Open SourceBrian Hogan
 
Rethink Frontend Development With Elm
Rethink Frontend Development With ElmRethink Frontend Development With Elm
Rethink Frontend Development With ElmBrian Hogan
 
Testing Client-side Code with Jasmine and CoffeeScript
Testing Client-side Code with Jasmine and CoffeeScriptTesting Client-side Code with Jasmine and CoffeeScript
Testing Client-side Code with Jasmine and CoffeeScriptBrian Hogan
 
FUD-Free Accessibility for Web Developers - Also, Cake.
FUD-Free Accessibility for Web Developers - Also, Cake.FUD-Free Accessibility for Web Developers - Also, Cake.
FUD-Free Accessibility for Web Developers - Also, Cake.Brian Hogan
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignBrian Hogan
 
Web Development with CoffeeScript and Sass
Web Development with CoffeeScript and SassWeb Development with CoffeeScript and Sass
Web Development with CoffeeScript and SassBrian Hogan
 
Building A Gem From Scratch
Building A Gem From ScratchBuilding A Gem From Scratch
Building A Gem From ScratchBrian Hogan
 
Intro To Advanced Ruby
Intro To Advanced RubyIntro To Advanced Ruby
Intro To Advanced RubyBrian Hogan
 
Turning Passion Into Words
Turning Passion Into WordsTurning Passion Into Words
Turning Passion Into WordsBrian Hogan
 
HTML5 and CSS3 Today
HTML5 and CSS3 TodayHTML5 and CSS3 Today
HTML5 and CSS3 TodayBrian Hogan
 
Web Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To ComplexWeb Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To ComplexBrian Hogan
 
Stop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard LibraryStop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard LibraryBrian Hogan
 
Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Brian Hogan
 
Make GUI Apps with Shoes
Make GUI Apps with ShoesMake GUI Apps with Shoes
Make GUI Apps with ShoesBrian Hogan
 
Story-driven Testing
Story-driven TestingStory-driven Testing
Story-driven TestingBrian Hogan
 

Mais de Brian Hogan (20)

Creating and Deploying Static Sites with Hugo
Creating and Deploying Static Sites with HugoCreating and Deploying Static Sites with Hugo
Creating and Deploying Static Sites with Hugo
 
Automating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleAutomating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and Ansible
 
Docker
DockerDocker
Docker
 
Getting Started Contributing To Open Source
Getting Started Contributing To Open SourceGetting Started Contributing To Open Source
Getting Started Contributing To Open Source
 
Rethink Frontend Development With Elm
Rethink Frontend Development With ElmRethink Frontend Development With Elm
Rethink Frontend Development With Elm
 
Testing Client-side Code with Jasmine and CoffeeScript
Testing Client-side Code with Jasmine and CoffeeScriptTesting Client-side Code with Jasmine and CoffeeScript
Testing Client-side Code with Jasmine and CoffeeScript
 
FUD-Free Accessibility for Web Developers - Also, Cake.
FUD-Free Accessibility for Web Developers - Also, Cake.FUD-Free Accessibility for Web Developers - Also, Cake.
FUD-Free Accessibility for Web Developers - Also, Cake.
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Web Development with CoffeeScript and Sass
Web Development with CoffeeScript and SassWeb Development with CoffeeScript and Sass
Web Development with CoffeeScript and Sass
 
Building A Gem From Scratch
Building A Gem From ScratchBuilding A Gem From Scratch
Building A Gem From Scratch
 
Intro To Advanced Ruby
Intro To Advanced RubyIntro To Advanced Ruby
Intro To Advanced Ruby
 
Turning Passion Into Words
Turning Passion Into WordsTurning Passion Into Words
Turning Passion Into Words
 
HTML5 and CSS3 Today
HTML5 and CSS3 TodayHTML5 and CSS3 Today
HTML5 and CSS3 Today
 
Web Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To ComplexWeb Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To Complex
 
Stop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard LibraryStop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard Library
 
Intro to Ruby
Intro to RubyIntro to Ruby
Intro to Ruby
 
Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7
 
Make GUI Apps with Shoes
Make GUI Apps with ShoesMake GUI Apps with Shoes
Make GUI Apps with Shoes
 
The Why Of Ruby
The Why Of RubyThe Why Of Ruby
The Why Of Ruby
 
Story-driven Testing
Story-driven TestingStory-driven Testing
Story-driven Testing
 

Último

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 

Último (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 

Create Development and Production Environments with Vagrant

  • 1. Create Development and Production Environments with Vagrant Brian P. Hogan Twitter: @bphogan
  • 2. Hi. I'm Brian. — Programmer (http://github.com/napcs) — Author (http://bphogan.com/publications) — Engineering Technical Editor @ DigitalOcean — Musician (http://soundcloud.com/bphogan) Let's chat today! I want to hear what you're working on.
  • 3. Roadmap — Learn about Vagrant — Create a headless Ubuntu Server — Explore provisioning — Create a Windows 10 box — Create boxes on DigitalOcean
  • 4. Disclaimers and Rules — This is a talk for people new to Vagrant. — This is based on my personal experience. — If I go too fast, or I made a mistake, speak up. — Ask questions any time. — If you want to argue, buy me a beer later.
  • 5. Vagrant is a tool to provision development environments in virtual machines. It works on Windows, Linux systems, and macOS. Vagrant A tool to provision development environments — Automates so!ware virtualization — Uses VirtualBox, VMWare, or libvirt for virtualization layer — Runs on Mac, Windows, *nix
  • 6. Vagrant needs a virtualization layer, so we'll use VirtualBox, from Oracle, cos it's free. Vagrant uses SSH and if you're on Windows, you'll need PuTTY to log in, and PuTTYgen to generate keys if you don't have public and private keys yet. Simplest Setup - Vagrant and VirtualBox — Vagrant: https://www.vagrantup.com — VirtualBox: https://virtualbox.org — On Windows — PuTTY to log in to SSH — PuTTYgen for SSH Keygeneration
  • 7. Using Vagrant $ vagrant init ubuntu/xenial64 Creates a config file that will tell Vagrant to: — Download Ubuntu 16.04 Server base image. — Create VirtualBox virtual machine — Create an ubuntu user — Start up SSH on the server — Mounts current folder to /vagrant
  • 8. Downloads image, brings up machine. Firing it up $ vagrant up
  • 9. Log in to the machine with the ubuntu user. Let's demo it. Using the machine $ vagrant ssh ubuntu@ubuntu-xenial:~$
  • 10. While the machine is provisioning let's look at the configuration file in detail. Configuration with Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "ubuntu/xenial64" # ... end
  • 11. Vagrant automatically shares the current working directory. Sharing a folder config.vm.synced_folder "./data", "/data"
  • 12. Forward ports from the guest to the host, for servers and more. Forwarding ports config.vm.network "forwarded_port", guest: 3000, host: 3000
  • 13. Creating a private network is easy with Vagrant. This network is private between the guest and the host. Private network config.vm.network "private_network", ip: "192.168.33.10"
  • 14. This creates a public network which lets your guest machine interact with the rest of your network, just as if it was a real machine. Bridged networking config.vm.network "public_network"
  • 15. The vm.privder block lets you pass configuration options for the provider. For Virtualbox that means you can specify if you want a GUI, specify the amount of memory you want to use, and you can also specify CPU and other options. VirtualBox options config.vm.provider "virtualbox" do |vb| # Display the VirtualBox GUI when booting the machine vb.gui = true # Customize the amount of memory on the VM: vb.memory = "1024" end
  • 16. We can set the name of the machine, the display name in Virtualbox, and the hostname of the server. We just have to wrap the machine definition in a vm.define block. Naming things Vagrant.configure("2") do |config| config.vm.define "devbox" do |devbox| devbox.vm.box = "ubuntu/xenial64" devbox.vm.hostname = "devbox" config.vm.network "forwarded_port", guest: 3000, host: 3000 devbox.vm.provider "virtualbox" do |vb| vb.name = "Devbox" vb.gui = false vb.memory = "1024" end end end
  • 17. Provisioning — Installing so!ware — Creating files and folders — Editing configuration files — Adding users
  • 18. Vagrant Provisioner config.vm.provision "shell", inline: <<-SHELL apt-get update apt-get install -y apache2 SHELL
  • 19. Demo: Apache Web Server — Map local folder to server's / var/www/html folder — Forward local port 8080 to port 80 on the server — Install Apache on the server
  • 20. The Vagrantfile Vagrant.configure("2") do |config| config.vm.define "devbox" do |devbox| devbox.vm.box = "ubuntu/xenial64" devbox.vm.hostname = "devbox" devbox.vm.network "forwarded_port", guest: 80, host: 8080 devbox.vm.synced_folder ".", "/var/www/html" devbox.vm.provision "shell", inline: <<-SHELL apt-get update apt-get install -y apache2 SHELL end end
  • 21. Configuration Management with Ansible — Define idempotent tasks — Use declarations instead of writing scripts — Define roles (webserver, database, firewall) — Use playbooks to provision machines
  • 22. An Ansible playbook contains all the stuff we want to do to our box. This one just installs some things on our server. Playbook --- - hosts: all become: true tasks: - name: update apt cache apt: update_cache=yes - name: install Apache2 apt: name=apache2 state=present - name: "Add nano to vim alias" lineinfile: path: /home/ubuntu/.bashrc line: 'alias nano="vim"'
  • 23. When we run the playbook, it'll go through all of the steps and apply them to the server. It'll skip anything that's already in place. Playbook results PLAY [all] ********************************************************************* TASK [Gathering Facts] ********************************************************* ok: [devbox] TASK [update apt cache] ******************************************************** changed: [devbox] TASK [install Apache2] ********************************************************* changed: [devbox] TASK [Add nano to vim alias] *************************************************** changed: [devbox] PLAY RECAP ********************************************************************* devbox : ok=4 changed=3 unreachable=0 failed=0
  • 24. Vagrant has support for playbooks with the ansible provisioner. Provisioning with Ansible Vagrant.configure("2") do |config| config.vm.define "devbox" do |devbox| # ,,, devbox.vm.provision :ansible do |ansible| ansible.playbook = "playbook.yml" end end end
  • 25. Demo: Dev box — Ubuntu 16.04 LTS — Apache/MySQL/PHP — Git/vim
  • 26. The Vagrantfile has the same setup we had last time, but we'll use the ansible provisioner this time. Ansible uses Python 2 but Ubuntu 16.04 doesn't include Python2. We can tell Ansible to use Python 3 using the ansible_python_interpreter option for host_vars. The Vagrantfile Vagrant.configure("2") do |config| config.vm.define "devbox" do |devbox| devbox.vm.box = "ubuntu/xenial64" devbox.vm.hostname = "devbox" devbox.vm.network "forwarded_port", guest: 80, host: 8080 devbox.vm.synced_folder ".", "/var/www/html" devbox.vm.provision :ansible do |ansible| ansible.playbook = "playbook.yml" ansible.host_vars = { "devbox" => {"ansible_python_interpreter" => "/usr/bin/python3"} } end end end
  • 27. Our playbook installs a few pieces of software including Ruby, MySQL, Git, and Vim. Playbook --- - hosts: all become: true tasks: - name: update apt cache apt: update_cache=yes - name: install required packages apt: name={{ item }} state=present with_items: - apache2 - mysql-server - ruby - git-core - vim
  • 28. Vagrant Boxes Get boxes from https://app.vagrantup.com Useful boxes: — scotch/box - Ubuntu 16.04 LAMP server ready to go — Microso!/EdgeOnWindows10 - Windows 10 with Edge browser
  • 29. You can get more Vagrant boxes from the Vagrant Cloud web site, including boxes that have a bunch of tooling already installed. You can even get a Windows box. Demo: Windows Dev box — Test out web sites on Edge — Run so!ware that only works on Windows — Run with a GUI — Uses 120 day evaluation license, FREE and direct from MS!
  • 30. Here's how we'd configure a Windows box. We tell Vagrant we're using Windows instead of Linux, and we specify that we're using WinRM instead of SSH. Then we provide credentials. The Vagrantfile $ vagrant init Vagrant.configure("2") do |config| config.vm.define "windowstestbox" do |winbox| winbox.vm.box = "Microsoft/EdgeOnWindows10" winbox.vm.guest = :windows winbox.vm.communicator = :winrm winbox.winrm.username = "IEUser" winbox.winrm.password = "Passw0rd!" winbox.vm.provider "virtualbox" do |vb| vb.gui = true vb.memory = "2048" end end end
  • 31. Vagrant and the Cloud — Provides — AWS — Google — DigitalOcean — Build and Provision
  • 32. Creating virtual machines is great, but you can use Vagrant to build machines in the cloud using various Vagrant providers. First, we install the Vagrant plugin. This will let us use a new provider. We need an API key from DigitalOcean. Demo: Web Server on DigitalOcean Install the plugin $ vagrant plugin install vagrant-digitalocean Get a DigitalOcean API token from your account and place it in your environment: $ export DO_API_KEY=your_api_key We'll place that API key in an environment variable and reference that environment variable from our config. That way we keep it out of configurations we
  • 33. The config has a lot more info than before. We have to specify our SSH key for DigitalOcean. We also have to specify information about the kind of server we want to set up. We configure these through the provider, just like we configured Virtualbox. Demo: Ubuntu on DigitalOcean Vagrant.configure('2') do |config| config.ssh.private_key_path = '~/.ssh/id_rsa' config.vm.box = 'digital_ocean' config.vm.box_url = "https://github.com/devopsgroup- io/vagrant-digitalocean/raw/master/box/digital_ocean.box" config.vm.define "webserver" do |box| box.vm.hostname = "webserver" box.vm.provider :digital_ocean do |provider| provider.token = ENV["DO_API_KEY"] provider.image = 'ubuntu-16-04-x64' provider.region = 'nyc3' provider.size = '512mb' provider.private_networking = true end # provider end # box end # config
  • 34. We can also use provisioning to install stuff on the server. Provisioning works too! Vagrant.configure('2') do |config| # ... config.vm.define "webserver" do |box| #... provider.private_networking = true box.vm.provision "ansible" do |ansible| ansible.playbook = "playbook.yml" ansible.host_vars = { "webserver" => {"ansible_python_interpreter" => "/usr/bin/python3"} } end # ansible end # box end # config
  • 35. Immutable infrastructure — "Treat servers like cattle, not pets" — Don't change an existing server. Rebuild it — No "Snowflake" servers — No "configuration dri#" over time — Use images and tools to rebuild servers and redeploy apps quickly
  • 36. Spin up an infrastructure — Vagrantfile is Ruby code — Vagrant supports multiple machines in a single file — Vagrant commands support targeting specific machine — Provisioning runs on all machines
  • 37. We define a Ruby array with a hash for each server. The hash contains the server info we need. The Vagrantfile Vagrant.configure('2') do |config| machines = [ {name: "web1", size: "1GB", image: "ubuntu-16-04-x64", region: "nyc3"}, {name: "web2", size: "1GB", image: "ubuntu-16-04-x64", region: "sfo1"} ] config.ssh.private_key_path = '~/.ssh/id_rsa' config.vm.box = 'digital_ocean' config.vm.box_url = "https://github.com/devopsgroup-io/vagrant- digitalocean/raw/master/box/digital_ocean.box"
  • 38. We then iterate over each machine and create a vm.define block. We assign the name, the region, the image, and the size. We could even use this to assign a playbook for each machine. The Vagrantfile Vagrant.configure('2') do |config| # ... machines.each do |machine| config.vm.define machine[:name] do |box| box.vm.hostname = machine[:name] box.vm.provider :digital_ocean do |provider| provider.token = ENV["DO_API_KEY"] provider.image = machine[:image] provider.size = machine[:size] end box.vm.provision "ansible" do |ansible| ansible.playbook = "playbook.yml" ansible.host_vars = { machine[:name] => {"ansible_python_interpreter" => "/usr/bin/python3"} } end # ansible end # box end # loop end # config
  • 39. Usage — vagrant up brings all machines online and provisions them — vagrant ssh web1 logs into the webserver — vagrant provision would re-run the Ansible playbooks. — vagrant ssh web1 logs into the db server — vagrant rebuild rebuilds machines from scratch and reprovisions — vagrant destroy removes all machines.
  • 40. Puphet is a GUI for generating Vagrant configs with provisioning. Pick your OS, servers you need,. programming languages, and download your bundle. Puphet https://puphpet.com/
  • 41. Terraform, by Hashicorp, is the production solution for building out cloud environments and provisioning them. Docker Machine can also spin up cloud environments and then install Docker on them, which you can use to host apps hosted in containers. And Ansible, with a little bit of code and plugins, can create and provision your infrastructure. Alternatives to Vagrant — Terraform — Docker Machine — Ansible
  • 42. Summary — Vagrant controls virtual machines — Use Vagrant's provisioner to set up your machine — Use existing box images to save time — Use Vagrant to build out an infrastructure in the cloud