Ansible Interview Questions and Answers

bookmark

Categories

Ansible


Ansible Interview Questions and Answers Online Training

Enroll Today

Top Ansible Interview Questions and Answers - 2021 [UPDATED]

Are you looking for Ansible Interview Questions and Answers? Than you are at the Right Place. Browse through Popular and Most Asked Interview Questions for Ansible.  There is a Huge Demand for Ansible Professionals in the Market. These Questions are suitable for both Freshers and Experienced Professionals and are based on Trending Topics and as per Current Industry Requirements.

Master These Topics and Increase your Chances in cracking Ansible Interviews like a pro and Secure your Dream Job Today.

Ansible Interview Questions and Answers

  • 80 Questions

Ansible is the well-recognized open-source platform written and developed in Python language. This platform facilitates task automation, configuration management, and application deployment. It uses the SSH approach to deploy the application without any specific downtime.

automation is a crucial part of any software development process. The Ansible platform used in managing various IT infrastructure. It is also used for deploying software applications to remote nodes.

Using Ansible can be beneficial in numerous ways. Then three of its advantages are mentioned below: Agentless Very low overhead and easy to learn Great performance Consistent with security Reliable

As Ansible facilitates bundling automation content. This makes it reusable. The Ansible galleries are needed here to share such Ansible roles. In simple words, the Ansible gallery is the tool which is merged with the Ansible. This integration creates the base directory structure.

It is the practice that involves delivering the software as soon as it is developed. For this, there is a need to use the versioning control system. Even in the live production system the software consistently updates.

There are two main categories of server type in Ansible: the nodes and controlling machine. It simply uses the SSH protocol to deploy modules to nodes. These nodes stored in remote nodes interact with Ansible Machine. The Ansible has the capability to manage more than 100 nodes in one single system.

In Ansible there are two major types of modules: core modules and extra modules. Core Modules: These modules are the first preference of the Ansible team. The core modules come with Ansible software. Extra Modules: The extra modules are reusable but for some reason, they always get a lower rate of response to issues. These are also maintained and managed by the Ansible Community. Although the extra modules are merged with Ansible but one can use it separately in the future.

The Ansible is the web-based center which is used for all kind of automation tasks. There is no requirement to install the daemons to connect with other controlling machines as it is an agentless model. The Ansible tower allows you free usage till ten nodes.

Ansible: The Ansible has the simplest technology written in the YAML language. It can be quickly installed and deployed because of agent-less architecture. The Ansible supports automated workflow for continuous delivery. Puppet: The puppet has complex technology in comparison to Ansible. This is written in Ruby language. To access this, it is important to learn Puppet DSL.

The Ansible is highly based on the agent-less architecture. This structure enables you to connect your nodes. The pool of modules can dwell on any system without any daemons, server or the database. The SSH protocol enables it to execute these modules. It removes them as soon as work is done.

The variable name can be created by adding stings. On the other hand, for the access of environment variable, there is a need to access the existing variables. The variable name uses ipv4 for the available name. For remote environment variables {{ ansible_env.SOME_VARIABLE }} is used.

With the Ansible these are the following things one can do: Deployment of application Configuration management Task automation IT orchestration

The Ansible is written in PowerShell and Python programming language.

The red hat Ansible and Ansible both all the great automation platforms. The end to end complete automation of these platforms makes it capable to provide below-mentioned functionalities: Application deployment Provisioning Management and configuration of IT systems Orchestrating workflows

For the window users, there is a need for the virtual machine in which the Linux should be installed. Otherwise, the Ansible requires Python 2.6 version or the higher one.

Yes, the Ansible allows us to create the modules within it. As it is an open-source tool that majorly runs on Python. This means anyone who has little bit knowledge of programming can create their own modules without any problem within Ansible.

The availability of mkpassword utility in Linux is the best option for generating the crypto passwords. For the OS X users who don’t have this utility installed on your system, they can also generate crypto passwords by using Python.

Ansible automation is consist of the following elements: Inventories Modules APIs Host Playbooks Cloud Networking

