Ansible Interview Questions for Freshers/Ansible Interview Questions and Answers for Freshers & Experienced

How do I access a variable name programmatically?

Variable names can be built by adding strings together. For example, if we need to get ipv4 address of an arbitrary interface, where the interface to be used may be supplied via a role parameter or other input, we can do it in this way.

{{ hostvars[inventory_hostname]['ansible_' + which_interface]['ipv4']['address'] }}

Explain the concept behind Infrastructure as Code (IaC).

Infrastructure as Code (IaC) is a process for managing and operating data servers, storage systems, system configurations, and network infrastructure.

In traditional configuration management practices, each minute configuration change required manual action by system administrators and the IT support team. But with IaC, all the configuration details are managed and stored in a standardized file system, wherein the system automatically manages infrastructure changes and deals with system configurations.

Therefore, we do not require most of the manual effort since everything is managed and automated by following the IaC approach. Tools such as Ansible can be used to implement IaC approach.

Explain a few of the basic terminologies or concepts in Ansible.

Few of the basic terms that are commonly used while operating on Ansible are:

Controller Machine: The Controller machine is responsible for provisioning the servers that are being managed. It is the machine where Ansible is installed.

Inventory: An inventory is an initialization file that has details about the different servers you are managing.

Playbook: It is a code file written in the YAML format. A playbook basically contains the tasks that need to be executed or automated.

Task: Each task represents a single procedure that needs to be executed, e.g. Install a library.

Module: A module is a set of tasks that can be executed. Ansible has 100s of built-in modules, but you can also create custom ones.

Role: An Ansible role is a pre-defined way for organizing playbooks and other files in order to facilitate sharing and reusing portions of provisioning.

Play: A task executed from start to finish or the execution of a playbook is called a play.

Facts: Facts are global variables that store details about the system, like network interfaces or operating system.

Handlers: Are used to trigger the status of a service, such as restarting or stopping a service.

Discuss method to Create an Empty File with Ansible

To create and empty file you need to follow given steps.

Step 1. Save An Empty File into The Files Directory

Step 2. Copy It to The Remote Host.

When should you test playbooks and roles?

In ansible, Tests can be added either in new Playbooks or to existing Playbooks. Therefore, most of the testing job offers a clean hosting each time. By using this testing methodology, you need to make very little to no code changes.

Explain modules in ansible

Modules in Ansible are idempotent. From a RESTful service standpoint, for the operation to be idempotent, clients can perform the same result by using modules in Ansible. Multiple identical requests become a single request.

There are two different types of modules in Ansible:

<> Core modules
<> Extras modules


Core Modules

The Ansible team maintains these types of modules, and they will always ship with Ansible software. They will also give higher priority for all requests than those in the “extras” repos.

Extras Modules:

These modules currently is bundled with Ansible but might available separately in the future. They are also mostly maintained by the Ansible community. These modules are still usable, but it can receive a lower rate of response to issues and pull requests.

How do you see all variables for a host?

You can see them using the hostvars variable. This stores host variables with the hostname as key. For example, to look at the variables defined for localhost, you can run;

ansible -m debug -a "var=hostvars[inventory_hostname]"

What Is the Best Method to Make Content Reusable/redistributable?

You can read everything about “Roles” in the playbooks documentation section. This helps to make playbook content self-contained and shareable with other ansible users.

How Can you submit a change to the Documentation in Ansible?

Documentation for Ansible is kept in the project git repository. It contains complete instructions for contributing can be found in the docs.

Explain how you can copy file recursively onto a target host?

The “copy” module has a recursive parameter. However, if you want this to perform more efficient for a large number of files, then “synchronize” module is the best option for you.

How do you keep data secret in a playbook?

If you want to keep secret data but still be able to share it publicly, then use Vault in playbooks. But if you’re using –v (verbose) mode and don’t want anyone to see the results, then use:

name: secret task

