Automating Labs with DevOps Tools (+ Github)

TLDR: We set up a small windows lab with Vagrant.

In the last article we spoke about Infrastructure as Code and DevOps practices to simplify the creation of virtual machines and automate the provisioning process. In this article we’ll actually get our hands dirty and create a test environment using Vagrant, Ansible, and VirtualBox.

vagrant init hashicorp/bionic64
Creating the folder, going into the folder, and creating a Vagrantfile
vagrant up
vagrant destroy -f
Vagrantfile after removing all the commented lines and default configuration
config.vm.define "vm-name" do |var|
  • A Windows 10 instance
  • A Windows Server 2019 instance (to create a domain)
Vagrantfile after defining three vms = <the image that you'll be using> = <internal or bridged network, ip address>
var.vm.hostname = <hostname for the machine>
var.vm.provider "virtualbox" do |x|
x.gui = <show vm or run in background> = <name of vm in virtualbox gui>
x.cpus = <number of cpus>
x.memory = <memory allocated to vm in megabytes>
var.vm.synced_foler <folder to share from local machine>, <location on vm>
var.vm.provision "shell", path: <path to a script on local machine>
Configuring the ansible-controller virtual machine
Three new folders
  • Scripts (to hold simple provisioning scripts)
  • Playbooks (to hold Ansible plays)
Script for setting up ansible
host_key_checking = False
<name of machine> ansible_host=<ip address of machine>
<variables for group>
ansible.cfg and hosts file
  • ansible_password
  • ansible_connection
  • ansible_winrm_server_cert_validation
Downloading script, running script, disabling firewall
Creating the two Windows virtual machines
vagrant up
Provisioning machines with vagrant
vagrant status
VMs running
vagrant <connection method> <machine name>examples:
vagrant ssh ansible-controller
vagrant rdp windows-box
ansible --version
Checking Ansible version, creating play, checking play file inside linux
Running Install-AD play and checking dc-server VM
vagrant halt
vagrant destroy -f
vagrant up

Daily Sys Admin; Nightly Info Sec Noob |

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store