Easy Vagrant example files

Following on from my last post, Quick Introduction to Vagrant, below are a couple of simple vagrant files. 

Both are using Centos, but it shows a simple file where you can specify a name and a private IP address.

The second will also show you how to run a Ansible job when started, or if you do want to test an ansible jobs.

Example 1

I also like to remove all the default text so all the Vagrantfiles are small as easy to view and understand.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.define "master"
  config.vm.network "private_network", ip: "192.168.33.10"
end

This example above, is as simple as it gets, this will create a centos machine.  It's already in a directory called Master, the machine its self will be called master and it will have a private IP address of 192.168.33.10.

Naming this will also be handy when you use vagrant global-status then you will see it named master rather than just a bunch of different characters/numbers.

Example 2

This example is that same as above, however this one will call and run the Ansible playbook called playbook.yml

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.define "master"
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "playbook.yml"
  end
end

This is handy if you have several different playbooks that use use to provision servers once you start them up.  

Hope this examples will help you out

I am always interested in your thoughts so if you have any comments or feedback then please feel free to add any comments, or you can mail me  here.

Related Posts Plugin for WordPress, Blogger... 

 

Microsoft to acquire Github

Microsoft to acquire Github

Mantis Malware