shell: /usr/bin/do_something --value={{ secret_value }}

no_log: True

When do you use {{ }}?

One of Ansible’s most basic rules is: “Always use {{ }} except when:”

Speaking of tags, how do you filter out tasks?

You can filter out tasks in one of two ways:

* Use –tags or –skip-tags options on the command line

* If you’re in Ansible configuration settings, use the TAGS_RUN and TAGS_SKIP options.

What exactly is a configuration management tool?

Configuration management tools help in keeping a system running within the desired parameters. They help in reducing the deployment time and substantially reduce the effort required to perform repetitive tasks. Popular configuration management tools on the market today include Chef, Puppet, Salt, and of course, Ansible.

Finally, let us go through the Ansible interview questions at an advanced level.

Explain the difference between a playbook and a play.

A play is basically a set of tasks that can run on multiple managed hosts. Plays are made of one or more tasks. On the other hand, the playbook consists of one or more plays.

What’s an ad hoc command?

Ad hoc commands are used to initiate actions on a host without using a playbook. It is basically a one-shot command.

Explain what an ask_pass module is.

Ask_pass module is a playbook control module that is used to control a password prompt. It is always set to True by default.

Explain how to access shell environment variables.

You can access the controlling machine’s existing variables by using the “env” lookup plugin. For instance, to access the value of the management machine’s home environment variable, you’d enter:

local_home:”{{lookup(‘env’,’HOME’)}}”

When do you use {{ }}?

One of Ansible’s most basic rules is: “Always use {{ }} except when:”

How do you upgrade Ansible?

Upgrading Ansible is easy. Just use this command: sudo pip install ansible==<version-number>

How do you test Ansible projects?

This is another frequently asked ansible interview question. Try elaborating the answer to this question rather than just answering the testing methods in one word. There are three testing methods available:

* Asserts

Asserts duplicates how the test runs in other languages like Python. It verifies that your system has reached the actual intended state, not just as a simulation that you’d find in check mode. Asserts shows that the task did the job it was supposed to do and changed the appropriate resources.

* Check Mode

Check mode shows you how everything would run if no simulation was done. Therefore, you can easily see if the project behaves the way you want it to. On the downside, check mode doesn’t run scripts and commands used in roles and playbooks. To get around this, you have to disable check mode for specific tasks by running “check_mode: no.”

* Manual Run

Just run the play and verify that the system is in its desired state. This testing choice is the easiest method, but it carries an increased risk because the results in a test environment may not be the same in a production environment.

What are Ansible tasks?

The task is a unit action of Ansible. It helps by breaking a configuration policy into smaller files or blocks of code. These blocks can be used in automating a process. For example, to install a package or update a software

Install <package_name>, update <software_name>

Explain how you can disable cowsay?

If cowsay is installed then executing playbooks inside the Ansible you can disable coway by using following options:

1. Uninstall cowsay
2. Setting up value for the environment variable

export ANSIBLE_NOCOWS=1

What’s a handler?

In Ansible, a handler is similar to a regular task in a playbook, but it will only run if a task alerts the handler. Handlers are automatically loaded by roles/<role_name>/handlers/main.yaml. Handlers will run once, after all of the tasks are completed in a particular play.

Speaking of tags, how do you filter out tasks?

You can filter out tasks in one of two ways:

* Use –tags or –skip-tags options on the command line

* If you’re in Ansible configuration settings, use the TAGS_RUN and TAGS_SKIP options.

Explain Ansible modules in detail?

Ansible modules are like functions or standalone scripts which run specific tasks idempotently. The return value of these are JSON string in stdout and input depends on the type of module. These are used by Ansible playbooks.
There are 2 types of modules in Ansible:

* Core Modules

The core Ansible team is responsible for maintaining these modules thus these come with Ansible itself. The issues reported are fixed on priority than those in the “extras” repo.

* Extras Modules

