Corporate Training
Request Demo
Click me
Menu
Let's Talk
Request Demo

Ansible Interview Questions and Answers

by Mohammed, on May 18, 2018 5:37:48 PM

Ansible Interview Questions and Answers

Q1. What Is Ansible ?

Ans: Ansible is a software tool to deploy application using ssh without sny downtime.It is also used to manage and configure software applications. Ansible is developed by Python language.

Q2. What is Ansible galaxy?

Ans: Galaxy refers to bothe website and CLI tool used to the interact with the website where you can download and share roles with other members of the ansible communty.

Q3. What is Forks in Ansible

Ans: Forks is a way to improve your ansible performance defining how many ansible processes will be created to communicate with remote hosts.

Q4. Briefly Explain Pipelining in Ansible.

Ans: Pipelining allows Ansible to use stream commands over a single connection instead of opening connection for each ansible command.

Q5. How can we use controlpersist to speed up ansible deployment?

Ans: This allows us to create a single master connection that can be reused subsequently for a given amount of time.

Q6. Explain “fire and forget” concept in ansible.

Ans: This allows us to  run a task without waiting for completion. You simply run the task Async and set poll=0.  Later in the playbook, use async_status to check the status of the job.

Q7. How do we make a variable available to a host or group without including it in the inventory file?

Ans: You can create a variable file under group_vars. For example, lets say we want to make a variable available too the webserver host group, you simple create group_vars/webservers and define the variable inside the file.

Q8. What’s The Use Of Ansible ?

Ans: Ansible can be used in IT infrastructure to manage and deploy software applications to remote nodes. For example, let’s say you need to deploy a single software or multiple software to 100’s of nodes by a single command, here ansible comes into picture, with the help of Ansible you can deploy as many as applications to many nodes with one single command, but you must have a little programming knowledge for understanding the ansible scripts.
We’ve compiled a series on Ansible, title ‘Preparation for the Deployment of your IT Infrastructure with Ansible IT Automation Tool‘, through parts 1-4 and covers the following topics.

Q9. Why would you want to disable ansible facts.

Ans: You can disable facts if it its not being used to save on memory used for storing the variables created during facts/

Q10. What are ansible strategies?

Ans: Ansible strategies are plugins that modifies the way ansible works. For example, the linear strategy executes task on the host in series waiting for all hosts to complete before moving to next task while free moves on to next task once it finish execution on a host. For debug strategy, it executes linear but triggers debugger on failure.

 

Q11. How can I set the PATH or any other environment variable for a task or entire playbook?

Ans: Setting environment variables can be done with the environment keyword. It can be used at the task or the play level:

environment:
PATH: ":/thingy/bin"
SOME: value

Note : starting in 2.0.1 the setup task from gather_facts also inherits the environment directive from the play, you might need to use the |default filter to avoid errors if setting this at play level.

Q12. How Do I Submit A Change To The Documentation ?
Documentation for Ansible is kept in the main project git repository, and complete instructions for contributing can be found in the docs.

Q13. When Should I Use ? Also, How To Interpolate Variables Or Dynamic Variable Names ?

Ans: 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 templated and you should avoid adding .
In most other cases you should always use the brackets, even if previouslly you could use variables without specifying (like with_ clauses), as this made it hard to distinguish between an undefined variable and a string.
Another rule is ‘moustaches don’t stack’. We often see this:

}}

The above DOES NOT WORK, if you need to use a dynamic variable use the hostvars or vars dictionary as appropriate:

Q14. How do I handle different machines needing different user accounts or ports to log in with?

Ans: Setting inventory variables in the inventory file is the easiest way.
Ansible 2.0 has deprecated the “ssh” from ansible_ssh_user,  ansible_ssh_host, and ansible_ssh_port to become ansible_useransible_host, and ansible_port.

If you are using a version of Ansible prior to 2.0, you should continue using the older style variables (ansible_ssh_*). These shorter variables are ignored, without warning, in older versions of Ansible.

For instance, suppose these hosts have different usernames and ports:

[webservers]
asdf.example.com ansible_port=5000 ansible_user=alice
jkl.example.com ansible_port=5001 ansible_user=bob

You can also dictate the connection type to be used, if you want:

[testcluster]
localhost ansible_connection=local
/path/to/chroot1 ansible_connection=chroot
foo.example.com ansible_connection=paramiko

You may also wish to keep these in group variables instead, or file them in a group_vars/<groupname> file. See the rest of the documentation for more information about how to organize variables

Q15. How To Install Ansible ?

Ans: The best way to get Ansible for Ubuntu is to add the project’s PPA (personal package archive) to your system.

To do this effectively, we need to install the software-properties-common package, which will give us the ability to work with PPAs easily. (This package was called python-software-properties on older versions of Ubuntu.)

  • sudo apt-get update
  • sudo apt-get install software-properties-common

Once the package is installed, we can add the Ansible PPA by typing the following command

sudo apt-add-repository ppa:ansible/ansible

Press ENTER to accept the PPA addition.

Next, we need to refresh our system’s package index so that it is aware of the packages available in the PPA. Afterwards, we can install the software:

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

Q16. How Do I Generate Crypted Passwords For The User Module ?
mkpasswd –method=sha-512

Ans: If this utility is not installed on your system (e.g. you are using OS X) then you can still easily generate these passwords using Python. First, ensure that the Passlib password hashing library is installed.

pip install passlib

Once the library is ready, 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())”

Use the integrated Hashing filters to generate a hashed version of a password. You shouldn’t put plaintext passwords in your playbook or host_vars; instead, use Vault to encrypt sensitive data.

Topics:Ansible Interview QuestionsAnsible Interview Questions and AnswersInformation Technologies (IT)

Comments

Subscribe

Top Courses in Python

Top Courses in Python

We help you to choose the right Python career Path at myTectra. Here are the top courses in Python one can select. Learn More →

aathirai cut mango pickle

More...