Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management Notes in Hindi & English : इंफ्रास्ट्रक्चर एज कोड (IaC): टेराफॉर्म बनाम एन्सिबल तुलना और 20 महत्वपूर्ण MCQ प्रश्न (India IT Exam)

Post a Comment

UGC-NET, GATE, NIELIT (O/A/B Level), KVS/NVS Computer Teacher, PGDCA, BCA, MCA, B-Tech व All India IT Exam विशेष नोट्स: इस अध्याय में हम Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management (इंफ्रास्ट्रक्चर एज कोड (IaC): टेराफॉर्म बनाम एन्सिबल तुलना) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और राष्ट्रीय स्तर की परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: Infrastructure as Code (IaC) manages cloud infrastructure and OS configurations through versioned, declarative or imperative code rather than manual clicks. Terraform (by HashiCorp) excels at declarative, stateful infrastructure provisioning across clouds, whereas Ansible (by Red Hat) excels at agentless, SSH/WinRM-based configuration management and application deployment.

अध्याय सार: इंफ्रास्ट्रक्चर एज कोड (IaC) मैनुअल सेटअप के बजाय वर्जन-नियंत्रित कोड के माध्यम से क्लाउड व सर्वर संसाधनों का प्रबंधन करता है। Terraform (HashiCorp) डिक्लेरेटिव व स्टेटफुल इंफ्रास्ट्रक्चर प्रोविजनिंग के लिए श्रेष्ठ है, जबकि Ansible (Red Hat) एजेंटलेस SSH/WinRM-आधारित कॉन्फ़िगरेशन प्रबंधन और ऐप डिप्लॉयमेंट के लिए उपयोग होता है।

Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management: Detailed Notes & Architecture (इंफ्रास्ट्रक्चर एज कोड (IaC): टेराफॉर्म बनाम एन्सिबल तुलना)

1. Declarative vs Imperative IaC & Idempotency (डिक्लेरेटिव बनाम इम्पेरेटिव IaC और आइडेम्पोटेंसी)

[EN] Declarative IaC specifies the desired end state (e.g., '3 EC2 instances exist') and lets the engine compute the diff, while imperative IaC specifies step-by-step commands. Both Terraform and Ansible modules are designed for idempotency: running the same code repeatedly converges to the same state without creating duplicates.

[HI] डिक्लेरेटिव IaC अंतिम वांछित स्थिति बताता है और इंजन स्वयं अंतर (diff) निकालता है, जबकि इम्पेरेटिव चरणबद्ध कमांड देता है। Terraform और Ansible दोनों आइडेम्पोटेंसी का पालन करते हैं ताकि बार-बार चलाने पर डुप्लीकेट संसाधन न बनें।

2. Terraform Architecture: HCL, State File & Plan/Apply (टेराफॉर्म आर्किटेक्चर: HCL, स्टेट फाइल और Plan/Apply)

[EN] Terraform uses HashiCorp Configuration Language (HCL) and cloud provider plugins to manage VPCs, VMs, and Kubernetes clusters. It maintains a `terraform.tfstate` JSON file mapping code resources to real-world cloud IDs; `terraform plan` previews changes before `terraform apply` mutates infrastructure, and remote backends (S3 + DynamoDB) enable team state locking.

[HI] टेराफॉर्म HCL भाषा और प्रोवाइडर प्लगइन्स से क्लाउड संसाधन बनाता है। यह `terraform.tfstate` फाइल में वास्तविक संसाधन ID ट्रैक करता है; `terraform plan` बदलावों का पूर्वावलोकन दिखाता है और रिमोट बैकएंड (जैसे S3) टीम के लिए स्टेट लॉकिंग देता है।

3. Ansible Architecture: Agentless SSH, Playbooks & Inventory (एन्सिबल आर्किटेक्चर: एजेंटलेस SSH, प्लेबुक्स और इन्वेंटरी)

[EN] Ansible is agentless—requiring no daemon on target servers—and pushes Python modules over SSH (Linux) or WinRM (Windows) from a control node. Desired configurations are written in YAML Playbooks targeting hosts listed in an Inventory file, making Ansible ideal for OS patching, package installation, and middleware setup.

[HI] एन्सिबल एजेंटलेस है और कंट्रोल नोड से SSH (Linux) या WinRM (Windows) के जरिए टारगेट सर्वर पर कार्य करता है। कॉन्फ़िगरेशन YAML प्लेबुक्स में लिखे जाते हैं और टारगेट होस्ट्स की सूची इन्वेंटरी फाइल में होती है।

