Objective
- Prove Ansible is agentless
- Understand playbook structure
- See fact gathering
- Observe idempotency
- Understand execution order
Architecture
Mac (Control Node)
↓ SSH
EC2 Ubuntu (Managed Node)
No agent installed on EC2.
Step 1 — Prove It Is Agentless
SSH into EC2:
ssh -i ~/Downloads/pem/key.pem ubuntu@3.141.22.178
Now check:
ps aux | grep ansible
You will see:
Nothing running.
Ask students:
“If Ansible works, where is the agent?”
Answer:
There is none.
Ansible connects via SSH, executes modules remotely, and exits.
Exit EC2.
Step 2 — Create Playbook to See Execution Flow
Create:
vim playbook-demo.yml
Paste:
- name: Playbook Behavior Demo
hosts: web
become: yes
tasks:
- name: Show hostname
command: hostname
- name: Create test file
file:
path: /tmp/ansible-test.txt
state: touch
- name: Write content into file
copy:
dest: /tmp/ansible-test.txt
content: "Hello from Ansible"
- name: Install htop
apt:
name: htop
state: present
Step 3 — Run Playbook
ansible-playbook -i inventory.ini playbook-demo.yml
Students observe:
- Gathering Facts
- Tasks executed in order
- changed vs ok
Step 4 — Run It Again
Run again:
ansible-playbook -i inventory.ini playbook-demo.yml
Now students see:
- hostname → ok
- file → ok
- copy → ok
- htop → ok
- changed = 0
Ask them:
“Did Ansible re-install htop?”
Answer:
No. Because state was already correct.
This is idempotency.
Step 5 — Disable Fact Gathering
Now modify playbook:
Add:
gather_facts: no
Like this:
- name: Playbook Behavior Demo
hosts: web
become: yes
gather_facts: no
Run again.
Students will see:
No "Gathering Facts" step.
Explain:
Ansible automatically collects system info using setup module.
Step 6 — Observe SSH Activity
Run with verbose mode:
ansible-playbook -i inventory.ini playbook-demo.yml -vvv
Students will see:
- SSH connection
- Module transfer
- Execution
- Cleanup
Explain:
Ansible copies module temporarily → executes → removes it.
That proves:
Agentless + push-based.
Step 7 — Break Something Intentionally
SSH into EC2:
sudo rm /tmp/ansible-test.txt
Run playbook again.
Now students see:
changed=1
Explain:
Ansible detected missing state and corrected it.

Top comments (0)