Ansible

Skill
DevOps

Top 30 Ansible Interview Questions and Answers 2025

33 questions found

Updated 3 Nov 2024

Q1. What to define in the ansible inventory file?

Ans.

The ansible inventory file defines the hosts and groups that ansible can manage.

  • Hosts and groups are defined using INI or YAML syntax

  • Hosts can have variables defined for them

  • Groups can have child groups and variables defined for them

  • Inventory files can be static or dynamic

  • Examples: [webservers] web1.example.com web2.example.com [databases] db1.example.com [all:vars] ansible_user=ubuntu

Add your answer
Frequently asked in

Q2. what is ansible and docker

Ans.

Ansible is a configuration management tool while Docker is a containerization platform.

  • Ansible automates software provisioning, configuration management, and application deployment.

  • Docker allows developers to package applications and dependencies into containers for easy deployment and scalability.

  • Ansible can be used to manage Docker containers and orchestrate container deployments.

  • Docker can be used with Ansible to create and manage containerized environments.

  • Both Ansible an...read more

Add your answer
Frequently asked in

Q3. What is ansible and terraform?

Ans.

Ansible and Terraform are both infrastructure as code tools used for automation and configuration management.

  • Ansible is a tool for automating software provisioning, configuration management, and application deployment.

  • Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently.

  • Ansible uses YAML-based playbooks to define tasks and configurations, while Terraform uses a domain-specific language (DSL) called HCL.

  • Both tools are popular in the ...read more

Add your answer

Q4. How to use ansible variables?

Ans.

Ansible variables can be used to store and retrieve values in playbooks and templates.

  • Variables can be defined in inventory files, playbooks, or roles

  • Variables can be accessed using the {{ variable_name }} syntax

  • Variables can be set using the set_fact module

  • Variables can be passed as arguments to roles or playbooks

  • Variables can be used in templates to dynamically generate files

Add your answer
Frequently asked in
Are these interview questions helpful?

Q5. Where does Ansible server maintains the inventory?

Ans.

Ansible server maintains the inventory in a file called 'hosts' by default.

  • Ansible server maintains the inventory in a file called 'hosts' by default

  • The 'hosts' file can be located in the /etc/ansible/ directory or specified using the -i option

  • Inventory can also be stored in dynamic inventory sources like AWS EC2, Azure, etc.

Add your answer

Q6. Explain modules in Ansible

Ans.

Ansible modules are reusable, standalone scripts that can be used to automate tasks in Ansible.

  • Modules are the building blocks of Ansible playbooks

  • They can be used to perform specific tasks like installing packages, managing files, or configuring services

  • Modules can be written in any language that can return JSON

  • Examples of modules include 'yum' for package management, 'copy' for file management, and 'service' for managing services

Add your answer
Frequently asked in
Share interview questions and help millions of jobseekers 🌟

Q7. What are roles in ansible

Ans.

Roles in Ansible are a way to group tasks, handlers, variables, and other related files together for easier management and reuse.

  • Roles help in organizing and structuring Ansible playbooks

  • They promote reusability and modularity

  • Roles can be shared and reused across different playbooks

  • Each role typically consists of directories like tasks, handlers, templates, vars, etc.

  • Roles can be installed using Ansible Galaxy

Add your answer
Frequently asked in

Q8. What is ansbible

Ans.

Ansible is an open-source automation tool used for configuration management, application deployment, and orchestration.

  • Ansible uses YAML syntax for its playbooks

  • It does not require agents to be installed on managed nodes

  • Ansible can automate tasks across multiple servers simultaneously

Add your answer

Ansible Jobs

Cloud Software Development Engineer 4-6 years
Intel Technology India Pvt Ltd
4.3
Bangalore / Bengaluru
Cloud Software Development Engineer 3-6 years
Intel Technology India Pvt Ltd
4.3
Bangalore / Bengaluru
Sr DevOps Engineer 12-17 years
IBM India Pvt. Limited
4.1
Bangalore / Bengaluru

Q9. How error handling in ansible

Ans.

Error handling in Ansible involves using various modules and strategies to manage and respond to errors during playbook execution.

  • Use the 'failed_when' directive in tasks to specify conditions that should result in a task failure.

  • Utilize the 'ignore_errors' directive to continue executing tasks even if errors occur.

  • Implement error handling with 'rescue' and 'always' blocks in playbooks to handle errors and cleanup tasks.

  • Use the 'failed_when' and 'changed_when' directives to c...read more

Add your answer
Frequently asked in

Q10. Write an Ansible script

Ans.

Ansible script to automate tasks

  • Use YAML syntax to define tasks and playbooks

  • Utilize Ansible modules for different operations

  • Define hosts and groups in inventory file

  • Use variables and templates for dynamic configurations

Add your answer

Q11. Explain Ansible architecture

Ans.

