Online courses

Free courses, labs and MOOCs, with your progress saved.

Infrastructure

Hands-on labs Advanced Free

Terraform & Ansible labs

Seven progressive labs, on a local (KVM) or Proxmox path, around a PHP/MariaDB application.

  • 7 labs
  • 67 steps
Start the lab

Terraform foundations

3 h 30 10 steps

Expected outcome

Define infrastructure as code, understand providers, resources and the plan.

Lab steps

Common steps

  1. Step 1 : Identify provider, resource, variable, output and state.

    Expected check: explain or show the result in the terminal / the VM.

  2. Step 2 : Create a Terraform directory, run fmt/init/validate.

    Expected check: explain or show the result in the terminal / the VM.

  3. Step 3 : Study terraform plan without provisioning until the plan is approved.

    Expected check: explain or show the result in the terminal / the VM.

  4. Step 4 : Explain why tfstate and secrets do not go into Git.

    Expected check: explain or show the result in the terminal / the VM.

LOCAL - KVM / libvirt

  1. Step 5 : Check `virsh list --all` and `virsh net-list --all`; enable the `default` network if needed.

    Capture or present the result specific to the local path.

  2. Step 6 : Identify the `qemu:///system` URI, the pool and the Ubuntu Cloud image.

    Capture or present the result specific to the local path.

  3. Step 7 : Initialise the `dmacvicar/libvirt` provider and inspect the local plan.

    Capture or present the result specific to the local path.

PROXMOX VE - remote infrastructure

  1. Step 8 : Check the Proxmox API endpoint, the token's rights and the TLS certificate.

    Capture or present the result specific to the Proxmox path.

  2. Step 9 : Identify node_name, datastore, vmbr0, the cloud-init template and the VMID.

    Capture or present the result specific to the Proxmox path.

  3. Step 10 : Initialise the `bpg/proxmox` provider and analyse the plan without touching existing VMs.

    Capture or present the result specific to the Proxmox path.

Resources

Creating the two VMs

3 h 30 10 steps

Expected outcome

Provision web-01 and db-01, mastering Cloud-init, SSH and networking.

Lab steps

Common steps

  1. Step 1 : Create two distinct VMs, with identifiable CPU/RAM resources.

    Expected check: explain or show the result in the terminal / the VM.

  2. Step 2 : Inject an SSH key via Cloud-init (never a clear-text password).

    Expected check: explain or show the result in the terminal / the VM.

  3. Step 3 : Run plan then apply after checking.

    Expected check: explain or show the result in the terminal / the VM.

  4. Step 4 : Test SSH to both VMs and note the IP addresses.

    Expected check: explain or show the result in the terminal / the VM.

LOCAL - KVM / libvirt

  1. Step 5 : Create the QCOW2 volumes and the Cloud-init ISOs.

    Capture or present the result specific to the local path.

  2. Step 6 : Attach the two VMs to the libvirt NAT network via DHCP.

    Capture or present the result specific to the local path.

  3. Step 7 : Retrieve the IPs via `terraform output -raw web_ip` and `db_ip`.

    Capture or present the result specific to the local path.

PROXMOX VE - remote infrastructure

  1. Step 8 : Clone the Ubuntu template prepared with Cloud-init.

    Capture or present the result specific to the Proxmox path.

  2. Step 9 : Adapt the bridge, datastore and two reserved IP addresses.

    Capture or present the result specific to the Proxmox path.

  3. Step 10 : Check the two VMs in the Proxmox interface and the Terraform outputs.

    Capture or present the result specific to the Proxmox path.

Resources

Variables, modules and State

3 h 30 11 steps

Expected outcome

Parameterise and industrialise the Terraform resources.

Lab steps