In Ansible there are three major ways to reuse files in playbooks which include import and roles.

For accessing shell environment variables in Ansible users need to use the “env” lookup plugin. There are some codes that you have to write for this. The codes are mentioned below: _ _ _ # … vars :

Yes, it is possible to keep secret data in your Ansible content with the use of Vault in playbooks. With V mode you have to use some commands to hide sensitive data from others.

The ad-hocs are used to take action on the hosts without writing the playbooks. So, if you have to reboot the hosts in a specific group then there are two ways to do that. You can either create a new playbook or you can simply use the one-off ad-hoc command.

In the Ansible environment, “fact” is the most commonly addressed term. The facts are used by Ansible to get information about the host and store. The Ansible runs the setup modules to generate these facts.

This “copy” module of Ansible has recursive parameters. You can also utilize “synchronize” modules if you need to perform more efficient for a huge number of files. It is important to use commands with “synchronize” modules.

The Ansible tasks are majorly used to break up bits of configuration policy in little files. These small blocks of code that are used to automate any process.

The Ansible role is completely another level of abstraction. These are used to organize playbooks. It provides an independent structure and a reusable collection of various things. It includes templates, files, variables, tasks, etc.

The Ansible vaults are used to keep all your secret data safe. It facilitates the encryption of sensitive data but also integrates them into your playbooks. The files can either be entirely encrypted or unencrypted, the vault is implemented with file-level granularity. The Ansible vaults are very user-friendly.

The Ansible towers display everything happening in the Ansible environment like inventory status, hosts and other recent activities. It also integrates the notifications about all the necessary updates. The multi-playbook workflow feature of Ansible tower makes it easier to chain all the playbooks. It is also useful for scheduling Ansible jobs.

After installing Ansible on the controlling systems, one inventory file is created which particularly explains the connection between other nodes. The SSH protocol can be used to make a connection. If you want to check its connection, then you can use the ping module. The command to check this connection is: ansible -m ping all

There are hundreds of modules present in Ansible that support AWS. It includes: Autoscaling groups CloudFormation Virtual Private Cloud (VPC) Security Groups Relational Database Service (RDS) CloudTrail Elastic Cloud Compute (EC2)

gather_facts: no gather_facts: False both gather_facts: no or gather_facts: False gather_facts: y Answer: gather_facts: no

/etc/ansible/hosts /etc/inventory /etc/configurations /etc/ansible Answer: /etc/ansible/hosts

Default location for Ansible modules is /usr/share/ansible

File template fetch copy Answer: File

Flush None of the options assest meta Answer: meta

docker_service docker_login docker_image docker Answer: docker_service

only node controlling machines and nodes Answer: controlling machines and nodes

1 5 7 depends upon hosts in the inventory Answer: 5

accelerate port pipelining forks become_method Answer: pipelining

Ansible Puppet chef CFEngine Answer: Ansible

Infrastructure as code Orchestration Engine Configuration management All the options Answer: All the options

