[ 35+ ] Most Popularly Ask Ansible Interview Questions & Answers

[ 35+ ] Most Popularly Ask Ansible Interview Questions & Answers

Last updated on 15th Jun 2020, Blog, Interview Questions

About author

Kernel (Team Lead DevOps Engineer )

Highly Expertise in Respective Industry Domain with 10+ Years of Experience Also, He is a Technical Blog Writer for Past 4 Years to Renders A Kind Of Informative Knowledge for JOB Seeker

(5.0) | 16212 Ratings 2396

Ansible is an open-source software provisioning, configuration management, and application-deployment tool. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. It includes its own declarative language to describe system configuration.The automation services catalog is part of the Red Hat Ansible Automation Platform, giving developers and business users access to the four areas where their automation lives – across physical, virtual, cloud and container environments. 

1. What do you know about Ansible?

Ans:

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.

2. Explain the use of Ansible?

Ans:

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.

3. How to keep secrete data in a playbook?

Ans:

The following command is used to keep verbose output but hide the sensitive information from others who would like to be able to see the output.

  • name: secrete task  

  • shell: /user/bin/do_somthing -value={{secrete value}}  

  • no_log: True   
    • Also, the no_log attribute can apply to an entire play.
  • hosts: all  

  • no_log: True 

4. Explain the Ansible Galaxy.

Ans:

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.

5. What is continuous delivery in terms of Ansible?

Ans:

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.

6. How does Ansible work?

Ans:

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.

7.Name different modules in Ansible.

Ans:

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.

8. Explain the Ansible tower.

Ans:

The Ansible is the web-based center which is used for all kinds 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.

9. What is the difference between Ansible and Puppet?

Ans:

  • Ansible: The Ansible has the simplest technology written in the YAML language. It can be quickly installed and deployed because of agentless 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.

10. Give a brief about Ansible architecture.

Ans:

The Ansible is highly based on the agentless 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.

11. What’s the difference between the environment variable and variable name?

Ans:

The variable name can be created by adding stings. On the other hand, for the access of environment variables, 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.

12. What are the things Ansible can do?

Ans:

With the Ansible these are the following things one can do:

  • Deployment of application
  • Configuration management
  • Task automation
  • IT orchestration

13. What language Ansible is written in?

Ans:

The Ansible is written in PowerShell and Python programming language.

14. Can you please explain the meaning of the red hat Ansible?

Ans:

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

15. What are the requirements of the Ansible server?

Ans:

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

16. Is it possible to create my own modules with Ansible?

Ans:

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.

17. What’s the best way to generate crypto passwords for the user module?

Ans:

The availability of mkpasswd 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.

18. Name the different components of Ansible.

Ans:

Ansible automation is consist of the following elements:

  • Inventories
  • Modules
  • APIs
  • Host
  • Playbooks
  • Cloud
  • Networking

19. How can we make content redistributable and reusable?

Ans:

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

20. Explain the way to access shell environment variables in Ansible.

