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
$ 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.
Install Ansible
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
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
-
gnupg
-
software-properties-common
-
curl
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: