अपना पहला 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 novel नहीं।
संक्षिप्त उत्तर
- Developer — app के लिए known setup चाहिए।
- Operations — server-side person जिसे कई hosts consistent रखने हैं।
- Problem — हाथ से SSH; drift; “server A पर चलता है B पर नहीं।”
- Ansible — inventory hosts; playbook desired state;
ansible-playbook। - Pocket: जो सच होना चाहिए बताओ → दो बार चलाओ → शांत results.
Language: English · मराठी · हिंदी
Problem? Suppose we are…
Suppose we are building Instagram (like updates)
हर API host पर packages “जैसा याद आया”। एक host पर file missing → कुछ users टूटते हैं। Operations सब hosts match हैं यह साबित नहीं कर सकता।
Suppose we are working at Netflix and we are giving updates
कई hosts identical रहने चाहिए। हाथ से SSH धीमा और error-prone।
Suppose you are working in Infosys on a client project
Client operations documented state माँगता है। Playbook = audit trail — private notepad of shell commands नहीं।
Control node पर Ansible, अपने lab host पर SSH। 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: मत चिपकाओ। Modules पहले से हुआ काम skip कर सकते हैं। याद रखो।
Learn it properly
Samajla ka? Why Ansible = snowflake servers रोकें; 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.