Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise32"
config.vm.provision "shell", path: "manifests/bootstrap.sh"
config.vm.provision "puppet" do |puppet|
puppet.manifest_file = "web.pp"
end
config.vm.define :web do |web_config|
web_config.vm.network "private_network", ip: "192.168.50.10"
end
end
bootstrap.sh:
#!/bin/sh
set -e -x
if which puppet > /dev/null ; then
echo "Puppet is already installed"
exít 0
fi
export DEBIAN_FRONTEND=noninteractive
sudo wget -q http://apt.puppetlabs.com/puppetlabs-release-pc1-precise.deb -O /tmp/puppetlabs.deb
sudo dpkg -i /tmp/puppetlabs.deb > /dev/null
rm /tmp/puppetlabs.deb
sudo apt-get update
echo Installlng puppet
sudo apt-get install -y puppet
echo "Puppet installed!"
web.pp:
exec { "apt-update":
command => "/usr/bin/apt-get update"
}
package { ["openjdk-7-jre", "tomcat7", "mysql-server"]:
ensure => installed,
require => Exec["apt-update"]
}
service { "tomcat7":
ensure => running,
enable => true,
hasstatus => true,
hasrestart => true,
require => Package["tomcat7"]
}
service { "mysql":
ensure => running,
enable => true,
hasstatus => true,
hasrestart => true,
require => Package["mysql-server"]
}
file { "/var/lib/tomcat7/webapps/vraptor-musicjungle.war":
source => "/vagrant/manifests/vraptor-musicjungle.war",
owner => "tomcat7",
group => "tomcat7",
mode => 0644,
require => Package["tomcat7"],
notify => Service["tomcat7"]
}
file { "/var/lib/tomcat7/webapps/vraptor-segunda-aplicacao.war":
source => "/vagrant/manifests/vraptor-musicjungle.war",
owner => "tomcat7",
group => "tomcat7",
mode => 0644,
require => Package["tomcat7"],
notify => Service["tomcat7"]
}
exec { "musicjungle":
command => "mysqladmin -uroot create musicjungle",
unless => "mysql -u root musicjungle",
path => "/usr/bin",
require => Service["mysql"]
}
exec { "mysql-password" :
command => "mysql -uroot -e \"GRANT ALL PRIVILEGES ON * TO 'musicjungle'@'%' IDENTIFIED BY 'minha-senha';\" musicjungle",
unless => "mysql -umusicjungle -pminha-senha musicjungle",
path => "/usr/bin",
require => Exec["musicjungle"]
}
define file_line($file, $line) {
exec { "/bin/echo '${line}' >> '${file}'":
unless => "/bin/grep -qFx '${line}' '${file}'"
}
}
file_line { "production":
file => "/etc/default/tomcat7",
line => "JAVA_OPTS=\"\$JAVA_OPTS -Dbr.com.caelum.vraptor.environment=production\"",
require => Package["tomcat7"],
notify => Service["tomcat7"]
}