4. Mutable vs Immutable Infrastructure & Combining Both (म्यूटेबल बनाम इम्यूटेबल इंफ्रास्ट्रक्चर और दोनों का संयोजन)

[EN] Configuration management tools like Ansible often perform mutable in-place updates on long-lived servers, whereas Terraform favors immutable infrastructure—replacing VMs or containers cleanly when images change. In production, teams frequently combine them: Terraform provisions the VPC and VMs, and Ansible configures OS packages inside them.

[HI] Ansible अक्सर मौजूदा सर्वरों पर इन-प्लेस (म्यूटेबल) अपडेट करता है, जबकि Terraform इम्यूटेबल इंफ्रास्ट्रक्चर (नए वर्जन पर VM बदलना) को बढ़ावा देता है। प्रैक्टिस में Terraform से नेटवर्क/VM बनाए जाते हैं और Ansible से उनके भीतर सॉफ्टवेयर कॉन्फ़िगर किया जाता है।

Syntax, Formula & Technical Example (Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management)

# Terraform HCL (Provisioning)       | # Ansible YAML Playbook (Config)
resource "aws_instance" "web" {      | - hosts: webservers
  ami           = "ami-0c55b159cbf"  |   become: yes
  instance_type = "t3.micro"         |   tasks:
}                                    |     - name: Install Nginx
# terraform init -> plan -> apply    |       apt: name=nginx state=present

Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management Quick Reference & Comparison Table

DimensionTerraformAnsible
Primary FocusInfrastructure provisioningConfiguration management & app deploy
Language / FormatHCL (HashiCorp Config Language)YAML Playbooks (Python-based)
State ManagementStateful (terraform.tfstate)Stateless (queries target live)
ArchitectureAPI calls via Cloud ProvidersAgentless push over SSH / WinRM

Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management Top 20 Bilingual MCQs with Answers

Q1. What is the primary role of Terraform compared to Ansible?

(Ansible की तुलना में Terraform की मुख्य भूमिका क्या है?)

(A) Replacing Git for source code version control

(B) Managing in-guest OS packages via SSH only

(C) Acting as a Linux kernel hypervisor

(D) Provisioning and lifecycle management of cloud/infrastructure resources

Correct Answer: (D)

[EN] Terraform specializes in creating, updating, and destroying cloud infrastructure (VPCs, VMs, RDS, DNS).

[HI] Terraform क्लाउड इंफ्रास्ट्रक्चर (VPC, VM, डेटाबेस, DNS) को बनाने और उनके जीवनचक्र प्रबंधन में विशेषज्ञ है।

Q2. Which file format and language does Terraform primarily use for configuration?

(टेराफॉर्म कॉन्फ़िगरेशन के लिए मुख्य रूप से किस भाषा का उपयोग करता है?)

(A) Ruby DSL

(B) YAML Playbooks

(C) XML Schema

(D) HCL (HashiCorp Configuration Language)

Correct Answer: (D)

[EN] Terraform configurations are written in `.tf` files using HCL (or JSON).

[HI] टेराफॉर्म कॉन्फ़िगरेशन HCL (HashiCorp Configuration Language) में `.tf` फाइलों में लिखे जाते हैं।

Q3. Why is Ansible described as 'agentless'?

(एन्सिबल को 'एजेंटलेस' (agentless) क्यों कहा जाता है?)

(A) Target managed nodes do not need any persistent Ansible agent daemon installed

(B) It does not require an operating system on targets

(C) It works without any network connection

(D) It has no control node

Correct Answer: (A)

[EN] Ansible connects from the control node over standard SSH (or WinRM) and executes temporary modules on targets.

[HI] एन्सिबल को टारगेट सर्वर पर किसी स्थायी एजेंट सॉफ्टवेयर की आवश्यकता नहीं होती; यह सीधे SSH/WinRM से काम करता है।

Q4. What is the purpose of `terraform.tfstate`?

(`terraform.tfstate` फाइल का क्या उद्देश्य है?)

(A) Acts as an Ansible inventory file

(B) Stores SSH private keys of all developers

(C) Maps declared HCL resources to real-world infrastructure IDs and tracks current state

(D) Compiles Python scripts into machine code

Correct Answer: (C)

