본문 바로가기

IT칼럼/Interview Preparation

Introduction to Ansible Interview Questions And Answer

So you have finally found your dream job in Ansible but are wondering how to crack the Ansible Interview and what could be the probable Ansible Interview Questions. Every interview is different and the scope of a job is different too. Keeping this in mind we have designed the most common Ansible Interview Questions and answers to help you get success in your interview.

Below is the list of common Ansible Interview Questions that are asked mostly in an interview

1.What Is Ansible?

Answer:
Ansible is an open source automation platform. It can help us with configuration management, application deployment or task automation. It can deploy an application using SSH without any downtime. Ansible is developed or written in Python language.

2.What Are The Advantages and use Of Ansible?

Answer:
Ansible has a huge number of benefits:
No Agent: Agent is not required for setting up Ansible. If Box can support ssh and it has python, then no issue to set up Ansible.
Idempotent: Architecture of Ansible is totally structured around the concept of idempotency. The main or core idea is that only those things need to be added which are needed, and those things will be repeatable without side effects.
Declarative not procedural: a Normal attitude of other configuration tools of following a procedural process, means do this then do that and so on. But Ansible normally writes the description of the state of machine what we want and it takes proper steps toward fulfilling that description.
Very Easy to learn and low overhead.

3.How Ansible Works?

Answer:
Ansible mainly categorized into two types of server: controlling machine and Nodes.
Ansible will install on the controlling machine and nodes are managed inside this controlling machine by SSH. Nodes location are specified by controlling machine through its inventory.
Ansible deploys modules to nodes using SSH protocol, these modules are mainly stored temporarily in remote nodes and communicate with the Ansible machine through a JSONconnection over the standard output.
Agent installation in remote nodes is not required for Ansible as it is agentless. So any background process or demon process not running for Ansible when it’s not managing any nodes.
Ansible can able to handle more than 100 of nodes in a single system over SSH connection and only one single command ‘ansible’ can be handled entire operation. But some scenarios we can build ‘playbooks’ where we require to execute multiple commands for a deployment.
Playbooks are actually holding all the sequential command needs to be executed for performing multiple tasks. Playbooks are in YAML file format.

4.What’s the use of Ansible?

Answer:
Ansible mainly used in IT infrastructure to manage or deploy applications to remote nodes. Suppose we want to deploy one application in 100 nodes by just executing one command, then Ansible is actually coming into the picture, but should need some knowledge on Ansible script to understand or execute the same.

5.When Should I Use {{ }}? Also, How To Interpolate Variables Or Dynamic Variable Names?

Answer:
One of the standard rules is ‘always use {{}} except when:’. Conditionals are always run through Jinja2 as to resolve the expression. So when:failed_when: and changed_when: are always templated and we should avoid adding {{}}.
In other cases except when clause we have to use brackets, otherwise distinguish between an undefined variable and String will be very difficult.

6.How Do I Generate Crypted Passwords For The User Module?

Answer:
A normal mkpasswd utility which is available in normal Linux system is a great option for generating crypted passwords.
mkpasswd –method=sha-512
Is somehow this utility not available in our system, suppose we are using OS X, then also we can easily generate this password by using Python. But for the same, need to install Passlib password hashing library in our system.
Once it installed, execute command will generate SHA512 password values.
python -c “from passlib.hash import sha512_crypt; import getpass; print sha512_crypt.encrypt(getpass.getpass())”

7.What Is The Best Way To Make Content Reusable/ redistributable?

Answer:
There have 3 ways to reuse files in playbooks of Ansible. 3 ways include, imports and roles.
Include and Imports are actually helping to create multiple small files of a large playbook or break up a large playbook of multiple small files. Those small files can be used across multiple parent playbooks or even for multiple times within the same playbook.
Roles are mainly used to manage multiple tasks in a package together. It can include variables, handlers, or even modules and other plugins. Roles also can be uploaded and shared by Ansible Galaxy.

8.How Do I Copy Files Recursively Onto A Target Host?

Answer:
Copy module of Ansible has a recursive parameter. But most efficient to use synchronize module which wrps rsync. For synchronize module we can use below command:
-name: Copy over h5bp configuration
synchronize: mode=pull src=/tmp/server-configs-nginx/{{ item }} dest=/etc/nginx/{{ item }}
with_items:
– “mime.types”
– “h5bp/”
To copy remote to remote use the same command, as delegate_to (as remote source) and current inventory_host (as remote dest).

9.Ansible Playbooks vs Roles and Ansible VS Puppet

Answer:
Ansible Playbook is a really simple configuration management and multi-machine deployment system. If we compare with another, it is very popular and well suited for deploying a complex application.
And Roles in Ansible are automatically loading certain var_files, task, and handlers based on a known file structure. Roles mainly grouping all the contents and packaged together. It also allows easy sharing of roles with other users.

AnsiblePuppet
Excellent Performance, Agent less install and deploy.Performance is little questionable compare to Ansible and it’s an agent based install.
Based on Python languageBased on Ruby language
CLI accepts commands in almost all language.All customer must learn the Puppet DSL.
As it is very and not tested well, it can’t give a proper and mature solution for every situation always.It always provides mature solution compare to Ansible.
GUI is in work in progress.Good GUI
No support for WindowsSupport for all major OS’s

10.Difference between a variable name and Environment Variables?

Answer:

Variable NameEnvironment Variable
Variable name can be built by adding String.To access the environment variable need to access existing variable.
{{ hostvars[inventory_hostname][‘ansible_’ + which_interface][‘ipv4’][‘address’] }}# … vars: local_home: “{{ lookup(‘env’,’HOME’) }}”
We can add StringsIf we want to add the variable we need to open advance playbooks section.
For variable name, we use IPV4 address.For Remote environment variables, use {{ ansible_env.SOME_VARIABLE }}

Recommended Article

This has been a guide to List Of Ansible Interview Questions and answers so that the candidate can crackdown these Ansible Interview Questions easily. This is the most valuable and useful post on Ansible Interview Questions and answers You may also look at the following articles to learn more –

Amazing Database Testing Interview Questions And Answer

Know The Top 5 Useful SSIS Interview Questions And Answer

Most Important Cognos Interview Questions And Answer

Top 5 Most Useful SSAS Interview Questions And Answer

references : 

https://www.educba.com/ansible-interview-questions/