Ansible Interview Questions 5

Q53) Explain the below output?


Expected Outcome of the first command for 4 QUE

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

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

Lets understand on how to interpret the output


node1 This idetntified the node on which thet ask is done

SUCCESS -Give a confirmation that the module was run successfully

þÿ c h a n g e d : falseþÿ p i n g m o d u l e d o e s n t d o a n y m o d i f i c a t i o n o n t h e r e m þÿ t h e p i n g o r n o d e O N s t a t u s . T h i s t h e r e a s o n t h e c h a n g e d s t a t u s f a l s e

þÿ p i n g : p o n g þÿ – T h i s a w a y p i n g m o d u l e c o n f i r m s t h e p i n g r e p l y a s p

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.

Ansible Interview Questions 1

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?

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.

Ansible Interview Questions 4

þÿ Q 5 8 ) w h a t i s t h e u s e o f s t a r t – a t – t a s k i n a n s i b l e ?

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?


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?


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

W i t h i n t a s k s , h a n d l e r s w i l l b e c a l l e d u s i n g n o t i f y t a g . N a m e g i v e n i n as in the -name tag inside handlers

Q62) How to define handler in ansible playbook?


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?

Ansible Interview Questions and Answers 1

Answer: Playbook may contains


Variables (Optional)


Q66) What are the advantages of Ansible?

þÿ A n s w e r : A n s i b l e i s a g e n t l e s s w h i c h m e a n s i t d o e s n t r e q u i r e a n y n o d e m

uses YAML to create playbooks which is easy to understand.

Q67) Explain about handlers in Ansible?

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

we need to us e notify in the play book . For example if we want to rest a 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 I P s .

Q69) Explain about ansible modules?

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

How to check database backups via sqlplus

Q70) How will start the services using ansible?

Answer : a n s i b l e – m s e r v i c e – a n a m e = h t t p d s t a t e = s t o p p e d b e c o m e