Common steps

  1. Step 1 : Change the variables without touching the core of main.tf.

    Expected check: explain or show the result in the terminal / the VM.

  2. Step 2 : Compare the plan before/after a CPU/RAM change.

    Expected check: explain or show the result in the terminal / the VM.

  3. Step 3 : Create a reusable module or identify the for_each resources.

    Expected check: explain or show the result in the terminal / the VM.

  4. Step 4 : Read the state and distinguish state, configuration and reality.

    Expected check: explain or show the result in the terminal / the VM.

  5. Step 5 : Check destroy without destroying other people's resources.

    Expected check: explain or show the result in the terminal / the VM.

LOCAL - KVM / libvirt

  1. Step 6 : Change the memory/CPU of the local.machines mapping then apply.

    Capture or present the result specific to the local path.

  2. Step 7 : Assess the effects of the disk linked to a base QCOW2 image.

    Capture or present the result specific to the local path.

  3. Step 8 : Check `virsh dominfo tp-web-01` then save the outputs.

    Capture or present the result specific to the local path.

PROXMOX VE - remote infrastructure

  1. Step 9 : Change the VM's CPU or RAM via variables and plan.

    Capture or present the result specific to the Proxmox path.

  2. Step 10 : Check the changes proposed in Proxmox.

    Capture or present the result specific to the Proxmox path.

  3. Step 11 : Explain why the API token stays in the environment, not in tfvars.

    Capture or present the result specific to the Proxmox path.

Resources

Ansible foundations

3 h 30 8 steps

Expected outcome

Prepare an inventory and run its first idempotent tasks.

Lab steps

Common steps

  1. Step 1 : Install Ansible on the control machine.

    Expected check: explain or show the result in the terminal / the VM.

  2. Step 2 : Create a web/database inventory with the VMs' SSH IPs.

    Expected check: explain or show the result in the terminal / the VM.

  3. Step 3 : Run `ansible all -m ping` then collect facts.

    Expected check: explain or show the result in the terminal / the VM.

  4. Step 4 : Write a playbook that installs curl and display its result.

    Expected check: explain or show the result in the terminal / the VM.

LOCAL - KVM / libvirt

  1. Step 5 : Reuse the two IPs from libvirt; check SSH visibility from the host.

    Capture or present the result specific to the local path.

  2. Step 6 : Diagnose the libvirt NAT network and SSH keys if unreachable.

    Capture or present the result specific to the local path.

PROXMOX VE - remote infrastructure

  1. Step 7 : Reuse the IPs configured by Cloud-init on the Proxmox bridge.

    Capture or present the result specific to the Proxmox path.

  2. Step 8 : Check the VLAN, the Proxmox firewall and SSH access from the machine.

    Capture or present the result specific to the Proxmox path.

Resources

Roles, variables and Vault

3 h 30 9 steps

Expected outcome

Factor out the Linux configuration and protect the secrets.

Lab steps

Common steps

  1. Step 1 : Create and explain the common and docker_engine roles.

    Expected check: explain or show the result in the terminal / the VM.

  2. Step 2 : Put the shared variables in group_vars/all.yml.

    Expected check: explain or show the result in the terminal / the VM.

  3. Step 3 : Prepare secrets.yml and encrypt it with ansible-vault.

    Expected check: explain or show the result in the terminal / the VM.

  4. Step 4 : Run the playbook twice and observe changed/ok.

    Expected check: explain or show the result in the terminal / the VM.

  5. Step 5 : Explain handlers and Jinja2 templates by going through the roles.

    Expected check: explain or show the result in the terminal / the VM.

LOCAL - KVM / libvirt

  1. Step 6 : Configure the two local Ubuntu VMs with the same playbook.

    Capture or present the result specific to the local path.

  2. Step 7 : Check `docker compose version` on each target.

    Capture or present the result specific to the local path.

PROXMOX VE - remote infrastructure

  1. Step 8 : Configure the two VMs hosted in Proxmox with the same playbook.

    Capture or present the result specific to the Proxmox path.

  2. Step 9 : Check the differences between SSH privileges and the Proxmox API token.

    Capture or present the result specific to the Proxmox path.