The Ansible community maintains these modules so, for now, these are being shipped with Ansible but they might get discontinued in the future. These can be used but if there are any feature requests or issues they will be updated on low priority.

Now popular extra modules might enter into the core modules anytime. You may find these separate repos for these modules as ansible-modules-core and ansible-modules-extra respectively.

Explain Infrastructure as Code?

Infrastructure as Code or IaC is a process that DevOps teams should follow to have a more organized way of managing the infra. Instead of some throwaway scripts or manually configuring any cloud component, there should be a code repo where all of these will lie and any change in configuration should be done through it. It is wise to put it under source control also. This improves speed, consistency, and accountability.

What are tags?

When there’s an extensive playbook involved, sometimes it’s more expedient to run just a part of it as opposed to the entire thing. That’s what tags are for.

What is the code you need to write for accessing a variable name?

Variable names can be built by adding using the following method:

{{ hostvars[inventory_hostname]['ansible_' + which_interface]['ipv4']['address'] }}

What is the way to access shell environment variables in Ansible?

In Ansible, if you want to access existing variables, the user needs to use the ‘env’ lookup plugin. Example, to access the value of the Office environment on the management machine:

You need to write following code:

(
---
# ...
vars:
local_home: "{{ lookup('env','Office') }}"
I
{{ ansible_env.SOME_VARIABLE }}

)

What exactly is a configuration management tool?

Configuration management tools help keep a system running within the desired parameters. They help reduce deployment time and substantially reduce the effort required to perform repetitive tasks. Popular configuration management tools on the market today include Chef, Puppet, Salt, and of course, Ansible.

Explain the difference between a playbook and a play.

A play is a set of tasks that run on one or more managed hosts. Plays consist of one or more tasks. A playbook consists of one or more plays.

What’s an ad hoc command?

Users initiate ad hoc commands to initiate actions on a host without using a playbook. Consider it a one-shot command.

Explain what an ask_pass module is.

It’s a playbook control module used to control a password prompt. It’s set to True by default.

What are “facts” in the context of Ansible?

Facts are newly discovered and known system variables, found in the playbooks, used mostly for implementing conditionals executions. Additionally, they gather ad-hoc system information.

You can get all the facts by using this command:

$ ansible all- m setup

How do you use Ansible to create encrypted files?

To create an encrypted file, use the ‘ansible-vault create’ command.

$ ansible-vault create filename.yaml

You will get a prompt to create a password, and then to type it again for confirmation. You will now have access to a new file, where you can add and edit data.

What are CD and CI, and what is Ansible’s relationship with them?

CD stands for continuous delivery, and CI stands for continuous integration. Both of them are very known for software development practices.

In CD, developers take care of the release of their software products in the condition of releasing it for production at any given time. CI is responsible for each developer uploading regularly scheduled integrations (usually daily), resulting in multiple integrations every day. Ansible is an ideal tool for CI/CD processes, providing a stable infrastructure for provisioning the target environment and then deploying the application to it.

How is Ansible useful for Continuous Delivery?

Ansible provides multi-tier, multi-step orchestration allowing for a granular control over operations and enabling orchestration of server configuration in batches. Splitting 1000s of servers into manageable groups and updating them a few 100 at a time is easily achieved in Ansible.

What are the different uses or different capabilities of Ansible?

Ansible can be used for provisioning cloud infrastructure, configuration management over existing infrastructure, record configuration into repeatable and editable scripts called Ansible Playbooks.

What is Ansible Galaxy?

This is a tool bundled with Ansible to create a base directory structure. Galaxy is a website that lets users find and share Ansible content. You can use this command to download roles from the website:

$ ansible-galaxy install username.role_name

What is “idempotency”?

idempotency is an important Ansible feature. It prevents unnecessary changes in the managed hosts. With idempotency, you can execute one or more tasks on a server as many times as you need to, but it won’t change anything that’s already been modified and is working correctly. To put it in basic terms, the only changes added are the ones needed and not already in place.

