Ansible

Ansible Interview Questions and Answers 2

Q51) What is inventory in Ansible and how to update it?

Answer:

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

Q52) How to run ansible command? Briefly explain?

Answer:

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)

READ ALSO
Lab. Getting Started with Amazon Web Services (AWS)

Q53) Explain the below output?

Answer:

Expected Outcome of the first command for 4 QUE

node1 | SUCCESS => { “changed”: false, “ping”:”pong” } node2 |

SUCCESS =>{ “changed”: false, “ping”:”pong” }

Explanation:

node1

SUCCESS -Give a confirmation that the module was run successfully

false

 

Note: The output varies from module to module depending on how the module is

Q54) What is ansible-playbook?

Answer: 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.

Q55) How to write playbook, give example?

Answer: 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

Q56) which command is used to run an ansible playbook?

READ ALSO
How to check database PITR after refresh

Answer: 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

Q57) What is the use of list-task in ansible?

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

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

Q59) What is ansible variables?

Answer:

Variables are used to store values that can be later used in the playbook.

Vars: is the tag to define a variable.

Q60) How are nodes,managed by a controlling machine over?

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

Answer: True

Q61) Why handlers are used in the playbook?

READ ALSO
Ansible Interview Questions 2

Answer:

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

as in the -name tag inside handlers

Q62) How to define handler in ansible playbook?

Answer:

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

state: restarted

Q63) What is ansible roles?

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

Q64) How to create Ansible roles?

Answer: By using the following command we can create ansible roles

Ansible-galaxy init <rolename>

Q65) What are the key things required for the playbook?

Answer: Playbook may contains

Hosts

Variables (Optional)

Tasks

Q66) What are the advantages of Ansible?

uses YAML to create playbooks which is easy to understand.

READ ALSO
Ansible Interview Questions and Answers 1

Q67) Explain about handlers in Ansible?

Answer: If we want to execute tasks whenever something changed in the configuration files then

configuration file changes.

Q68) What is inventory in ansible?

Answer: /etc/ansible/hosts file called as inventory. It contains the group of the server name or

Q69) Explain about ansible modules?

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

Q70) How will start the services using ansible?

Q71) What is configuration management?

Answer: 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.

Q72) How to execute the created roles?

hosts: true

role:

Q73) How to use existing tasks in Ansible?

Answer: by using import_tasks:

Q74) How to use ansible-galaxy to download roles?

Answer: ansible-galaxy install username.rolename

Q75) What is ansible jinja2 templates?

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

READ ALSO
Ansible Interview Questions 3

Q76) How to do role duplication and execution?

Answer: using allow_duplicates: true

Q77) What are the role dependencies?

Answer: Role default variables allow you to set the default variables for included or dependencie

Dependencies

Role: tire

Role: brake

Q78) How to secure Ansible playbooks?

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

Q79) How to encrypt and decrypt Ansible playbooks?

Answer: Using ansible-vault encrypt and ansible-vault decrypt

Q80) How to change the existing password for ansible vault?

Answer: ansible-vault rekey

Q81) How to install Ansible on Linux?

Answer: First we need to install epel repo and then install ansible

Yum install epel-repo

Yum install ansible

Q82) Which module copies a dynamically generated file from control machine to target

  1. template
  2. file
  3. fetch
  4. copy

Answer: Template

Q83) How do you define ansible in the configuration management perspective?

Answer: Anything can be deployed/configured/installed by using ansible in the list of servers

READ ALSO
Ansible Interview Questions 7

configuration management service

Q83) Do u know how to illustrate the working of Ansible ?

Answer: Yes, Ansible should be setup on a dedicated server which contains modules, inventories configured. Inventory contains the list of the target host which we want to connect/deploy/install/configure. That is simply a yaml file contained group name, server details. Modules are predefined in ansible which has the actual implementation definition on the ansible libraries. Host machines i.e target machines are connected via ssh and executes using python interpreter since all the definitions converted into python.

Q84) How do you define ansible is useful in the automation paradigm?

Answer: Automation is a sequence of operation which is done manually by the admin which is not possible over a thousands of server but that has to be managed from some place so ansible server is needed and all the server need not to be configured with some agent which takes operational headache all these can be overcome by the Ansible configuration management.

READ ALSO
Cloud offering 3 types of service models

Q84) Do you know any API reference for Ansible ?

Answer: Yes, Ansible works on Rest API call which can be achieved by using ansible tower. It gives an option to use RBAC which is secured to access the secured ssh credentials

Q85) Will you be able to restart the target machines with Ansible?

Answer: Yes, we can restart the machines since it is OS operations, we have reboot module that has to be added in the tasks of the playbook to restart the machine

Q86) Do you know what are all the features of Ansible beyond automation?

Answer: Yes, It is not only for task automation, we can also perform beyond that. Cloud infrastructure automation can be performed using that, you can deploy the application to servers by using ansible, you can perform configuration management which is the main feature, and you can orchestrate multiple IT environment

READ ALSO
Ansible Interview Questions 4

Q87) How ansible is executing just by YAML script?

Answer: Actually Ansible is not written in YAML, it has written in python programming and

Q88) Do you know ansible cannot be considered as opensource?

Answer: That is completely wrong, Ansible is opensource whereas Redhat Ansible is customized by Redht

Q89) Server requirement for Ansible how will it look like ?

Answer: Here Ansible server should have linux installed and python version should be 2.6 or higher.

Q90) So do you have an option do customize you own ansible modules?

Answer: Yes, Since it is an opensource tool, you have an option to customize it. But the clear

requirement is you should be a good programmer so that you can get started to develop your

module

Q91) Do you know the other way around to perform ansible operations without writing playbooks ?

