Skip to content

Introduction to Ansible

This article provides a clear, concise introduction to Ansible, guiding beginners through installation, basic configuration, and running their first automation tasks.

Ansible simplifies IT automation by providing an agentless, easy-to-learn tool for configuration management, application deployment, and task automation. It enhances efficiency, reduces manual errors, and ensures consistent environments.

Terminal window
sudo apt update
sudo apt install -y ansible
Terminal window
sudo yum install epel-release
sudo yum install -y ansible
Terminal window
pip install ansible
Terminal window
ansible --version

Create an inventory file to define managed hosts.

Terminal window
sudo nano /etc/ansible/hosts

Example content:

[webservers]
192.168.1.10
192.168.1.11
[dbservers]
db01.example.com
Terminal window
ansible all -m ping

If using a specific user:

Terminal window
ansible all -m ping -u your_user

Create a file named install_nginx.yml.

- hosts: webservers
become: yes
tasks:
- name: Install nginx
apt:
name: nginx
state: present
Terminal window
ansible-playbook install_nginx.yml

Ansible provides a powerful yet simple approach to automate IT tasks. By starting with basic configurations and playbooks, you can quickly scale automation across your infrastructure. Explore advanced features like Roles, Variables, and Ansible Galaxy to enhance your automation workflows.