Ansible Tutorial For DevOps Engineers in Hindi (With Notes) 🔥
Table of Contents
Introduction
This tutorial provides a comprehensive guide to using Ansible for DevOps engineers, based on the video by TrainWithShubham. Ansible is an open-source automation tool that simplifies the management of systems and applications. This guide will walk you through essential concepts, setup instructions, and practical tips to help you effectively leverage Ansible in your DevOps practices.
Step 1: Understanding Ansible Basics
- Ansible is a configuration management tool that automates the deployment of software.
- It uses a push model, meaning the control machine pushes changes to the nodes.
- Key components of Ansible include:
- Inventory: A file listing all the nodes (servers) that Ansible manages.
- Modules: Units of work that Ansible can execute on managed nodes.
- Playbooks: YAML files that define the tasks to be executed on nodes.
Step 2: Setting Up Ansible
-
Install Ansible:
- On Ubuntu:
sudo apt update sudo apt install ansible
- On CentOS:
sudo yum install ansible
- On Ubuntu:
-
Verify Installation:
- Check the installed version:
ansible --version
- Check the installed version:
-
Configure Inventory:
- Create an inventory file (e.g.,
hosts.ini
):[webservers] your_server_ip
- You can define groups for better organization.
- Create an inventory file (e.g.,
Step 3: Writing Your First Playbook
-
Create a Playbook file (e.g.,
site.yml
):- hosts: webservers tasks: - name: Install nginx apt: name: nginx state: present
-
This playbook installs Nginx on the servers listed in the inventory under the
webservers
group.
Step 4: Running the Playbook
- Execute the playbook with the following command:
ansible-playbook -i hosts.ini site.yml
- Ensure you have SSH access to the nodes specified in your inventory.
Step 5: Using Ansible Modules
- Ansible provides various modules for different tasks. Common modules include:
- apt: For package management on Debian-based systems.
- yum: For package management on RedHat-based systems.
- copy: For transferring files.
Example of using the copy
module:
- name: Copy a file
copy:
src: /path/to/local/file
dest: /path/to/remote/file
Step 6: Best Practices
- Keep your playbooks modular by breaking them into roles.
- Document your playbooks and tasks for better readability.
- Use version control (e.g., Git) to manage your playbooks.
Conclusion
In this tutorial, we've covered the fundamentals of Ansible, including installation, configuration, and writing your first playbook. By following these steps, you can automate your DevOps tasks efficiently. For further learning, consider exploring more advanced Ansible features and best practices. Happy automating!