Answer: We have an option to write our single task and execute it without even writing playbook that is called ad-hoc commands. Which is like normal Ansible CLI commands which passes required modules and arguments for the modules, and the targeted host groups in a single command.

READ ALSO
AWS Lambda using Python

Q92) Do you know how do we parameterize the arguments required for the module ?

Answer: This can be done in the playbook or roles when you write it, you have to use variables and its value under vars section in playbook. If it is roles, it has to be in the vars folder and main.yaml file.

Example:

vars:

myvar1: value

myvar2: value

Q93) Will you be able to see the host machine all variables using ansible?

Answer: Yes we have a module called debug module. Either you can write playbook or adhoc commands, both the way it can be achieved. Pass the arguments as

Q94) Could you differentiate Roles and Playbooks?

Answer: Roles are written as a collection which contains tasks, vars, default vars, metadata information, handlers, files all separated in different folder whereas in playbook which contains all in a single file. Roles can be shared with ansible galaxy so that others can easily pull it without any dependency

READ ALSO
Kubernetes interview questions 4

Q95) Differentiate ask_pass and ask_sudo_pass

Answer: Yes Ask_pass default value is actually no, if you want it to enable explicitly you can set it as True. This enables option to ask password whereas ask_sudo_pass will be prompted when sudo password is required to entered by the user.

Q96) Do you know how do we make use of our ansible script reusable or redistributable ?

Answer: Yes roles is the only way we can use this. Roles ensures that can be distributed or redistributed with the updated content . This contains document which says how to use the roles.

Q97) Do we hav option to copy a file from my ansible server to all server ?

Answer: Yes, we have option to copy files from ansible servers to all the servers. We have file module which does that. You can also copy files with changing or without changing permissions, owners, groups etc.

READ ALSO
Introduction to AWS CLI

Q98) How can u encrypt ansible passwords or any data ?

Answer: We have ansible vault which protects all the confidential information which is needs to be protected from the end user.

Q99) How will you ensure the targeted server connection is established ?

Answer: We can use ping module which tries to ping all the servers in the inventory files. This will

whether the servers are reachable with ansible server or not. The syntax of the commands is

Q100) What are playbooks in ansible ?

Answer: Playbooks are the scripts that we use in Ansible. They are used as building blocks that you can use to execute on remote machine. The scripts will contain the instructions that needs to be executed on the remote machines. This script follows a yaml format so you have to very careful with the indentation.

READ ALSO
Visual Basic Creating a simple Calculator to get familiar with the interface and code

Q101) What are ad-hoc commands ?

Answer: Ad-hoc commands in ansible is another way of executing commands on remote machines. They are your one time commands that will not be saved for future use. The other way that you can execute commands on remote machines is by writing a playbook.

Q102) What is an inventory file ?

Answer: Inventory file is the file that will be used by the playbooks to identify the IP addresses of the remote machines to execute the playbooks. This file is also known as the host file and will be

to provide the IP addresses in the inventory file.

Q103) What is ansible tower ?

Answer: Ansible tower is the UI version of Ansible. Ansible tower provides an web user interface that you can use to execute the playbooks. Ansible tower makes it easier to use ansible for all the IT needs.

READ ALSO
What is DevOps? Introduction to DevOps 1

Q104) What are roles in ansible ?

Answer: Roles are the advanced way to execute your playbooks on remote machines. Instead of writing one large playbook and making it very complicated, you can divide the playbook as per their section (Target, variables, tasks, handlers) by using roles and make the executing easier. By using roles, it becomes easier to manage very large playbooks. Roles will be present in

Q105) What is your understanding about Ansible ?

Answer: Ansible is a widely used IT configuration management tool . The best part of ansible is it is Open source so License is required and second one is it is Agent less , means we not need to Install any software on client machine to manage it .

Q106) What is Ansible Host and Node ?

Answer: Ansible has two part one is called Node machine and one is called Host Machine. The Node machine is here the ansible Server is installed and Host Machine is which is managed my Ansible Node.

READ ALSO
Counting Words in File(s) using Elastic MapReduce (AWS)

Q107) How Ansible Communicate with its host Machine?

Answer: Ansible communicates with all its host machine using SSK key. We need to create an SSH Key using ssh-keygen command on Ansible Node machine and copy to all host machines.

Q108) What is Ansible Tower?

Answer: Ansible tower is commercial products from Redhat . It is used to simplify the job of ansible automation. We can also has lot of options like monitoring

Q109) What is Configuration Management (CM) Practices?

Answer: Configuration Management is the practice of managi8ng the complete Infrastructure as a code ( IAC), it helps to automate the provisioning, deprovision, update, manage, deprovisioning of infrastructure which include OS, Application, update as an code.The organization is using Ansible , Terraform likes tool for their CM.

Q110) What are the basic terminologies used in Ansible.

Answer: The most basic terminology used in Ansible are

READ ALSO
Ansible Interview Questions 5

Controller Machine: It is the main controller machine, which manages all the host

Playbook: An YAML script, which contains the tasks

Task: Task is the single piece of work like install http

Inventory: The server can be gopura together know as inventory

Module: It is an executable set of tasks.

Role: An Ansible role is a pre-configured way forgetting organize the playbooks

Q111) Please define what is Ansible Galaxy?

Answer: Ansible Galaxy is the website , where we can share all the ansible roles

Q112) How can you install Ansible on Amazon EC2 instance?

Answer: Ansible can be installed on Amazon EC2 Instance using the Yum Install command.

Q113) How can you install Ansible on Amazon EC2 instance?

Answer: Ansible can be installed on Amazon EC2 Instance using sudo pip Install ansible command.

Q114) How can you take backup of configuration in Ansible?

Answer: Use copy module in Ansible we can backup the file to remote locations