{{}} {##} {%%} Answer: {##}

yum install ansible Once the installation is completed, check the ansible version : ansible –version If ansible package is not available in the default yum repositories, we need to manualy download.

It provides passwordless auth to access the managed servers In Control Server. Step 1: Create user for ansible useradd -d /home/gangboard -m gangboard passwd gangboard Step 2: Switch to ansible user Step 3: su – gangboard Step 4: Generate ssh key ssh-keygen -t rsa Step 5: /home/gangboard/.ssh/id_rsa.pub => Public Key is in this file which needs to be copied to nodes ~/.ssh/authorized_keys

Create user for ansible useradd -d /home/tadmin -m tadmin passwd tadmin Step 2: Switch to ansible user su – tadmin Step 3: Create .ssh directory mkdir .ssh Step 4: Change permission to 700 for .ssh chmod 700 .ssh/ Step 5: Change Ownership to tadmin for .ssh chown tadmin:tadmin .ssh/ Step 6: create an authorized_keys file under .ssh and paste the public key from controller and save it Step 7: cd .ssh/ , vi authorized_keys Step 8: Copy & paste the public key from the Controller server to this file [/home/tadmin/.ssh/id_rsa.pub] Now you able to access the server without a password.

The inventory files contain a host list of managed nodes, when ansible accessing the client it look into inventory. The default inventory file for Ansible is located under /etc/ansible/hosts This default inventory lookup can be overridden using -i option providingthe custom inventory file Example: ansible -i cmdb.inv main.yml Update default Inventoryfile/etc/ansible/hosts (as rootuser) [clients] node1 node2

Running ansible command #ansible all -m ping ansible => Ansible command all => Specifies the target to run the command.The target could an individual node or group(mentionedininventoryfile)orall(allthenodesintheinventory file). In this case all is used, which means that the command will be executed on all the nodes. -m is the option that indicates that a module needs to be executed on remote nodes ping is the name of a module. This module checks the ping status of the remote node. It has no attribute parameter (-a)

Expected Outcome of the first command for 4 QUE node1 | SUCCESS => { "changed": false, "ping":"pong" } node2 | SUCCESS =>{ "changed": false, "ping":"pong" } Let’s understand on how to interpret the output Explanation: node1 – This identified the node on which the task is done SUCCESS -Give a confirmation that the module was run successfully “changed”: false – ping module doesn’t do any modification on the remote node. It just checks the ping or node ON status. This the reason the changed status “false”. “ping”:” pong” -This a way ping module confirms the ping reply as“pong”. Note: The output varies from module to module depending on how the module is

The playbook is a .yml file that contains a piece of code called a module. You can have multiple tasks in a playbook and these tasks would be executed by Ansible. Playbooks have a list of remote hosts, user variables, tasks, handlers inside it.

Below is the sample playbook: name: Install Docker and restart service hosts: webapp become: true tasks: name: Install Docker yum: name: docker state: latest name: Restart Docker Service service: name: docker state: restarted

command to run a playbook $ ansible-playbook -i hosts main4.yml -i- This is an option to specify to ansible to override the default inventory file and the inventory file specified. main.yml: This is the playbook file

list-task: List all the tasks that will be executed when you run a playbook.

start-at-task option, will start executing the task you specify and subsequent tasks are executed. The tasks above are skipped.

Variables are used to store values that can be later used in the playbook. Vars: is the tag to define a variable.

They are managed by SSH and also the location of nodes are specified by controlling machine through inventory. You can use ansible-vault to store sensitive information. True False Answer: True

Handlers are similar to tasks in executing modules. The only difference is that the handlers need to be called explicitly. Handlers will be called only on successful change of the state i.e. when the task has done some changes on remote nodes aka. state: changed Within tasks, handlers will be called using “notify” tag. Name given in notify should exactly match as in the -name tag inside handlers

handlers: name: Restart Docker Service service: name: docker state: restarted

Ansible roles consists of many playbooks. Roles are a way to group multiple tasks together into one container. These are reusable scripts.

By using the following command we can create ansible roles Ansible-galaxy init

Playbook may contains Hosts Variables (Optional) Tasks

Ansible is agentless which means it doesn’t require any node machine to configure. It uses YAML to create playbooks which is easy to understand.

If we want to execute tasks whenever something changed in the configuration files then we need to use “notify” in the playbook. For example if we want to restart apache whenever the configuration file changes.

/etc/ansible/hosts file called as inventory. It contains the group of the server name or IP’s.

Ansible modules are building blocks of ansible that are reusable scripts that are used by ansible playbooks.

ansible -m service -a “name= httpd state=stopped” –become

Configuration management is a process of continuous deployment and continuous delivery and continuous monitoring of the many servers in less period of time to achieve deliverables.

— hosts: true role: – apache

by using import_tasks:

ansible-galaxy install username.rolename

It is a file that contains all dynamic configurations parameters which will be having .j2 extension.

using allow_duplicates: true

Role default variables allow you to set the default variables for included or dependencies Dependencies: Role: tire Role: brake

We have concept called ansible-vault .which encrypts the YAML files.

Using ansible-vault encrypt and ansible-vault decrypt