Day 102: Installing Ansible
Step-by-Step Guide to Installing Ansible and Running Your First Task

Yesterday, I explored what Ansible is and why itโs powerful for automation.
Today, I got hands-on: installed Ansible and ran my very first job! ๐
๐น Installing Ansible on Ubuntu
# Update system
sudo apt update -y
# Install Ansible
sudo apt install ansible -y
# Verify installation
ansible --version
This confirmed Ansible was installed and ready to go โ
๐น Setting Up Inventory
I created a simple inventory.ini file:
[web]
192.168.1.20 ansible_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa
This defines my web server where Ansible will run tasks.
๐น Running My First Ansible Ad-Hoc Command
To test connectivity:
ansible all -i inventory.ini -m ping
๐ก Response:
192.168.1.20 | SUCCESS => {
"changed": false,
"ping": "pong"
}
This means Ansible successfully connected to my remote server over SSH ๐ฏ
๐น Writing My First Playbook
I wrote a simple playbook to install nginx on my server:
- name: Install and start Nginx
hosts: web
become: yes
tasks:
- name: Install nginx
apt:
name: nginx
state: present
- name: Start nginx service
service:
name: nginx
state: started
enabled: yes
Then executed:
ansible-playbook -i inventory.ini nginx-playbook.yml
๐ก Nginx was installed and running on my web server within seconds!
๐น My Takeaway
Running my first Ansible job felt like magic โ instead of logging into the server and running multiple commands, I automated everything with just a few lines of YAML.
This is the real power of Infrastructure as Code (IaC) โจ




