Categories
News

Ansible 2.0 Interview Questions

Q. What is Ansible?
Ansible is an open-source community project which is a simple IT automation engine, developed by Red Hat Software.

Q. What is Ansible tower?
Ansible Tower is a web-based solution that is designed to be the hub for all automation tasks such that it makes Ansible even easier to use for IT teams of all kinds.

Q. Enlist some advantages of using Ansible?
Some of the advantages of using Ansible are:

Ansible is free of cost
Very simple to set up and use
Ansible is Flexible
Ansible is Efficient
Ansible lets you model even highly complex IT workflows
You don’t need to install any other software or firewall ports

Q. What is Ansible role?
Ansible roles are defined using YAML files. IT is basically a set of tasks used to configure a host to serve a certain purpose like configuring a service.

Q. What is cowsay in ansible?
In Ansible, cowsay is a program that is used to generate the ASCII pictures of a cow following with a message.

Q. What Is An Ansible Playbook?
Ansible playbooks are pre-written code that developers can use on the fly or as a starting point. Ansible playbooks are used to automate complicated IT tasks, infrastructure (like operating system/Kubernetes platforms), security systems, and networks on a regular basis. An Ansible inventory is made up of a group, classification, or set of hosts that are all executed by Ansible playbooks.

A sample playbook may look something like below:

name: Playbook1
connection: ansible.netcommon.network_cli
gather_facts: true
hosts: all
tasks:
– name: Get config for VyOS devices
vyos.vyos.vyos_facts:
gather_subset: all
– name: Display the config
debug:

Q. What Is Ansible Galaxy?
Ansible Galaxy is a collection of Ansible Roles that can be brought directly into your Playbooks to speed up your automation projects.

Galaxy consists of a large number of roles that are always changing and expanding.

Other role sources like GitHub can be added to Galaxy using git. You can use ansible-galaxy init to create a new galaxy role, or you can use ansible-galaxy install role name> to install a role straight from the Ansible Galaxy store.

Other role sources like GitHub can be added to Galaxy using git. You can use ansible-galaxy init to create a new galaxy role, or you can use ansible-galaxy install role name> to install a role straight from the Ansible Galaxy store.

The command to install Ansible galaxy roles and collections simultaneously with a single command :

$ ansible-galaxy install -r requirements.yml

Q. Define Ad-Hoc Commands.
Ad-hoc commands are one-line commands that are used to accomplish a particular task. Ad Hoc commands can be thought of as a replacement for playbooks. The following is an example of an Ad Hoc command:
ansible host -m netscaler -a “nsc_host=nsc.xyz.com user=apiuser password=apipass”
The above Ad Hoc command terminates the server by accessing the netscaler module.

Q. What is Ansible tower?
Ansible is a web-based hub for all your automation tasks. It is based on agentless model that doesn’t require nodes to have locally installed daemons to connect with controlling machine. The Ansible tower is free for usage till 10 nodes.

Q. Explain different modules in Ansible.
There are two types of modules in Ansible namely core modules and extra modules. Modules in Ansible are idempotent and the clients can perform the same result by using modules in Ansible for the operation to be idempotent.

Core modules– The Ansible team gives more importance to these modules over extra modules. Core modules are always shipped with Ansible software.

Extra modules– These modules are maintained by Ansible community and are reusable but receive a lower rate of response to issues. These modules are bundled with Ansible but can be separately available in future.

Q. When to use {{}} ? How to interpolate variables or dynamic variable names?
A steadfast rule is ‘always use {{ }} except when when:‘. Conditionals are always run through Jinja2 as to resolve the expression, so when: failed_when: and changed_when: are always templates and you should avoid adding {{}}.
It is always recommended to use brackets even if you have previously used variables without specifying (like with_clauses). This makes it hard to distinguish between a string and an undefined variable.
Another rule is ‘moustaches don’t stack’. We often see this:
{{ somevar_{{other_var}} }}
The above DOES NOT WORK, if you need to use a dynamic variable use the hostvars or vars dictionary as appropriate:
{{ hostvars[inventory_hostname][‘somevar_’ + other_var] }}

Q. How to install Ansible?
The most effective way to install Ansible for Ubuntu is to add the project’s personal package archive (PPA) to your system. For this, you have to install the software properties common package. This will ensure that you can work with PPA easily. On older versions, this package was called as python software properties. Once the package has been installed, type the following command to add the Ansible PPA.

sudo apt-add-repository ppa:ansible/ansible
Press enter for PPA addition. Once done, refresh the package to see available PPA packages and you can install the software.

sudo apt-get install ansible
sudo apt-get update
We have the software required to administer our servers through Ansible.

Q. How to generate crypto passwords for the user module?
To generate crypto passwords for the user module, mkpasswd utility available in Linux systems is a great option.

Mkpasswd –method=sha-512.
However, if you’re OS X user and this utility is not installed on your system, you can still generate it using python. First check that Passlib passwo4rd hashing library is installed. Once the library is installed, SHA512 password values can then be generated as follows:

python -c “from passlib.hash import sha512_crypt; import getpass; print sha512_crypt.encrypt(getpass.getpass())”
To generate the hashed version of the password, use the hashing filters. Also, use vault to protect sensitive data.

Q. What is Ansible role?
The very first step in creating an Ansible role is creating its directory structure. To create the base directory structure, use a tool bundled with Ansible called Ansible galaxy.

$ ansible-galaxy init azavea.packer

azavea.packer was created successfully
This command will create an azavae.packer directory.

For more  Click Here