Skip to content
Luca Dell'Oca Principal Cloud Architect @Veeam
Virtual To The Core Virtual To The Core

Virtualization blog, the italian way.

  • Media
  • About me
Virtual To The Core
Virtual To The Core

Virtualization blog, the italian way.

My Automated Lab project: #1 Install and configure the needed tools

Luca Dell'Oca, September 19, 2023September 18, 2023

Raise your hand if you love to rebuild everytime your home lab manually! Noone, right? you either end up trying to not breaking it, thus defeating the purpose of the lab, or you spend insame amount of hours to fix it everytime, or to rebuilding it from scratch. So, automation in our home labs has always been a huge topic, and there are around many posts in these regards. So, why my own version? Because I found around some posts that I used to create my own automation, but none of them was perfect for my needs. I love beers, so let me use this example: like an home brewer (which I’m not, by the way) during this year I made my own recipe. It may not be the best one around, but it’s my own personal recipe. If you find it useful too, be my guest!

My setup

I have a Windows laptop for work. I need it since many of the corporate apps we use are Windows based, or their Windows version is better. Then, I also use WSL on my Windows machine: it’s an embedded Linux virtual machine that can run as an application together with the Windows OS:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal

It runs Ubuntu LTS 20.04, and I described how to install it in a previous blog post.

I find this setup very convenient as I can share scripts and files between my Windows laptop, where I write the code and surf the Internet to find the information I need, and the Ubuntu VM where I then run the tools. You can see below my folder C:\IAC where I store all the files for my “Infrastructure as Code” projects (that’s where the folder name comes from). The same folder can be accessed inside the WSL machine:
For my project, I use three different tools. It’s may seems a non optimized choice, but for me it’s good because I can learn all of them and have a good knowledge of the whole “Infrastructure as Code” topic, but also since I truly believe each tool is great at what it was designed for:
  • packer: build templates from scratch in VMware vSphere
  • terraform: build infrastructure resources
  • ansible: manage the configuration of the resources
Let’s see first how to install and configure the tools.

Install Ansible

To install Ansible inside the WSL machine, I run these commands:
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt install python3-pip
sudo pip3 install pywinrm
sudo pip3 install pyvmomi
sudo pip3 install ansible

I can then check the version that was installed with:

$ ansible --version
ansible [core 2.13.5]
config file = None
configured module search path = ['/home/luca/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
ansible collection location = /home/luca/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.8.10 (default, Mar 13 2023, 10:26:41) [GCC 9.4.0]
jinja version = 3.1.2
libyaml = True

Install Packer

Ansible is the tool of choice for configuring and maintaining the environment, but at the beginning I need the VM templates to start from. For this task, the best tool around in my opinion is Packer. Packer’s user guide offers multiple options to install this program:
https://developer.hashicorp.com/packer/tutorials/docker-get-started/get-started-install-cli . For Ubuntu, the quick procedure is:
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install packer

And you can check that packer is installed:

$ packer --version
1.8.7

There’s no configuration for packer, so we are now ready to build our environment.

Install Terraform

As explained in the Hashicorp documentation, I need to ensure that the system has installed these packages:
  • gnupg
  • software-properties-common
  • curl
I use these packages to verify HashiCorp’s GPG signature and install HashiCorp’s Debian package repository.
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common

Then, I install the Hashicorp’s GPG key:

wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg

Then I verify the key’s fingerprint:

gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint

Then, I add the official HashiCorp repository to my system. The lsb_release -cs command finds the distribution release codename for my current system:

$ lsb_release -cs
focal

I use this information to choose the correct source:

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

Then I download the package information from HashiCorp:

sudo apt update

And I finally install Terraform:

sudo apt-get install terraform

Terraform is correctly installed:

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to email a link to a friend (Opens in new window) Email
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
Tech ansibleautomationcodeiacinfrastructurelabpackerterraform

Post navigation

Previous post
Next post

Search

Sponsors

Latest Posts

  • Migrate WSL (Windows Subsystem for Linux) to a new computer
  • Pass keystrokes to a pfSense virtual machine to install it automatically
  • Automatically deploy pfSense with Terraform and Ansible
  • My Automated Lab project: #6 Create a S3 Bucket with Terraform
  • My Automated Lab project: #5 Deploy a Linux vSphere VM with Terraform and custom disks
©2025 Virtual To The Core | WordPress Theme by SuperbThemes
We use cookies to ensure that we give you the best experience on our website, and to collect anonymous data regarding navigations stats using 3rd party plugins; they all adhere to the EU Privacy Laws. If you continue to use this site we will assume that you are ok with it.OkNoPrivacy Policy