Skip to main content

Command Palette

Search for a command to run...

Day 102: Installing Ansible

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

Published
โ€ข2 min readโ€ขView as Markdown
Day 102: Installing Ansible

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) โœจ

DevOps overview as a beginner

Part 1 of 50

Sharing my journey of learning DevOps as a beginner โ€” covering essential tools, cloud setup, CI/CD, Docker, monitoring, and more, step by step with practical examples.