Ansible Interview Questions

Ansible interview questions

When you want to crack an interview, preparation is the essential thing that you need to focus on and we do understand the necessity of it. Therefore, our experts and professionals come with the relevant Ansible interview questions and answers that will help you in cracking the interviews with ease so that you can get into a job smoothly. There will not much of hassles or issues in learning the questions and answers that we prepare as it is quite self-explanatory and easy to remember. So, what are you waiting for? Just start learning from today onwards.

About Ansible

Ansible is basically a cloud computing format service that is introduced by Microsoft to build, test, deploy, and manage all the tools and services through the data centers that are controlled by Microsoft. It offers SaaS (Software as a Service), PaaS (Platform as a Service), and IaaS (Infrastructure as a Service), and is known to support lots of various programming languages, applications, and frameworks that include both the Microsoft-based and third-party application centers or systems. It was launched in the year of October 2008 and since then it is known to dominate the market because of the types of services it offers.

Best Ansible Interview Questions of 2020

1. What Is Ansible?

Ansible is a configuration management system. It is used to set up and manage infrastructure and applications. It allows users to deploy and update applications using SSH, without needing to install an agent on a remote system.

2. What’s the use of Ansible?

Ansible is used for managing IT infrastructure and deploy software apps to remote nodes.

For example, Ansible allows you to deploy as an application to many nodes with one single command. However, for that, there is a need for some programming knowledge to understand the ansible scripts.

3. What is Ansible Galaxy?

Ansible can communicate with configured clients from the command line by using ansible command. It also allows you to automate configuration by using ansible-playbook command. To create the base directory structure, you can use a tool bundled with Ansible which is known as ansible-galaxy.

Command:

$ ansible-galaxy init azavea. packer

azavea.packer was created successfully

4. What is Continuous Delivery?

Continuous delivery is a practice of delivering the software as soon as it developed. In this method, we need to use versioning control system. The software is constantly updated in live production systems.

5. 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 }}

6. 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'] }}

The method of using hostvars is important because it’s a dictionary of the entire namespace of variables. ‘inventory_hostname’ variable specifies the current host you are looking over in the host loop.

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

8. 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.

9. 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.

10. 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.

11. What is Ansible Tower?

Ansible tower is a tool which makes Ansible very easy to use. It acts as a hub for the task automation. The tower is free for usage till 10 nodes.

12. What’s the method to check the inventory vars defined for the host?

For that use this command:

ansible -m debug -a "var=hostvars['hostname']" localhost

13. State the difference between Variable name and Environment Variables.

Variable Name Environment Variables
It can be built by adding strings. To access the environment variable, you need to access existing variables.
{{ hostvars[inventory_hostname][‘ansible_’ + which_interface][‘ipv4’][‘address’] }} # … vars: local_home: “{{ lookup(‘env’,’HOME’) }}”
Allows to add strings To set environment variables, we need to see the advanced playbooks section.
Ipv4 address type use for Variable names we use the ipv4 address. For Remote environment variables, use {{ ansible_env.SOME_VARIABLE }}

14. What are ad-hoc commands?

You can think of ad-hoc commands as a way for us to take actions on our hosts without writing a playbook. For example, if we want to reboot all hosts in a particular group(webservers). Then you can write a playbook or simply run a one-off ad-hoc command.

16. Explain Ansible facts

You can think of ansible facts as a way for ansible to get information about a host and store them in variables for easy access. This information stored in predefined variables are available to use in the playbook. To generate facts, ansible runs the setup module.

17. How do you see all variables for a host?

You can see them using the host vary 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_hostnam

18. 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.

19. Perform the following setps on all Managed nodes.

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 tadmin for .ssh chown tadmin: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/tadmin/.ssh/id_rsa.pub]

Now you able to access the server without password.

20. What is inventory in ansible and how to update it?

  • 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

21. How to run ansible command? Briefly explain?

Running ansible command #ansible all -m ping

  • ansible => Ansible command
  • all       => Specifies the target to run the command.Target could a individual nodeorgroup(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 aremote node. It has no attribute parameter (-a)

22. What is ansible playbook?

The playbook is a .yml file which contains a piece of code called as 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.

23. How to write playbook, give example?

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

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

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

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

The main difference between the two is that an instance of a web role runs IIS, while an instance of a worker role does not. Both are managed in the same way, however, and it’s common for an application to use both.For example, a web role instance might accept requests from users, then pass them to a worker role instance for processing.

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

The Windows Azure Fabric Controller is a resource provisioning and management layer that manages the hardware, and provides resource allocation, deployment/upgrade, and management for cloud services on the Windows Azure platform.

27. 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.

29. 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
  • Within tasks, handlers will be called using “notify” tag. Name given in notify should  exactly match  as in the -name tag inside handlers

29. What is ansible roles?

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

30. How to create Ansible roles?

  • By using following command  we can create ansible roles

    Ansible-galaxy init <rolename>

Career scopes and salary scale

As most of the institutions in the current day depend on the software that is managed by Microsoft, there are lots of companies who are hiring software developers who possess good skills and expertise in managing this product. Therefore, if you know that you have the right skills and expertise to work on this platform, then try to apply for jobs in your country as there are lots of scopes and opportunities available for you. For a fresher, he or she can grab this opportunity to earn about 86,900 dollars to 90,000 dollars per year, while an experienced worker can earn up to 214,500 dollars per year.

Conclusion

What you need to do is starting preparing using our Azure Interview questions and answers and we assure you that you will easily convince the interviewers. In case of any issues or questions, you can drop us a message at any given time.

Intellinuts Terms : A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z