How dourado/packer-ansible-terrafrom-gitlab works
Project type and purpose
• This is an Infrastructure-as-Code (IaC) orchestration project whose goal is to fully automate the build and deployment of a private GitLab Runner on AWS.
• Key tools:
• Packer: to bake an AMI
• Ansible: to provision that AMI (install Docker, Docker Machine and GitLab-Runner)
• Terraform: to deploy the AWS resources (VPC/networking/instance) using the AMI
File structure
• Top-level directories:
• packer/ ← Packer template + variables + gitlab PAT
• roles/ ← Ansible roles for provisioning
– docker/ ← installs Docker & Docker Machine
– gitlab-runner/ ← installs & configures GitLab Runner
• terraform/ ← Terraform root + modules
– modules/iam ← IAM roles & policies
– modules/key ← Key pair setup
• Root files:
• Makefile ← orchestrates Packer & Terraform
• README.md ← project overview & usage
• gitlab.yaml ← CI/CD pipeline (optional)
Extract additional insights from README
• Workflow:
1. Run make
2. Packer calls Ansible playbooks (roles/docker + roles/gitlab-runner) → produces new AMI
3. Terraform uses the new AMI to spin up an EC2 instance in the specified VPC/Subnet/Security Group
4. Manual step: register the runner with GitLab using the provided arquivo_exemplo.toml
a. Main components
• Developer/CI host (where you run Make, Packer, Terraform)
• Packer service
• Ansible provisioners (Docker role, GitLab-Runner role)
• AWS account:
• VPC, Subnet, Security Group
• IAM roles & key pair
• AMI (output of Packer)
• EC2 instance (GitLab Runner)
• External GitLab service
b. Relationships & interactions
1. Developer Machine → invokes Packer → AWS API (create and configure AMI)
2. Packer → calls Ansible roles (via local or remote provisioner) to install Docker & Runner into the AMI
3. Developer Machine → invokes Terraform → AWS API (use AMI to launch EC2, attach IAM, key pair, network settings)
4. New EC2 instance boots → loads GitLab Runner → registers with GitLab service (manual token step)
c. Architectural patterns & design principles
• Separation of concerns:
• Image baking (Packer) vs. provisioning software (Ansible) vs. resource orchestration (Terraform)
• Modularity:
• Ansible roles for distinct tasks
• Terraform modules for IAM and key management
• Idempotence & reproducibility:
• Every run produces the same AMI and infrastructure state
d. Key technologies & frameworks
• Packer (AMI builder)
• Ansible (roles, playbooks)
• Terraform (IaC, modules)
• AWS (EC2, IAM, VPC, Subnets, SGs)
• Docker & Docker Machine
• GitLab Runner