Ansible Interview Questions

Ansible interview questions Download Ansible interview questions PDF

Ansible interview questions

The most effective way to install Ansible for Ubuntu is to add 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.

The trick lies in this command:

{{ hostvars[groups['webservers'][0]]['ansible_eth0']['ipv4']['address'] }}

Here, we’re pulling out the hostname of the first machine of the webservers group. If you’re doing this in a template, use the Jinja2 ‘#set’ or in a playbook, you can also use set_fact:

- set_fact: headnode={{ groups[['webservers'][0]] }}
- debug: msg={{ hostvars[headnode].ansible_eth0.ipv4.address }}
Variable Name Environment variables
To build variable names, you need to add strings.To access environment variables, you have to access existing variables.
It allows adding more strings.We need to see advances playbook section to set environment variables.
We use the ipv4 address for variable names.We use {{ ansible_env.SOME_VARIABLE }} for remote environment variables.
{{ hostvars[inventory_hostname][‘ansible_’ + which_interface][‘ipv4′][‘address’]


# … vars: local_home: ”

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

Ansible is an open source automation platform which can help you with configuration management, task automation and application deployment. Ansible uses SSH installed on all systems unlike other configuration softwares that work on agent architecture. Ansible also do IT orchestration where you run tasks and create a chain of events that happen on different servers and devices. It is written on Python language which needs to be installed on the remote host. Ansible is very easy to set up yet it is a very powerful tool for software deployment.

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.