Date: 8/3/2020
Welcome and greetings
- Hello, and welcome to today’s episode. A very special welcome and thank you to our listeners in Enterprise, Alabama.
Recap of last episode
- In our last real episode, we discussed Hashicorp’s Vagrant product. I talked a little bit about what it is and how it can be used to improve and speed up your automation efforts….especially around server provisioning.
Summary of this episode
- In this episode, I’m going to talk about how you can further enhance automation with Vagrant by using a Vagrantfile. I’m going to cover 3 examples of how a Vagrantfile can be used in different ways to provision a server.
What’s in it for you?
- At the end of this episode, you will be able to discuss with your peers and co-workers how you can use Vagrant and Vagrantfiles to further your automation efforts. You will see how to set up a basic Vagrantfile and some of the syntax that goes into setting up the commands to successfully create the server(s) that you need for your application and environment.
Episode Content
Here are the 3 examples that I cover in this episode. Having this in front of you as a reference will help you understand some of the commands that I cover.
# Begin examples.
– Create an empty directory.
– Copy the above file to it as Vagrantfile.
– Install Vagrant and VirtualBox if you don’t have them yet.
– Using “cd”, change to the directory and run “vagrant up”. It will take a while to download the image and then to install Jenkins in the image.
– Then on your computer browse to http://localhost:8080/ Jenkins will prompt you for the secret admin password that was set up during installation.
– On the command line, type “vagrant ssh” this will ssh into the VirtualBox running Jenkins.
– Type “sudo cat /var/lib/jenkins/secrets/initialAdminPassword” to get the secret, copy that secret to the browser.
– Just use the default installation parameters, then create a user for the admin user.
– If you don’t see the jenkins screen, then restart the machine by typing in “sudo reboot”.
– Once the machine has rebooted, you can reload the page in the browser and it should show you the Jenkins login page.
——————————————————
# Example # 1
——————————————————
# vi: set ft=ruby :
Vagrant.configure(“2”) do |config|
config.vm.box = “ubuntu/bionic64”
config.vm.network “forwarded_port”, guest: 8080, host: 8080, host_ip: “127.0.0.1” ### this should be the IP of the host that vagrant is running on.
config.vm.provision “shell”, inline: <<-SHELL
apt-get update
apt-get upgrade -y
wget -q -O – https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add –
sh -c ‘echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list’
apt-get update
apt-get install -y openjdk-8-jre
apt-get install -y jenkins
SHELL
end
——————————————————
# Example # 2
——————————————————
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = “2”
$script = <<ENDSCRIPT
sudo yum install -y epel-release
sudo yum -y update
sudo yum install -y net-tools
sudo yum install -y wget
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm –import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum install -y jenkins
sudo yum install -y java-1.8.0-openjdk.x86_64
sudo systemctl start jenkins.service
sudo systemctl enable jenkins.service
ENDSCRIPT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = “centos/7”
config.vm.network “forwarded_port”, guest: 8080, host: 8888
config.vm.provision “shell”, inline: $script
end
——————————————————
# Example # 3
——————————————————
Vagrant.configure(“2”) do |config|
config.vm.define “jenkinsserver”, primary: true do |pm|
pm.vm.box = “puppetlabs/centos-7.0-64-puppet”
pm.vm.box_version = “1.0.2”
pm.vm.hostname = “jenkinsserver”
pm.vm.network :private_network, ip: “10.10.10.10”
pm.vm.provider “vmware_fusion” do |v|
v.vmx[‘memsize’] = “4000”
v.vmx[‘numvcpus’] = “2”
end
pm.vm.provision “shell”, path: “setup.sh”
pm.vm.provision “puppet” do |puppet|
puppet.options = “–verbose –debug”
puppet.environment_path = “path/to/puppet-manifests”
puppet.environment = “dev”
puppet.hiera_config_path = “hirea/hiera.yaml”
puppet.working_directory = “/tmp/vagrant-puppet”
end
end
end
# End of examples.
Recap of this episode
- In this episode, we reviewed how to set up and use a Vagrantfile to enhance your automated server provisioning. This will be valuable if you need to stand up an isolated server instance for a particular type of testing when you don’t have the time or money to purchase a new bare-metal server and get it into your data center and network.
I’d like to thank you for joining me in this episode.
I hope that you found some value in what I covered and if you have suggestions for future topics, please feel free to drop me a message and I’ll be sure to review those to work into the schedule.
If you enjoy this podcast and the topics I cover, you can help me out by sharing the link with your friends. You can also give us a like or a thumbs-up where-ever you listen.
Please leave a review on your favorite podcast service as this will help me become better and ensure that I’m providing the value that you are looking for.
Before you leave, don’t forget to subscribe to ensure that you are notified of future episodes.
Next Episode: Sonar code scanning – From A – F
Where you can find us!
Direct Messages:
- @cs_everhart on Twitter
- ScottTalksTech group on Facebook
- ScottTalksTech.slack.com
Links to Podcast Providers:
- On Google Podcasts
- On Apple Podcasts
- On Spotify
- On iHeartRadio
- Stitcher
- Pandora coming soon
- PodcastAddict – web link not available but podcast is available in the app
- On PodChaser
- On Deezer
- On ListenNotes
- On OverCast
- On CastBox