Resources

Application deployment

3 h 30 9 steps

Expected outcome

Automate MariaDB on db-01 and the application on web-01.

Lab steps

Common steps

  1. Step 1 : Reuse the Docker lab's sources in an Ansible role.

    Expected check: explain or show the result in the terminal / the VM.

  2. Step 2 : Create the two Compose projects (web and DB) with the right variables.

    Expected check: explain or show the result in the terminal / the VM.

  3. Step 3 : Deploy MariaDB, then the PHP API, frontend, phpMyAdmin and Mailpit.

    Expected check: explain or show the result in the terminal / the VM.

  4. Step 4 : Test GET /api/hello, a POST message, the DB record and the Mailpit email.

    Expected check: explain or show the result in the terminal / the VM.

  5. Step 5 : Rerun the playbook and explain the idempotent results.

    Expected check: explain or show the result in the terminal / the VM.

LOCAL - KVM / libvirt

  1. Step 6 : Use the libvirt private IPs, without exposing MariaDB on a public interface.

    Capture or present the result specific to the local path.

  2. Step 7 : Test the application via `http://WEB_IP:8080`.

    Capture or present the result specific to the local path.

PROXMOX VE - remote infrastructure

  1. Step 8 : Use the Proxmox private network and check the firewall rules allowing web-01 → db-01:3306.

    Capture or present the result specific to the Proxmox path.

  2. Step 9 : Test the frontend and the tools from the administration network.

    Capture or present the result specific to the Proxmox path.

Resources

Final workshop: Terraform + Ansible

3 h 30 10 steps

Expected outcome

Start again from a blank infrastructure and reproduce the complete deployment.

Lab steps

Common steps

  1. Step 1 : Provision two VMs with one controlled Terraform command.

    Expected check: explain or show the result in the terminal / the VM.

  2. Step 2 : Inject the Terraform IPs into the Ansible inventory.

    Expected check: explain or show the result in the terminal / the VM.

  3. Step 3 : Run the preparation and deployment playbooks.

    Expected check: explain or show the result in the terminal / the VM.

  4. Step 4 : Check the frontend, the API, the DB, phpMyAdmin and Mailpit.

    Expected check: explain or show the result in the terminal / the VM.

  5. Step 5 : Change a variable, rerun and compare the changes.

    Expected check: explain or show the result in the terminal / the VM.

  6. Step 6 : Document the restoration and carry out a controlled cleanup.

    Expected check: explain or show the result in the terminal / the VM.

LOCAL - KVM / libvirt

  1. Step 7 : Check there is no libvirt pool/network conflict with the other students.

    Capture or present the result specific to the local path.

  2. Step 8 : Run the inventory generation script with the local outputs.

    Capture or present the result specific to the local path.

PROXMOX VE - remote infrastructure

  1. Step 9 : Check the Proxmox account's scope and the VMs reserved for the lab.

    Capture or present the result specific to the Proxmox path.

  2. Step 10 : Run the inventory generation script from the Proxmox IPs.

    Capture or present the result specific to the Proxmox path.

Resources

In the same series Step 2 of 2

  1. 1 Course Terraform & Ansible — The course
  2. 2 Lab Terraform & Ansible labs You are here

Share this article

In the same category

Course

Infrastructure · Intermediate

Docker & Docker Compose — The course

Images, containers, volumes, networks and Compose: vocabulary, essential commands and good practice.

3 guides · 132 concepts In the same series

Course

Infrastructure · Intermediate

Kubernetes — The course

Pods, deployments, services, configuration and storage: orchestrating containers, from theory to kubectl.

3 guides · 159 concepts In the same series

Course

Infrastructure · Intermediate

Terraform & Ansible — The course

Describe infrastructure with Terraform and configure it with Ansible: providers, playbooks, roles and idempotence.

3 guides · 146 concepts In the same series