Ansible interview questions and answers 👇

  1. Ansible Interview Questions


Ansible Interview Questions

What is Ansible Galaxy?

View answer

Ansible Galaxy is the Galaxy website where users can share roles, and to a command line tool for installing, creating and managing roles.

What is CI/CD?

View answer

CI/CD is a method to frequently deliver apps to customers by introducing automation into the stages of app development. The main concepts attributed to CI/CD are continuous integration, continuous delivery, and continuous deployment. CI/CD is a solution to the problems integrating new code can cause for development and operations teams.

What is Configuration Management?

View answer

Ansible is a configuration management platform that automates storage, servers, and networking. When you use Ansible to configure these components, difficult manual tasks become repeatable and less vulnerable to error.

What is a YAML file?

View answer

Ansible uses YAML syntax for expressing Ansible playbooks. YAML uses simple key-value pair to represent the data.

What is Ansible Tower and what are its features?

View answer

YAML is a serialization language that has steadily increased in popularity over the last few years. It is often used as a format for configuration files, but its object serialization abilities make it a viable replacement for languages like JSON.

What is Infrastructure as Code?

View answer

Infrastructure as Code (IaC) is a process for managing and operating data servers, storage systems, system configurations, and network infrastructure.

In traditional configuration management practices, every minor configuration change requires manual action by system administrators and the IT support team. With IaC, all configuration details are managed and stored in a standardized file system, wherein the system automatically manages infrastructure changes and deals with system configurations.

Tools such as Ansible can be used to implement IaC approach.

What is Ansible Vault?

View answer

Ansible Vault can encrypt entire files, entire YAML playbooks or even a few variables. It provides a facility where you can not only encrypt sensitive data but also integrate them into your playbooks.

Vault is implemented with file-level granularity where the files are either entirely encrypted or entirely unencrypted. It uses the same password for encrypting as well as for decrypting files which makes using Ansible Vault very user-friendly.

How can looping be done over a list of hosts in a group, inside of a template?

View answer

An easy way to do this is to iterate over a list of hosts inside of a host group, in order to fill a template configuration file with a list of servers. In order to access facts about these hosts, like, the IP address of each hostname, you need to make sure that the facts have been populated.

What are callback plugins in Ansible?

View answer

Callback plugins enable adding new behaviors to Ansible when responding to events. By default, callback plugins control most of the output you see when running the command line programs, but can also be used to add additional output, integrate with other tools and marshal the events to a storage backend.

How does Ansible synchronize module work?

View answer

synchronize is a wrapper around rsync to make common tasks in your playbooks quick and easy. It is run and originates on the local host where Ansible is being run. Of course, you could just use the command action to call rsync yourself, but you also have to add a fair number of boilerplate options and host facts.

Describe Ansible register.

View answer

Ansible register is a way to capture the output from task execution and store it in a variable. This is important, as this output is different for each remote host, and the basis on that we can use conditions loops to do some other tasks. Also, each register value is valid throughout the playbook execution.

What is “idempotency”?

View answer

The resource models are idempotent meaning change commands are not run unless needed, and Ansible will bring the system back to a desired state regardless of the actual state – rather than you having to tell it how to get to the state.

Explain “facts” in the context of Ansible.

View answer

Ansible facts are data gathered about target nodes (host nodes to be configured) and returned back to controller nodes. Ansible facts are stored in JSON format and are used to make important decisions about tasks based on their statistics.

What is an ad hoc command?

View answer

Ad hoc commands are commands which can be run individually to perform quick functions. These commands need not be performed later. For example, you have to reboot all your company servers. For this, you will run the Adhoc commands from '/usr/bin/ansible'.

What is a handler?

View answer

Handlers are special tasks that only get executed when triggered via the notify directive. Handlers are executed at the end of the play, once all tasks are finished. In Ansible, handlers are typically used to start, reload, restart, and stop services.

How do you access shell environment variables?

View answer

Explain Ansible architecture.

View answer

The main component of Ansible is the Ansible automation engine. This engine directly interacts with various cloud services, Configuration Management Database (CMBD) and different users who write various playbooks to execute the Ansible Automation engine.

The Ansible Automation engine consists of the following components:

  • Inventories: A list of nodes containing their respective IP addresses, servers, databases, etc. which need to be managed.
  • APIs: Ansible APIs are used for commuting various Cloud services, public or private services.
  • Modules: Used to manage system resources, packages, libraries, files, etc. Ansible modules can be used to automate a wide range of tasks. Ansible provides around 450 modules that automate nearly every part of the environment.
  • Plugins: If you want to execute Ansible tasks as a job, Ansible Plugins can be used. They simplify the execution of a task by building a job like an environment that basically contains pieces of code corresponding to some specific functionality. There are 100s of Plugins provided by Ansible.
  • Networking: Ansible can also be used to automate different networks and services. It can do this by creating a playbook or an Ansible role that easily spans different network hardware.
  • Hosts: Ansible Hosts/ Node systems are machines (Linux, Windows, etc) that are getting automated.
  • Playbooks: Playbooks are simple code files which describe the tasks that need to be executed. The Playbooks are written in YAML format. They can be used to automate tasks, declare configurations, etc.
  • CMDB: It is a database that acts as a storehouse for various IT installations. It holds data about various IT assets (also known as configuration items (CI)) and describes the relationships between such assets.
  • Cloud: It is a network of remote servers hosted on the Internet to store, manage, and process data, rather than a local server.

What is Role in Ansible?

View answer

An Ansible role is a pre-defined way for organizing playbooks and other files in order to facilitate sharing and reusing portions of provisioning.

What are Tasks in Ansible?

View answer

Ansible Tasks allow you to break up bits of configuration policy into smaller files. These are blocks of code that can be used to automate any process.

How would you configure a jump host to access servers that you have no direct access to?

View answer

The first step would be to set a ProxyCommand in the ansible_ssh_common_args inventory variable. All arguments that are defined in this variable are added to the sftp/scp/ssh command line when connecting to the relevant host.

Describe the ask_pass module in Ansible.

View answer

Ask_pass is the control module in an Ansible playbook. This controls the prompting of the password when the playbook is getting executed. By default, it’s always set to True. If you are using SSH keys for authentication purposes then you don’t need to change this setting at all.