What is Ansible Tower?

It’s an enterprise-level web-based solution that increases Ansible’s accessibility to other IT teams by including an easy-to-use UI (user interface). Tower’s primary function is to serve as the hub for all of an organization’s automation tasks, allowing users to monitor configurations and conduct rapid deployments.

How do you set up Ansible?

You can use either the Python installer or a Linux-based installation process, such as apt or yum.

What a “playbook” is.

A playbook has a series of YAML-based files that send commands to remote computers via scripts. Developers can configure entire complex environments by passing a script to the required systems rather than using individual commands to configure computers from the command line remotely. Playbooks are one of Ansible’s strongest selling points and often referred to as the tool’s building blocks.

State the requirements for the Ansible server.

You need a virtual machine with Linux installed on it, running with Python version 2.6 or higher.

Describe how Ansible works.

This is one of the most frequently asked ansible interview questions where the interviewer wants to know whether you actually know the tool in and out or not. You can start this way - ansible is broken down into two types of servers: controlling machines and nodes. Ansible is installed on the controlling computer, and the controlling machines manage the nodes via SSH.

The controlling machine contains an inventory file that holds the node system’s location. Ansible runs the playbook on the controlling machine to deploy the modules on the node systems. Since Ansible is agentless, there’s no need for a third-party tool to connect the nodes.

What is Ansible and what makes it stand out from the rest of the Configuration Management tools?

Ansible is an open source IT Configuration Management, Deployment & Orchestration tool. It aims to provide large productivity gains to a wide variety of automation challenges.

Here’s a list of features that makes Ansible such an effective Configuration Management and Automation tool:

1. Simple: Uses a simple syntax written in YAML called playbooks.
2. Agentless: No agents/software or additional firewall ports that you need to install on the client systems or hosts which you want to automate.
3. Powerful and Flexible: Ansible’s capabilities allow you to orchestrate the entire application environment regardless of where it is deployed.
4. Efficient: Ansible introduces modules as basic building blocks for your software. So, you can even customize it as per your needs.

What are CD and CI, and what is Ansible’s relationship with them?

CD stands for continuous delivery, and CI stands for continuous integration; both are software development practices.

In CD, developers build software that can be released into production at any given time. CI, on the other hand, consists of each developer uploading regularly scheduled integrations (usually daily), resulting in multiple integrations every day. Ansible is an ideal tool for CI/CD processes, providing a stable infrastructure for provisioning the target environment and then deploying the application to it.

List Ansible’s advantages

Ansible has many strengths, including:

* It’s agentless and only requires SSH service running on the target machines
* Python is the only required dependency and, fortunately, most systems come with the language pre-installed
* It requires minimal resources, so there’s low overhead
* It’s easy to learn and understand since Ansible tasks are written in YAML.
* Unlike other tools, most of which are Procedural, ansible is declarative; define the desired state, and Ansible fulfills the requirements needed to achieve it

What is Ansible?

It is an open-source platform that facilitates configuration management, task automation, or application deployment. It is a valuable DevOps tool. It was written in Python and powered by Red Hat. It uses SSH to deploy SSH without incurring any downtime.

Search
R4R Team
R4R provides Ansible Freshers questions and answers (Ansible Interview Questions and Answers) .The questions on R4R.in website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,Ansible Interview Questions for Freshers,Ansible Freshers & Experienced Interview Questions and Answers,Ansible Objetive choice questions and answers,Ansible Multiple choice questions and answers,Ansible objective, Ansible questions , Ansible answers,Ansible MCQs questions and answers Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for Ansible fresher interview questions ,Ansible Experienced interview questions,Ansible fresher interview questions and answers ,Ansible Experienced interview questions and answers,tricky Ansible queries for interview pdf,complex Ansible for practice with answers,Ansible for practice with answers You can search job and get offer latters by studing r4r.in .learn in easy ways .