Ansible
Top 30 Ansible Interview Questions and Answers 2025
33 questions found
Updated 3 Nov 2024
Q1. What to define in the ansible inventory file?
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
Q2. what is ansible and docker
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
Q3. What is ansible and terraform?
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
Q4. How to use ansible variables?
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
Q5. Where does Ansible server maintains the inventory?
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.
Q6. Explain modules in Ansible
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
Q7. What are roles in ansible
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
Q8. What is ansbible
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
Ansible Jobs
Q9. How error handling in ansible
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
Q10. Write an Ansible script
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
Q11. Explain Ansible architecture
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
Q12. Store ansible secrets Trigger pipeline after another
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
Q13. where do you save ansible files
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
Q14. what are packages we use in ansible?
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
Q15. explain dynamic inventory in ansible
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
Q16. How to create VMs using ansible?
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
Q17. Wt is ansible and how to write play book in ansible?
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
Q18. Write play book to copy files in ansible
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
Q19. What is Ansible Ansible commands
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.
Q20. How would you install Apache Server using Ansible
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.
Q21. How does ansible works with windows, any scenarios that you can explain
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
Q22. Ansible different playbooks
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
Q23. dry run in ansible?
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
Q24. Variable precedence in Ansible
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
Q25. What is difference between Dockers and ansible
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
Q26. what is ansible and what is the difference between ansible and terraform?
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
Q27. Command to list all hosts of Ansible inventiory.
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
Q28. what are the modules in anasible ?
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.
Q29. What is roles in ansible?
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
Q30. Ansible playbook about upgrading apache
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
Q31. Different between Terraform and ansible
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
Q32. Modules in Anaible
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
Q33. Ansible terraform usage
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
Top Interview Questions for Related Skills
Interview Questions of Ansible Related Designations
Interview experiences of popular companies
Reviews
Interviews
Salaries
Users/Month