Vagrant: Exemplos de Arquivos Vagrantfile provisionando o Apache HTTP server via arquivo Shell, Comandos e Ansible

= Exemplo 1 - Vagrantfile provisionando o Apache HTTP server via arquivo Shell=

Arquivo Vagrantfile

 * 1) -*- mode: ruby -*-
 * vi: set ft=ruby :

Vagrant.configure("2") do |config|

config.vm.box = "hashicorp-vagrant/centos-7.4"

config.vm.network "private_network", ip: "192.168.33.10" config.vm.hostname = "webserver1" config.vm.define "webserver"

config.vm.provider "virtualbox" do |vb| vb.gui = true vb.memory = "1024" end config.vm.provision "shell", path: "webserver.sh" end

Arquivo webserver.sh
echo "Instalando apache" yum -y install httpd
 * 1) !/usr/bin/env bash

= Exemplo 2 - Vagrantfile provisionando o Apache HTTP server via comandos=

Arquivo Vagrantfile

 * 1) -*- mode: ruby -*-
 * vi: set ft=ruby :

Vagrant.configure("2") do |config|

config.vm.box = "hashicorp-vagrant/centos-7.4"

config.vm.network "private_network", ip: "192.168.33.10" config.vm.hostname = "webserver2" config.vm.define "webserver"

config.vm.provider "virtualbox" do |vb| vb.gui = true vb.memory = "1024" end

config.vm.provision "shell", inline: <<-SHELL yum -y update yum -y install httpd SHELL end

= Exemplo 3 - Vagrantfile provisionando o Apache HTTP server via Ansible=

Arquivo Vagrantfile

 * 1) -*- mode: ruby -*-
 * vi: set ft=ruby :

Vagrant.configure("2") do |config|

config.vm.box = "hashicorp-vagrant/centos-7.4"

config.vm.network "private_network", ip: "192.168.33.10" config.vm.hostname = "webserver3" config.vm.define "webserver"

config.vm.provider "virtualbox" do |vb| vb.gui = true vb.memory = "1024" end

config.vm.provision "ansible" do |ansible| ansible.playbook = "webserver.yml" ansible.verbose = "vvv" end end

Arquivo webserver.yml
--- - hosts: all become: true tasks: - name: "Instala Apache" shell: "yum -y install httpd"

= Ver também =


 * Artigos sobre DevOps


 * Mais Artigos sobre Cloud / WebDev / Tecnologias