If all you have is a windows 10 machine, but if you have to build an automated configuration deployment with Ansible on a Linux machine, this small article comes to rescue. You can easily creade and destroy new infrastructure configurations on your local machine with Vagrant.
In the next steps I will describe how you can create virtual linux machines on a windows 10 system with Vagrant and then how you can access them to install Ansible and run a small setup configuration on them.
Prerequisites
Enabling Linux on Windows 10 is now wasy. You can check on this article for a detailed net to step approach: Linux on Windows 10
Install ubuntu bash: Ubuntu bash on Windows 10
Upgrade powershell to latest version: Powershell
Download and install Vagrant: Vagrantup
Install Ansible on Windows 10: Ansible
Setting up a Vagrant Configuration
Create a path on your local machine, where you would like to have the vagrant configuration. Make sure the path does not contain any space in the names. I took me a while to catch this limitation.
Let’s say we work with: d:\vagrant\demo
Create a vagrant file:
vagrantfile
. The next script sample shows a configuration for two similar linux virtual machines, with 2 CPUs and 2 GB of Memory.######################################################################### ###### VM1 config ##################################################### ######################################################################### config.vm.define "vm1", primary: true do |vm1| vm1.vm.box = "centos/7" vm1.vm.network "private_network", ip: "192.160.55.10" vm1.vm.provider "virtualbox" do |vb| # Don't boot with headless mode # vb.gui = true # Use VBoxManage to customize the VM. For example to change memory: vb.memory = 2048 vb.cpus = 2 end end ######################################################################### ###### VM2 config #################################################### ######################################################################### config.vm.define "vm2", autostart: false do |vm2| vm2.vm.box = "centos/7" vm2.vm.network "private_network", ip: "192.160.55.20" vm2.vm.provider "virtualbox" do |vb| # Don't boot with headless mode # vb.gui = true # Use VBoxManage to customize the VM. For example to change memory: vb.memory = 2048 vb.cpus = 2 end end
For creating the virtual machines, the
virtual up machine_name
command has to be used As you can notice, the first machine configuration specifies that vm1 is the primary machine, this means that themachine_name
can be skipped from the command.Therefore, start the
cmd
underadmin
rights and navigate tod:\vagrant\demo
path where thevagrantfile
can be foundFor creating the first machine, execute:
$ vagrant up
For creating the second machine, execute:
$ vagrant up vm2
Enable ssh-agent in bash
$ ssh-agent bash
Enable ssh communication to the vagrant machine by adding the private key generated by vagrant for each machine
$ ssh-add /mnt/d/vagrant/demo/.vagrant/machines/vm1/virtualbox/private_key $ ssh-add /mnt/d/vagrant/demo/.vagrant/machines/vm2/virtualbox/private_key
Check the connections to each machine by using the IPs added in the vagrantfile configuration:
$ ssh vagrant@192.160.55.10 $ ssh vagrant@192.160.55.20
Now you can execute your Ansible configuration setup on the above created machines. In the next article I will post a detailed step by step sample on how to do this.
If you want to start from scratch, you can delete the vagrant machines by using the
destroy
command$ vagrant destroy vm1 $ vagrant destroy vm2
Other Good References
That’s it! Now you are good to go!