What
This article provides a clear, concise introduction to Ansible, guiding beginners through installation, basic configuration, and running their first automation tasks.
Why
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.
How
Step 1: Installing Ansible
On Ubuntu/Debian
sudo apt update
sudo apt install -y ansible
On CentOS/RHEL
sudo yum install epel-release
sudo yum install -y ansible
Using pip (for latest version)
pip install ansible
Step 2: Verify Ansible Installation
ansible --version
Step 3: Configure Inventory File
Create an inventory file to define managed hosts.
sudo nano /etc/ansible/hosts
Example content:
[webservers]
192.168.1.10
192.168.1.11
[dbservers]
db01.example.com
Step 4: Test Connection with Ping Module
ansible all -m ping
If using a specific user:
ansible all -m ping -u your_user
Step 5: Create a Simple Playbook
Create a file named install_nginx.yml
.
- hosts: webservers
become: yes
tasks:
- name: Install nginx
apt:
name: nginx
state: present
Step 6: Run the Playbook
ansible-playbook install_nginx.yml
Conclusion
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.