Ans:

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 :

    Subscribe For Free Demo

    21. Is it possible to keep secret data in the playbook?

    Ans:

    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.

    22. Explain ad-hoc commands.

    Ans:

    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.

    23. Explain the term “fact” in Ansible.

    Ans:

    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.

    24. What is the right way to copy files recursively onto a target host?

    Ans:

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

    25. Explain the meaning of Ansible tasks.

    Ans:

    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.

    26. Explain the Ansible role and what makes it different from the playbooks?

    Ans:

    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.

    27. Why are Ansible vaults used?

    Ans:

    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.

    28. Explain the features of the Ansible tower.

    Ans:

    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.

    29. How can you connect other devices within Ansible?

    Ans:

    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

    30. Does Ansible support AWS?

    Ans:

    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)

    Course Curriculum

    Learn Ansible Certification Course & Get Hired by TOP MNCs

    Weekday / Weekend BatchesSee Batch Details

    31. Which one is not a valid value of the state argument of the “file” module?

    1. file
    2. absent
    3. folder
    4. link

    Ans:

    1.Folder

    32. Which module can be utilized to copy files from a remote machine to a control machine?

    1. ping
    2. fetch
    3. copy
    4. move

    Ans:

    2. fetch

     33. If you do not need any facts from the host, what command would you use?

    1. gather_facts: no
    2. gather_facts: False
    3. both gather_facts: no or gather_facts: False
    4. gather_facts: y

    Ans:

    1. gather_facts: no

     34. Where is Inventory file located by default?

    1. /etc/ansible/hosts
    2. /etc/inventory
    3. /etc/configurations
    4. /etc/ansible

    Ans:

    1. /etc/ansible/hosts

    35. What is the default location for Ansible?

    Ans:

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

     36. What module can be utilized to stop a playbook execution for a specific period?

    1. Sleep
    2. Pause
    3. Stop
    4. Suspend

    Ans:

    2.Pause

     37. Which module will you utilize to create a directory?

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

    Ans:

    1.File

     38. Which module can be used to force a handler to run in between two tasks?

    1. Flush
    2. None of the options
    3. assets
    4. meta

    Ans:

    4.meta

    39. Which Ansible module is utilized for managing docker services and containers?

    1. docker_service
    2. docker_login
    3. docker_image
    4. docker

    Ans:

    1.docker_service

    40. Ansible has two types of servers. Select the appropriate answer from the given options.

    1. only node
    2. controlling machines and nodes

    Ans:

    2.controlling machines and nodes

    41. How to define the number of parallel processes while communicating to remote hosts?

    1. pipelining
    2. Forks
    3. become_method
    4. become

    Ans:

    2.Forks

     42. What is the default forks value in configuration files?

    1. 1
    2. 5
    3. 7
    4. depends upon hosts in the inventory

    Ans:

    2. 5

     43. How can you reduce the number of SSH connections required?

    1. accelerate port
    2. pipelining
    3. forks
    4. become_method

    Ans:

    2. pipelining

     44. Which configuration management is agentless

    1. Ansible
    2. Puppet
    3. chef
    4. CFEngine

    Ans:

    1.Ansible

     45. Ansible is generally referred to as what?

    • Infrastructure as code
    • Orchestration Engine
    • Configuration management
    • All the options

    Ans:

    All the options

     46. How would you write comments on Jinja2:

    1. {{}}
    2. {##}
    3. {%%}

    Ans:

    2.{##}

     47. What is the web-based interface used to access projects, inventories, job templates and jobs Ansible?

    Ans:

    Ansible Tower Interface

    48. What is the ask_pass module in Ansible?

    Ans:

    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 really don’t have to change this setting at all.

    49. How to set SSH-based access from Controller to Managed Nodes which is recommended by Ansible?

    Ans:

    • It provides passwordless auth to access the managed servers
    • In the 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

    50. Perform the following steps on all Managed nodes.

    Ans:

    Step 1: 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 admin for .ssh chown admin: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/admin/.ssh/id_rsa.pub] Now you are able to access the server without a password.

    Course Curriculum

    Get Ansible Training By Industry Experts to UPGRADE Your Skills

    • Instructor-led Sessions
    • Real-life Case Studies
    • Assignments
    Explore Curriculum

    51. What is inventory in Ansible and how to update it?

    Ans:

    • The inventory files contain a host list of managed nodes, when ansible accessing the client it looks into inventory.
    • The default inventory file for Ansible is located under /etc/ansible/hosts
    • This default inventory lookup can be overridden using -i option providing the custom inventory file

     Example: ansible -i cmdb.inv main.yml Update default Inventory File/etc/ansible/hosts (as root user) [clients]

    • node1
    • node2

    52. How to run ansible commands? Briefly explain?

    Ans:

    Running ansible command #ansible all -m ping

    • ansible => Ansible command
    • all       => Specifies the target to run the command.The target could be an individual node or group(mentioned inventory file)orall(all the nodes in the inventory 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)

    53. Explain the below output?

    Ans:

    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 is the reason the changed status is “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

    54. What is ansible-playbook?

    Ans:

    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.

    55. How to write a playbook, give examples?

    Ans:

    Below is the sample playbook:

    name: Install Docker and  restart service hosts: web app

    become: true tasks:

    name: Install Docker yum:

    name: docker state: latest

    name: Restart Docker  Service service:

    name: docker state: restarted

    56. Which command is used to run an ansible playbook?

    Ans:

    command to run a playbook

    •  $ ansible-playbook -i hosts main4.yml   

    •  -i- This is an option to specify an ability to override the default inventory file and the inventory file specified.
    •  main.yml: This is the playbook file

    57. What is the use of list-task in ansible?

    Ans:

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

    58. What is the use of –start-at-task in ansible?

    Ans:

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

    59. What are ansible variables?

    Ans:

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

    60. 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 machines through inventory.
    2.  You can use ansible-vault to store sensitive information.
    3. True
    4. False

    Ans:

    3.True

    61. Why are handlers used in the playbook?

    Ans:

    • 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 the “notify” tag. Name given in notify should  exactly match  as in the -name tag inside handlers

    62. How to define handlers in ansible playbooks?

    Ans:

    handlers:

    • name: Restart Docker Service

    service:

    • name: docker
    • state: restarted

    63. What are possible roles?

    Ans:

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

    64. How to create Ansible roles?

    Ans:

    By using the following command  we can create ansible roles

    • Ansible-galaxy init <rolename>

    65. What are the key things required for the playbook?

    Ans:

    Playbook may contains

    • Hosts
    • Variables (Optional)
    • Tasks

    66. What are the advantages of Ansible?

    Ans:

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

    67. Explain about handlers in Ansible?

    Ans:

    If we want to execute tasks whenever something changes 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.

    68. What is inventory in ansible?

    Ans:

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

    69. Explain about ansible modules?

    Ans:

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

    70. How will I start the services using ansible?

    Ans:

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

    Docker Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

    71. What is configuration management?

    Ans:

    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.

    72. How to execute the created roles?

    Ans:

    • hosts: true
    • role:
    • – apache<rolename>

    73. How to use existing tasks in Ansible?

    Ans:

    by using  import_tasks:

    74. How to use ansible-galaxy to download roles?

    Ans:

    ansible-galaxy install username.rolename

    75. What are possible jinja2 templates?

    Ans:

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

    76. How to do role duplication and execution?

    Ans:

    using allow_duplicates: true

    77. What are the role dependencies?

    Ans:

    Role default variables allow you to set the default variables for included or dependencies

    Dependencies:

    • Role: tire
    • Role: brake

    78. How to secure Ansible playbooks?

    Ans:

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

    79. How to encrypt and decrypt Ansible playbooks?

    Ans:

    Using ansible-vault encrypt and ansible-vault decrypt

    80. How to change the existing password for a sensible vault?

    Ans:

    ansible-vault rekey

    81. How to install Ansible on Linux?

    Ans:

    First we need to install epel repo and then install ansible

    • Yum install epel-repo
    • Yum install ansible

    82. Which module copies a dynamically generated file from control machine to target

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

    Ans:

    1.Template

    83. How do you define ansible in the configuration management perspective?

    Ans:

    Anything can be deployed/configured/installed by using ansible in the list of servers without even touching the server which actually doesn’t need any clients to be configured in all the server since it operates in ssh mode. That’s why it is called agentless, low overhead configuration management service

    84. Do you know how to illustrate the working of Ansible ?

    Ans:

    Yes, Ansible should be set up 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 containing the 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 executed using python interpreter since all the definitions are converted into python.

    85. How do you define ansible as useful in the automation paradigm?

    Ans:

    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.

    86. Is it possible to build our modules in Ansible?

    Ans:

    Yes, we can create our own modules within Ansible. It’s an open-source tool which basically works on python. You can start creating your own modules. The only requirements would be to be amazingly good at programming.

    87. Will you be able to restart the target machines with Ansible?

    Ans:

    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

    88. Do you know what are all the features of Ansible beyond automation?

    Ans:

    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

    89. How ansible is executed just by YAML script?

    Ans:

    Actually Ansible is not written in YAML, it is written in python programming and Powershell. So, YAML is getting converted to it that’s how it works

    90. Do you know ansible cannot be considered as open source?

    Ans:

    That is completely wrong, Ansible is open source whereas Red Hat Ansible is customized by Redht

    91. Server requirement for Ansible how will it look like ?

    Ans:

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

    92. So do you have an option to customize your own ansible modules?

    Ans:

    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 own module for Ansible. You don’t need any extraordinary prior experience to build your own module

    93. Do you know the other way around to perform ansible operations without writing playbooks ?

    Ans:

    We have an option to write our single task and execute it without even writing a 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.

    94. Do you know how we parameterize the arguments required for the module ?

    Ans:

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

    Example: vars:

    • myvar1: value
    • myvar2: value

    95. Will you be able to see the host machine all variables using ansible?

    Ans:

    Yes we have a module called debug module. Either you can write playbook or ad hoc commands, both the way it can be achieved.  Pass the arguments as ‘var=hostvars[inventory_hostname] localhost’ this gets the variables of machines

    96. Could you differentiate Roles and Playbooks?

    Ans:

    Roles are written as a collection which contains tasks, vars, default vars, metadata information, handlers, files all separated in different folders whereas in a 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

    97. Differentiate ask_pass and ask_sudo_pass

    Ans:

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

    98. Do you know how we make use of our ansible script reusable or redistributable ?

    Ans:

    Yes, roles are the only way we can use this. Roles ensure that they can be distributed or redistributed with the updated content . This contains a document which says how to use the roles.

    99. Do we have the option to copy a file from my ansible server to all servers ?

    Ans:

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

    100. How can you encrypt ansible passwords or any data ?

    Ans:

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

    Are you looking training with Right Jobs?

    Contact Us
    Get Training Quote for Free