[EN] Terraform compares desired `.tf` config against `terraform.tfstate` to generate an execution plan.

[HI] टेराफॉर्म वांछित `.tf` कोड की तुलना `terraform.tfstate` से करके आवश्यक बदलावों का प्लान बनाता है।

Q5. Which Terraform command shows a dry-run preview of creations, updates, and destructions without applying them?

(कौन-सा टेराफॉर्म कमांड बिना बदलाव लागू किए निर्माण, अपडेट और डिलीट का पूर्वावलोकन (dry-run) दिखाता है?)

(A) terraform apply

(B) terraform destroy

(C) terraform plan

(D) terraform fmt

Correct Answer: (C)

[EN] `terraform plan` computes and displays the diff before `terraform apply` executes API calls.

[HI] `terraform plan` वास्तविक क्लाउड संसाधनों को बदले बिना संभावित परिवर्तनों की सूची दिखाता है।

Q6. In Ansible, which file format is used to write Playbooks?

(एन्सिबल में प्लेबुक्स लिखने के लिए किस फाइल फॉर्मेट का उपयोग किया जाता है?)

(A) TOML

(B) HCL

(C) INI only

(D) YAML

Correct Answer: (D)

[EN] Ansible Playbooks are written in YAML, while Inventory files commonly use INI or YAML.

[HI] एन्सिबल प्लेबुक्स YAML फॉर्मेट में लिखी जाती हैं।

Q7. What is 'configuration drift' in Infrastructure as Code?

(इंफ्रास्ट्रक्चर एज कोड में 'कॉन्फ़िगरेशन ड्रिफ्ट' (Configuration Drift) क्या है?)

(A) Encrypting Terraform state files

(B) When actual running infrastructure diverges from the versioned IaC definition due to manual changes

(C) Moving VMs from AWS to Azure automatically

(D) Upgrading Ansible from Python 3.8 to 3.11

Correct Answer: (B)

[EN] Manual console edits cause drift; running `terraform plan` or Ansible in check mode detects and reconciles drift.

[HI] मैनुअल बदलावों के कारण वास्तविक इंफ्रास्ट्रक्चर और IaC कोड के बीच अंतर आ जाना कॉन्फ़िगरेशन ड्रिफ्ट कहलाता है।

Q8. Why is storing `terraform.tfstate` in a remote backend (like AWS S3 with locking) recommended for teams?

(टीमों के लिए `terraform.tfstate` को रिमोट बैकएंड (जैसे लॉकिंग के साथ S3) में रखना क्यों अनुशंसित है?)

(A) To automatically convert HCL into Ansible YAML

(B) To eliminate the need for cloud IAM credentials

(C) Prevents concurrent `apply` race conditions via state locking and keeps state shared and encrypted

(D) Because local disks cannot store JSON files

Correct Answer: (C)

[EN] State locking stops two engineers from mutating infrastructure simultaneously and corrupting state.

[HI] रिमोट बैकएंड स्टेट लॉकिंग प्रदान करता है ताकि दो इंजीनियर एक साथ `apply` चलाकर स्टेट को खराब न करें।

Q9. What does 'idempotency' mean for an Ansible task like `apt: name=nginx state=present`?

(एन्सिबल टास्क `apt: name=nginx state=present` के लिए 'आइडेम्पोटेंसी' का क्या अर्थ है?)

(A) The task reinstalls nginx from scratch every single run

(B) The task cannot be run on Ubuntu

(C) Running the playbook 1 time or 10 times leaves nginx installed without errors or duplicate actions

(D) The task runs only once and deletes itself

Correct Answer: (C)

[EN] Ansible checks if nginx is already present; if so, it reports `ok` (unchanged) rather than `changed`.

[HI] यदि nginx पहले से इंस्टॉल है, तो दोबारा चलाने पर भी सिस्टम की स्थिति नहीं बदलती और कोई त्रुटि नहीं आती।

Q10. Which mechanism does Ansible use to connect to Windows managed nodes?

(एन्सिबल Windows मैनेज्ड नोड्स से कनेक्ट करने के लिए किस प्रोटोकॉल का उपयोग करता है?)

(A) SNMPv1

(B) WinRM (Windows Remote Management)

(C) NFS

(D) Telnet

Correct Answer: (B)

[EN] Ansible uses SSH for Linux/Unix targets and WinRM (or OpenSSH on modern Windows) for Windows targets.

[HI] एन्सिबल Linux के लिए SSH और Windows नोड्स के लिए WinRM का उपयोग करता है।

Q11. In Terraform, which command must be run first in a new directory to download provider plugins and initialize the backend?

(नई डायरेक्टरी में प्रोवाइडर प्लगइन्स डाउनलोड करने और बैकएंड शुरू करने के लिए सबसे पहले कौन-सा टेराफॉर्म कमांड चलाया जाता है?)

(A) terraform validate

(B) terraform init

(C) terraform import

(D) terraform apply

Correct Answer: (B)

[EN] `terraform init` downloads required provider binaries (e.g., hashicorp/aws) and configures state backends.

[HI] `terraform init` आवश्यक प्रोवाइडर प्लगइन्स डाउनलोड करता है और स्टेट बैकएंड को इनिशियलाइज करता है।

Q12. Which statement best describes 'Immutable Infrastructure'?

('इम्यूटेबल इंफ्रास्ट्रक्चर' (Immutable Infrastructure) का सबसे सही वर्णन कौन-सा है?)

(A) Firewall rules are hardcoded in BIOS

(B) Servers are never modified in-place after deployment; updates replace them with newly built images

(C) Servers cannot be restarted after boot

(D) Configuration files are never stored in Git

Correct Answer: (B)

[EN] Replacing servers from golden images (Packer + Terraform) eliminates configuration drift across fleets.

[HI] इसमें सर्वरों को सीधे अपडेट करने के बजाय नई इमेज से नया सर्वर बनाकर पुराने को बदल दिया जाता है।

Q13. How does Ansible determine which target servers a playbook should run against?

(एन्सिबल यह कैसे तय करता है कि प्लेबुक किन टारगेट सर्वरों पर चलानी है?)

(A) By reading `terraform.tfstate` natively without plugins

(B) Using the Inventory file (hostnames/IPs and groups)

(C) By broadcasting ARP packets on port 80

(D) Through DNS TXT records only

Correct Answer: (B)

[EN] An Ansible Inventory (static INI/YAML or dynamic cloud script) lists hosts and host groups.

[HI] एन्सिबल इन्वेंटरी फाइल (स्टैटिक या डायनामिक) में सूचीबद्ध होस्ट्स और समूहों के आधार पर टारगेट चुनता है।

Q14. Which tool is an open-source fork of Terraform created after HashiCorp changed Terraform's license to BSL?

(HashiCorp द्वारा टेराफॉर्म का लाइसेंस BSL में बदलने के बाद बनाया गया ओपन-सोर्स फोर्क कौन-सा है?)

(A) OpenTofu

(B) PulumiJS

(C) Chef Solo

(D) Puppet Bolt

Correct Answer: (A)

[EN] OpenTofu is the Linux Foundation-hosted open-source fork of Terraform maintaining HCL compatibility.

[HI] OpenTofu टेराफॉर्म का Linux Foundation समर्थित ओपन-सोर्स फोर्क है जो HCL के साथ संगत है।

Q15. What happens if you run `terraform apply` after manually deleting an EC2 instance in the AWS Console?

(यदि आप AWS Console में जाकर मैनुअल रूप से एक EC2 इंस्टेंस डिलीट कर दें और फिर `terraform apply` चलाएं तो क्या होगा?)

(A) Terraform ignores the deletion permanently

(B) Terraform deletes all `.tf` files automatically

(C) Terraform refreshes state, detects the missing resource, and recreates it to match the HCL code

(D) Terraform converts the EC2 instance into an S3 bucket

Correct Answer: (C)

[EN] During refresh, Terraform sees the resource no longer exists in AWS and plans to recreate it.

[HI] स्टेट रिफ्रेश के दौरान टेराफॉर्म को पता चलता है कि संसाधन गायब है, और वह HCL कोड के अनुसार उसे पुनः बना देता है।

Q16. Which of the following statements comparing Terraform and Ansible is NOT true?

(Terraform और Ansible की तुलना करने वाला निम्नलिखित में से कौन-सा कथन सत्य नहीं है?)

(A) Terraform is stateful and tracks resources in a state file

(B) Ansible is primarily designed for configuration management and orchestration

(C) Terraform and Ansible are frequently used together in production pipelines

(D) Ansible requires installing a dedicated persistent agent daemon on every Linux target server

