Welcome to the Terraform and Ansible labs.
These are hands-on resources to help you learn Terraform and Ansible.
Pre-reqs
Ensure you have the following installed on your local machine:
- Docker
- Terraform
- Ansible
- kubectl
- Node.js and npm
- Download the Terraform ZIP file from the official website.
- Extract the ZIP file to a directory, e.g.,
C:\terraform.
- Add the directory to your system PATH:
- Right-click on ‘This PC’ and choose ‘Properties’.
- Click on ‘Advanced system settings’.
- Click on ‘Environment Variables’.
- Under ‘System variables’, find ‘Path’, click ‘Edit’.
- Click ‘New’ and add the path to your Terraform directory.
- Open a new command prompt and verify the installation:
- Update package index and install required packages:
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
- Add the HashiCorp GPG key:
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
- Add the official HashiCorp repository:
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
- Update and install Terraform:
sudo apt-get update && sudo apt-get install terraform
- Verify the installation:
- Install Homebrew if not already installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install Terraform using Homebrew:
- Verify the installation:
Setting up Ansible
Ansible on Windows
Ansible doesn’t run natively on Windows. The recommended approach is to use Windows Subsystem for Linux (WSL).
- Enable WSL by opening PowerShell as Administrator and running:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
- Restart your computer.
- Install a Linux distribution from the Microsoft Store (e.g., Ubuntu).
- Launch the Linux distribution and follow the Linux instructions below.
Ansible on Linux
- Update package index and install Ansible:
sudo apt update
sudo apt install ansible
- Verify the installation:
Ansible on macOS
- Install Ansible using Homebrew:
- Verify the installation:
Comparison Chart: Deployment With and Without Ansible
| Aspect |
With Ansible |
Without Ansible |
| Setup Process |
Automated via playbook |
Manual execution of commands |
| Reproducibility |
High - playbook ensures consistent setup |
Lower - depends on following documentation accurately |
| Time Efficiency |
Fast - runs all steps automatically |
Slower - requires manual intervention for each step |
| Error Handling |
Built-in error handling and reporting |
Manual error checking required |
| Idempotency |
Ensures system state, can be run multiple times safely |
Manual checks needed to avoid duplicate actions |
| Learning Curve |
Requires learning Ansible syntax |
Requires familiarity with individual tools and commands |
| Flexibility |
Can easily modify playbook for different environments |
Might need separate scripts for different environments |
| Documentation |
Playbook serves as executable documentation |
Separate documentation needed |
| Version Control |
Easy to version control Ansible playbooks |
Need to version control multiple scripts or documentation |
| Scalability |
Easily scalable to multiple servers |
More challenging to scale manually |
Pros and Cons
With Ansible
Pros:
- Automation reduces human error
- Consistent and reproducible deployments
- Time-efficient for repeated deployments
- Built-in idempotency
- Serves as self-documenting infrastructure
- Easy to maintain and update
Cons:
- Initial learning curve for Ansible
- Overhead of installing and maintaining Ansible
- May be overkill for very simple deployments
- Debugging Ansible itself can be challenging
Without Ansible
Pros:
- No need to learn Ansible syntax
- Direct control over each step of the process
- No additional tool dependencies
- Potentially simpler for very basic deployments
Cons:
- More prone to human error
- Time-consuming for repeated deployments
- Harder to maintain consistency across environments
- Manual documentation required and may become outdated
- Scaling to multiple servers is more challenging
- No built-in error handling or reporting
Part 3. Deploying TypeScript (with Ansible)
Part 4. Deploying TypeScript (without Ansible)
Part 5. Deploying to AWS
Part 6. Exercises