Ansible architecture is based on a client-server model where the control machine communicates with managed nodes using SSH.

  • Ansible control machine: where playbooks are written and executed

  • Managed nodes: machines that are being managed by Ansible

  • Inventory: list of managed nodes

  • Playbooks: automation scripts written in YAML format

  • Modules: reusable units of code that perform specific tasks on managed nodes

Add your answer
Frequently asked in

Q12. Store ansible secrets Trigger pipeline after another

Ans.

Store ansible secrets securely and trigger pipeline after another

  • Use ansible-vault to encrypt sensitive data like passwords and API keys

  • Store encrypted secrets in a separate file or in a secure vault

  • Use ansible-playbook to trigger pipelines sequentially or use a CI/CD tool like Jenkins for automation

Add your answer
Frequently asked in

Q13. where do you save ansible files

Ans.

Ansible files are typically saved in a version control system like Git for easy access and collaboration.

  • Save ansible files in a version control system like Git

  • Create separate repositories for different projects or roles

  • Organize files into directories based on their purpose or role

  • Use naming conventions to easily identify files and their functions

Add your answer
Frequently asked in

Q14. what are packages we use in ansible?

Ans.

Some common packages used in Ansible are ansible, ansible-lint, ansible-playbook, ansible-vault, and ansible-doc.

  • ansible

  • ansible-lint

  • ansible-playbook

  • ansible-vault

  • ansible-doc

Add your answer

Q15. explain dynamic inventory in ansible

Ans.

Dynamic inventory is a feature in Ansible that allows for automatic inventory updates based on external data sources.

  • Dynamic inventory can be configured to pull inventory information from sources such as cloud providers, configuration management databases, or custom scripts.

  • This allows for more flexible and scalable inventory management, as hosts can be added or removed automatically based on changes in the external data source.

  • Dynamic inventory can be configured using plugin...read more

Add your answer
Frequently asked in

Q16. How to create VMs using ansible?

Ans.

VMs can be created using ansible by defining the virtual machine specifications in a playbook and running it on the target host.

  • Define the virtual machine specifications in a playbook using the 'virt' module

  • Specify the name, memory, vCPU, disk, network, and other details of the VM in the playbook

  • Run the playbook on the target host using the 'ansible-playbook' command

Add your answer

Q17. Wt is ansible and how to write play book in ansible?

Ans.

Ansible is an open-source automation tool used for configuration management, application deployment, and task automation.

  • Ansible uses YAML syntax to write playbooks

  • Playbooks contain a set of tasks to be executed on remote hosts

  • Ansible uses SSH protocol to connect and execute tasks on remote hosts

  • Playbooks can be used for various tasks such as installing packages, configuring services, and managing users

  • Example playbook: - name: Install Apache hosts: webserver become: true tas...read more

Add your answer

Q18. Write play book to copy files in ansible

Ans.

Playbook to copy files in Ansible

  • Use the 'copy' module in Ansible to copy files

  • Specify source and destination paths in the playbook

  • Run the playbook using 'ansible-playbook' command

Add your answer
Frequently asked in

Q19. What is Ansible Ansible commands

Ans.

Ansible is an open-source automation tool that simplifies IT orchestration and configuration management.

  • Ansible is agentless and uses SSH or WinRM to communicate with remote machines

  • It uses YAML syntax for writing playbooks that define the desired state of the system

  • Ansible modules are used to perform specific tasks on remote machines

  • Some commonly used Ansible commands are ansible-playbook, ansible-galaxy, ansible-vault, etc.

Add your answer

Q20. How would you install Apache Server using Ansible

Ans.

To install Apache Server using Ansible, you can create an Ansible playbook with tasks to install Apache and start the service.

  • Create an Ansible playbook with tasks to install Apache Server package (e.g. apache2) using the 'apt' module.

  • Include a task to ensure Apache service is started and enabled using the 'service' module.

  • Run the playbook using the 'ansible-playbook' command to execute the tasks and install Apache Server.

Add your answer

Q21. How does ansible works with windows, any scenarios that you can explain

Ans.

Ansible works with Windows by using PowerShell remoting and WinRM to manage Windows servers.

  • Ansible uses PowerShell remoting and WinRM to communicate with Windows servers.

  • It can execute PowerShell scripts and commands on Windows servers.

  • Ansible can manage Windows services, install software, and configure Windows settings.

  • It supports managing Windows Server, Windows 10, and older versions of Windows.

  • Ansible can join Windows machines to a domain, manage Active Directory, and co...read more

Add your answer

Q22. Ansible different playbooks

Ans.

Ansible playbooks are YAML files that define a set of tasks to be executed on a target host.

  • Playbooks can be used to install software, configure services, and manage files on remote hosts.

  • Each playbook can contain multiple plays, each targeting a specific group of hosts.

  • Playbooks can also include variables, conditionals, and loops to make them more flexible and reusable.

  • Examples of Ansible playbooks include setting up a web server, deploying an application, and configuring ne...read more