Correct Answer: (D)

[EN] Ansible is famously agentless on Linux, communicating directly over SSH without a persistent target daemon.

[HI] एन्सिबल एजेंटलेस है; इसे Linux टारगेट सर्वर पर किसी स्थायी एजेंट डेमन की आवश्यकता नहीं होती।

Q17. Within Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management, which dimension directly maps to: "Infrastructure provisioning"?

(Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management में कौन सा Dimension सीधे "Infrastructure provisioning" से संबंधित है?)

(A) Language / Format

(B) Architecture

(C) Primary Focus

(D) State Management

Correct Answer: (C)

[EN] In Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management, 'Primary Focus' handles 'Infrastructure provisioning' (Configuration management & app deploy).

[HI] Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management में 'Primary Focus' का कार्य/विवरण 'Infrastructure provisioning' (Configuration management & app deploy) है।

Q18. Which option accurately describes 'Language / Format' in Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management?

(Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management के संदर्भ में 'Language / Format' की सही विशेषता कौन सी है?)

(A) Infrastructure provisioning

(B) API calls via Cloud Providers

(C) HCL (HashiCorp Config Language)

(D) Stateful (terraform.tfstate)

Correct Answer: (C)

[EN] 'Language / Format' provides 'HCL (HashiCorp Config Language)' — key point: YAML Playbooks (Python-based).

[HI] 'Language / Format' का मुख्य विवरण 'HCL (HashiCorp Config Language)' है (YAML Playbooks (Python-based))।

Q19. In Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management, identify the correct parameter for the specification: "Stateful (terraform.tfstate)".

(Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management में "Stateful (terraform.tfstate)" विवरण किस विकल्प के लिए सही है?)

(A) Primary Focus

(B) State Management

(C) Language / Format

(D) Architecture

Correct Answer: (B)

[EN] 'State Management' corresponds to 'Stateful (terraform.tfstate)' (Stateless (queries target live)).

[HI] 'State Management' का संबंध 'Stateful (terraform.tfstate)' (Stateless (queries target live)) से है।

Q20. Considering Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management, what key behavior defines 'Architecture'?

(Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management में 'Architecture' की मुख्य भूमिका या मान क्या है?)

(A) Infrastructure provisioning

(B) HCL (HashiCorp Config Language)

(C) API calls via Cloud Providers

(D) Stateful (terraform.tfstate)

Correct Answer: (C)

[EN] 'Architecture' represents 'API calls via Cloud Providers' (Agentless push over SSH / WinRM).

[HI] 'Architecture' का अर्थ/मान 'API calls via Cloud Providers' है (Agentless push over SSH / WinRM)।

Infrastructure as Code (IaC): Terraform vs Ansible Configuration Management — Exam FAQs

Q1: Should I choose Terraform or Ansible if I can only pick one?

यदि केवल एक ही चुनना हो तो Terraform या Ansible में से किसे चुनना चाहिए?

[EN] Choose Terraform if your main need is multi-cloud infrastructure provisioning (VPCs, VMs, managed DBs); choose Ansible if your main need is OS/software configuration on existing servers.

[HI] क्लाउड संसाधन (VPC, VM, DB) बनाने के लिए Terraform चुनें, और मौजूदा सर्वरों पर सॉफ्टवेयर/OS कॉन्फ़िगरेशन के लिए Ansible चुनें।

Q2: Can Terraform execute Ansible playbooks automatically?

क्या Terraform स्वचालित रूप से Ansible प्लेबुक्स चला सकता है?

[EN] Yes, via `local-exec` provisioners or cloud-init/user_data, though decoupling them in CI/CD pipelines (Terraform then Ansible) is cleaner.

[HI] हां, `local-exec` प्रोविजनर से संभव है, हालांकि CI/CD पाइपलाइन में पहले Terraform और फिर Ansible चलाना बेहतर माना जाता है।

Q3: What is the difference between `terraform.tfstate` and `terraform.tfvars`?

`terraform.tfstate` और `terraform.tfvars` में क्या अंतर है?

[EN] `terraform.tfstate` tracks deployed resource state (auto-managed), while `terraform.tfvars` supplies input variable values (user-authored).

[HI] `terraform.tfstate` डिप्लॉय किए गए संसाधनों की वर्तमान स्थिति ट्रैक करता है, जबकि `terraform.tfvars` इनपुट वेरिएबल्स के मान प्रदान करता है।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)