Ansible Architecture, Configuration & Automated Inventory
This creates billable resources. Run it in a dev environment and destroy it when you finish. Set a budget alarm first.
Success criteria
0 of 3
What you are building#
What is Ansible Configuration & Dynamic Inventory?#
Ansible is an open-source, agentless configuration management and automation platform. Unlike legacy agent-based systems (such as Chef, Puppet, or SaltStack) that require a background daemon agent installed on every target node, Ansible operates over standard SSH (TCP Port 22) on Linux or WinRM on Windows.
- Control Node: The central workstation or CI server running Ansible binaries. It reads playbooks, parses dynamic inventory inputs, compiles Python module payloads, opens SSH sessions, and executes modules in-memory on remote target hosts.
- Target Managed Node: The target server (our Jenkins EC2 host deployed in Lab 06). It requires zero custom agent software — only an SSH daemon (
sshd) and a standard Python 3 runtime environment. - Dynamic Inventory: In modern elastic cloud infrastructure (AWS), EC2 instance IP addresses change dynamically whenever instances are recreated. A dynamic inventory script queries infrastructure outputs (e.g.
terraform output -raw jenkins_public_ip) and dynamically generates Ansible's inventory file (inventory/hosts.ini), completely eliminating manual IP editing.
ANSILE AGENTLESS INVENTORY ARCHITECTURE
+-------------------------------------+ +-------------------------------------+
| ANSIBLE CONTROL NODE | | AWS EC2 TARGET MANAGED NODE |
| | | (Jenkins Server — Public Subnet A) |
| [ master config: ansible.cfg ] | | |
| [ script: update-inventory.sh ] | SSH Port 22 | - Standard OpenSSH Daemon (sshd) |
| | (Fetches TF Output IP) | ==============> | - Python 3 Runtime Environment |
| v | Pushes Python | - Zero Agent Software Installed |
| [ inventory: hosts.ini ] | Module Payload | - Systemd Service Manager |
+-------------------------------------+ +-------------------------------------+Steps#
Step 1: Make Script Executable#
cd 02-Configuration-Management-Ansible/Lab07-Ansible-Inventory-Setup
chmod +x scripts/update-inventory.shStep 2: Extract Public IP from Lab 06 & Generate Inventory#
JENKINS_IP=$(terraform -chdir=../../01-Infrastructure-Terraform/Lab06-Jenkins-EC2-AWSBackup output -raw jenkins_public_ip)
./scripts/update-inventory.sh $JENKINS_IPStep 3: Test Ad-Hoc Ping Connectivity#
ansible jenkins_servers -m ping -i inventory/hosts.iniVerify it worked#
ansible jenkins_servers -m ping -i inventory/hosts.iniExpected Terminal Output:
jenkins_host:
changed: false
ping: pongVerify inventory/hosts.ini contents:
cat inventory/hosts.iniExpected File Output:
[jenkins_servers]
jenkins_host ansible_host=54.210.142.88 ansible_user=ubuntu
[all:vars]
ansible_python_interpreter=/usr/bin/python3
ansible_ssh_common_args='-o StrictHostKeyChecking=no'Clean up#
Run this even if you did not finish. Everything above is destroyable, and an account full of half-built experiments is how a surprise bill starts.
Destructive — This removes real resources. Check which environment you are in first.
terraform destroy -auto-approve
aws ec2 describe-instances --filters Name=instance-state-name,Values=running --query 'Reservations[].Instances[].InstanceId'Cost of this lab: Free tier — Ansible itself is free; the cost is whichever EC2 instances it configures. A t3.micro control node is inside the free tier.