Add your answer

Q23. dry run in ansible?

Ans.

Dry run in Ansible is a simulation of playbook execution without making any actual changes on the target hosts.

  • Dry run can be performed using the --check flag in ansible-playbook command.

  • It allows the user to see what changes would be made without actually applying them.

  • Useful for testing playbooks before running them in production environment.

  • Example: ansible-playbook playbook.yml --check

Add your answer
Frequently asked in

Q24. Variable precedence in Ansible

Ans.

Variable precedence in Ansible

  • Ansible follows a specific order to determine variable precedence

  • Highest precedence: Variables defined in playbooks or roles

  • Next: Variables defined in inventory files or inventory plugins

  • Then: Variables defined in command line or extra vars

  • Lowest precedence: Variables defined in role defaults or inventory group_vars

View 1 answer
Frequently asked in

Q25. What is difference between Dockers and ansible

Ans.

Docker is a containerization platform used to package and run applications, while Ansible is a configuration management tool used for automating IT infrastructure tasks.

  • Docker is used to create containers that encapsulate an application and its dependencies, providing a lightweight and portable environment.

  • Ansible is used for automating tasks such as configuration management, application deployment, and orchestration of IT infrastructure.

  • Docker containers are isolated environ...read more

Add your answer

Q26. what is ansible and what is the difference between ansible and terraform?

Ans.

Ansible is a configuration management and automation tool, while Terraform is an infrastructure provisioning tool.

  • Ansible is used for configuration management, application deployment, and task automation.

  • Terraform is used for infrastructure provisioning and managing cloud resources.

  • Ansible uses YAML-based playbooks to define tasks and configurations, while Terraform uses HCL (HashiCorp Configuration Language) to define infrastructure as code.

  • Ansible is agentless, meaning it d...read more

Add your answer

Q27. Command to list all hosts of Ansible inventiory.

Ans.

The command to list all hosts of Ansible inventory is 'ansible-inventory --list'.

  • Use the 'ansible-inventory' command

  • Add the '--list' option to list all hosts

  • The command should be run from the command line

Add your answer

Q28. what are the modules in anasible ?

Ans.

Ansible modules are reusable, standalone scripts that can be used to automate tasks in Ansible.

  • Modules are categorized into core modules and extras modules.

  • Core modules are included in the Ansible package, while extras modules are available as separate packages.

  • Examples of core modules include command, file, and service modules.

  • Examples of extras modules include community contributed modules like AWS, Docker, and Git modules.

Add your answer
Frequently asked in

Q29. What is roles in ansible?

Ans.

Roles in Ansible are a way to group tasks, handlers, variables, and other related files together for easier management and reuse.

  • Roles help in organizing and structuring Ansible playbooks.

  • They promote reusability and modularity by allowing tasks to be grouped together.

  • Roles can be shared and reused across different playbooks.

  • Each role typically consists of directories like tasks, handlers, templates, vars, and defaults.

  • Roles can be installed using Ansible Galaxy or manually c...read more

Add your answer

Q30. Ansible playbook about upgrading apache

Ans.

An Ansible playbook for upgrading Apache

  • Use the 'yum' module to update the Apache package

  • Restart the Apache service using the 'systemd' module

  • Include error handling in case the update fails

Add your answer
Frequently asked in

Q31. Different between Terraform and ansible

Ans.

Terraform is used for infrastructure provisioning and management, while Ansible is used for configuration management and automation.

  • Terraform is used for defining and managing infrastructure as code, focusing on provisioning resources like virtual machines, networks, and storage.

  • Ansible is used for configuration management and automation of software deployment, focusing on tasks like installing packages, configuring services, and managing files.

  • Terraform uses declarative lang...read more

Add your answer

Q32. Modules in Anaible

Ans.

Modules in Ansible are reusable, standalone scripts that can be used to perform specific tasks.

  • Modules can be written in any programming language

  • Modules can be executed on remote hosts

  • Modules can be used to install packages, manage files, and perform other tasks

  • Modules can be found in the Ansible library or created by users

  • Examples of modules include apt, yum, and copy

Add your answer
Frequently asked in

Q33. Ansible terraform usage

Ans.

Ansible and Terraform are tools used for automation and infrastructure management.

  • Ansible is used for configuration management and automation of IT infrastructure.

  • Terraform is used for infrastructure as code and provisioning of resources.

  • Both tools can be used together to manage infrastructure and automate deployment.

  • Ansible can be used to configure servers and deploy applications, while Terraform can be used to provision the necessary infrastructure.

  • For example, Ansible can ...read more

Add your answer
Frequently asked in
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview Questions of Ansible Related Designations

Interview experiences of popular companies

3.7
 • 10.3k Interviews
3.9
 • 8k Interviews
3.7
 • 7.5k Interviews
3.7
 • 5.5k Interviews
3.8
 • 4.8k Interviews
View all
Ansible Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter