Top Ansible(2021) Interview Questions | CodeUsingJava
















Top Ansible Interview Questions


  1. What is Ansible?
  2. How Ansible Works?
  3. What is Configuration Management?
  4. What are Roles?
  5. What are the Ansible Server requirements?
  6. What is the way to access shell environment variables in Ansible?
  7. What are the basic concepts in Ansible?
  8. What are Ad-hoc commands?
  9. How to create a directory using Ansible?
  10. How to ignore ansible SSH authenticity checking?
  11. What is Ansible Tower?
  12. How to create an empty file with Ansible?

What Is Ansible?

Ansible helps in automating taks which are cumbersome, repetitive or complex such as configuration management, cloud provisioning as it has over 750 modules built in it.Ansible is an open source which enables infrastructure as code.It runs by many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows.

How Ansible Works?

Ansible works by connecting nodes and pushing out all small programs known as Ansible Modules, it executes modules and removes them when they are finished.Modules helps in residing any machine, and there are no servers, daemons and database required.
Ansible removes the modules once they are installed and connects to the host machine, also executes the instruction when it is successfully installed removes the code which is copied on the host machine which is executed.

What is Configuration Management?

Configuration Management helps in maintaining configuration of the product performance by keeping records and updating detailed information that describes enterprise hardware and software.

What are Roles?

Roles in Ansible are a collection of variables, tasks, files, templates, and modules.It helps in breaking the modules into multiple files, as it makes them easier to reuse.
Roles is a functionality output, provides the result within that role itself or in other roles listed as dependencies.We cannot execute a role directly.They have no explicit setting for the host the role will apply to.

What are the Ansible Server requirements?

If you are a windows user, then you required to have a virtual machine in which Linux should be installed.
And it requires python 2.6 version or higher.

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

We can access shell environment variables by using the following code:
---
# ...
vars:
local_home: "{{ lookup('env','Office') }}"
I
{{ ansible_env.SOME_VARIABLE }}


What are the basic concepts in Ansible?

The basic concepts of Ansible are:
  • Conroller Machine - used in provisioning the servers.
  • Inventory - used in initializing file that contains details about different servers.
  • Playbook - helps in containing tasks which are needed to be automated.
  • Task - used to represent single procedures needed to be executed.
  • Module - helps by setting the tasks which can be executed.
  • Role - helps in organizing playbooks and other files for sharing and reusing portions of provisioning.
  • Play - used for executing the playbook.
  • Facts - helps in storing details about the systems like network interfaces or operating system.
  • Handlers - used for triggering status of service like restarting or stopping a service.

What are Ad-hoc commands?

Ad-hoc commands are used for performing a certain tasks.
ansible host -m netscaler -a "nsc_host=nsc.example.com user=ansiuser password=ansipass"  


How to create a directory using Ansible?

- name: Creates directory
  file:
    path: /src/www
    state: directory


How to ignore ansible SSH authenticity checking?

For ignoring ansible SSH we need to use the following code:
[defaults]
host_key_checking = False


What is Ansible Tower?

Ansible tower is used for increasing Ansible's accessibility to other IT teams by including an easy way to use UI, it is a function which servers as the hub for all organization's automation tasks by allowing users for monitoring configurations ans conduct rapid deployments.

How to create an empty file with Ansible?


name: ensure file exists
  copy:
    content: ""
    dest: /etc/nologin
    force: no
    group: sys
    owner: root
    mode: 0555