तुमचा पहिला Ansible Playbook लिहा
Read this guide in: English · मराठी · हिंदी
Why Ansible हवा आहे? कारण प्रत्येक server हाताने configure केला की developers आणि operations मध्ये problem येतो. Developers म्हणतात “nginx आणि ही file.” Operations — server side — Friday ला वेगवेगळे commands टाइप करतो. Config drifts. Ansible YAML playbooks ने desired state inventory मधील hosts वर लागू करतो (बहुतेक वेळा SSH) — ok vs changed. प्रत्येक वेळी नवीन लांब shell commands लिहायची गरज नाही.
मित्रांनो, प्रत्येक server वेगळा झाला की Friday रात्री भीती वाटते. Ansible म्हणजे “काय असावे” एकदा लिहा, पुन्हा चालवा.
थोडक्यात उत्तर
हे पाच पॉइंट्स लक्षात ठेवा:
- Developer — app साठी known setup हवा.
- Operations — server-side person ज्याला अनेक hosts समान ठेवायचे आहेत.
- Problem — हाताने SSH; drift; “server A वर चालते B वर नाही.”
- Ansible — inventory hosts; playbook desired state;
ansible-playbook. - लक्षात ठेवा: काय खरे असावे ते सांगा → दोनदा चालवा → शांत results.
Language: English · मराठी · हिंदी
Problem? Suppose we are…
Suppose we are building Instagram (like updates)
प्रत्येक API host वर packages “जसे आठवले” install. एका host वर file missing → काही users तुटतात. Operations सर्व hosts match आहेत हे सिद्ध करू शकत नाही.
Suppose we are working at Netflix and we are giving updates
अनेक hosts identical राहायला हवेत. हाताने SSH मंद आणि चुकण्याची शक्यता जास्त.
Suppose you are working in Infosys on a client project
Client operations documented state मागतो. Playbook = audit trail — खाजगी notepad मधील shell commands नाही.
Control node वर Ansible, स्वतःच्या lab host ला SSH (SSH EC2). Private keys commit करू नका.
The control node runs a playbook over SSH so managed hosts reach the same desired state (idempotent).
Terminal-style teaching diagram: inventory + playbook ping task and ansible-playbook recap (use only hosts you own).
Ansible कसे उत्तर देते
[lab]
REPLACE_WITH_YOUR_HOST ansible_user=ec2-user
- name: Ping lab hosts
hosts: lab
gather_facts: false
tasks:
- name: Connectivity check
ansible.builtin.ping:
ansible --version
ansible lab -i inventory.ini -m ping
ansible-playbook -i inventory.ini playbook.yml
दुसऱ्यांदा चालवा — ok जास्त, changed कमी (idempotence). Modules (copy, package, service) prefer करा; shell: last resort.
Ravindra Bagale's Tip
प्रत्येक task साठी shell: paste करू नका. Modules आधीच झालेले काम skip करू शकतात. लक्षात ठेवा.
Learn it properly
समजलं का? Why Ansible = प्रत्येक server वेगळा होणे थांबवा; Instagram / Netflix / Infosys “suppose”; inventory + playbook + दोनदा run.
Frequently asked questions
What is Ansible?
An automation tool that pushes desired state to servers, often over SSH, using YAML playbooks.
What is a playbook?
A YAML file listing plays: which hosts, and which tasks to apply.
What is inventory?
The list of hosts and groups Ansible targets.
What does idempotent mean?
Running the same playbook again should not break things — only fix drift.
Do I need agents on servers?
No classic agent: SSH (or winrm) from the control node is enough for many setups.
Ansible vs Terraform?
Ansible often configures servers and apps. Terraform often creates cloud resources. Many teams use both.