Ansible Interview Questions and Answers - Here are some of the following Ansible interview questions and answers that are generally asked in Ansible interviews.
Ansible is a free-software platform for configuring and managing computers, combines multi-node software deployment, ad hoc task execution, configuration management, provisioning ,Security and Compliance. It manages nodes over SSH or over PowerShell. Modules work over JSON and standard output and can be written in any programming language. The system uses YAML to express reusable descriptions of systems. It aims to provide large productivity gains to a wide variety of automation challenges. Unlike Puppet or Chef it doesn’t use an agent on the remote host. Instead Ansible uses SSH which is assumed to be installed on all the systems you want to manage. Also it’s written in Python which needs to be installed on the remote host. This means that you don’t have to setup a client server environment before using Ansible, you can just run it from any of your machines and from the clients point of view there is no knowledge of any Ansible server (you can run Puppet in standalone mode, but Puppet still needs to be installed). There are some other requirements though, for example if you want to do something related to git on a remote machine a git package must first be installed on the remote machine.
Ansible is available for free and runs on Linux, Mac or BSD. Aside from the free offering, Ansible also has an enterprise product called Ansible Tower. Ansible tool is very simple to use yet powerful enough to automate complex multi-tier IT application environments.
Michael DeHaan, the author of the provisioning server application Cobbler and co-author of the Func framework for remote administration, developed the platform. Ansible, Inc. (originally AnsibleWorks, Inc.) was the company set up to commercially support and sponsor Ansible. Red Hat acquired Ansible in October 2015. Current version is Ansible v2.4.3.0-0.5.rc2 /January 18, 2018.
What is Ansible?
Ansible is an open source software platform for managing and combining multi node software deployment, as well as ad-hoc changes in the execution and configuration management of a system. Ansible is a new devops tools that enter after puppet and chef were already established in the IT market. It has a different approach to solving the IT infrastructure and automation issues. The original author of Ansible created it, with the intention that to deploy infrastructure, you shouldn’t be required to learn programming. To connect to remote servers that needs to be managed, ansible either uses ssh for *nix based system and winrm(windows remote management) for windows based systems.

Which language Ansible is written in?
Ansible is written in Python and PowerShell

What Ansible can do?
We have many automation tools used in the market namely Chef, Puppet, Salt stack and Maven etc. Each tools has own functionality and features. Ansible can be used in many different ways too. I have mentioned some of them below:
  • Configuration Management
  • Application deployment
  • Security and Compliance
  • Provisioning
  • Orchestration
How Ansible Works?
Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs. Ansible categorize into two types of server: controlling machines and nodes.
The controlling machine, where Ansible is installed and Nodes are managed by this controlling machine over SSH. The location of nodes are specified by controlling machine through its inventory. The controlling machine (Ansible) deploys modules to nodes using SSH protocol and these modules are stored temporarily on remote nodes and communicate with the Ansible machine through a JSON connection over the standard output.
Process of Ansible:
  • Setting up the Architecture
  • SSH keys and their role
  • Managing Inventory in simple text files
  • Using Ansible
What are the advantages of Ansible?
  • Ansible is a free and open source software
  • Easier and faster to deploy as it doesn’t rely on agents or additional custom security infrastructure.
  • Ansible has the flexibility to allow user-made modules that can be written in any programming language such as Ruby, Python. It also allows adding new server side behaviors extending Ansible’s connection types through Python APIs.
  • System requirement is very low in Ansible
  • Ansible using YAML Syntax in Configuration files
What is Ansible Playbooks?
Playbooks are a completely different way to use ansible than in adhoc task execution mode, and are particularly powerful. Playbooks are Ansible’s configuration, deployment, and orchestration language. They can describe a policy you want your remote systems to enforce, or a set of steps in a general IT process. Ansible is a configuration management tool that automates the configuration of multiple servers by the use of Ansible playbooks.  The playbook is the core component of any Ansible configuration. An Ansible playbook contains one or multiple plays, each of which define the work to be done for a configuration on a managed server. Ansible plays are written in YAML. Every play is created by an administrator with environment-specific parameters for the target machines; there are no standard plays.

Do we have any Web Interface/ Rest API etc for this?
Yes, Ansible Inc makes a great efficient tool. It is easy to use

What is Ansible Tower?
Ansible Tower (AWX) is a web-based solution that makes Ansible even more easy to use for IT teams of all kinds. It is considered to be or acts like a hub for all of your automation tasks. The tower is free for usage till 10 nodes.

What is Ad-hoc commands in Ansiable?
Ad-hoc commands are a powerful yet simple feature of Ansible. Ad-hoc commands are commands that we use only for quick purposes that we don't want to save for later, such as checking the status of a server or copying a file to the server tasks we just want to do quickly by typing only few commands.

How to write an Ansible ad-hoc command?
ansible <hosts> [-m <module_name>] -a <"arguments"> -u <username> [--become]
Hosts: It can be any entry in the inventory file. For specifying all hosts in inventory, use all or '*'. Wild card patterns are also accepted.
Module name: It's an optional parameter. There are hundreds of modules available in Ansible. By default it is command. For example shell, copy, yum, apt, file.
Arguments: We should pass values that are required by the module. It may change according to the module used.
Username: It specifies the user account in which Ansible can execute commands. User account, SSH.
Become: It's an optional parameter specified when we want to execute operations that need sudo privilege. By default become is false.
If you put a -c option, then Ansible will do a dry run of the command. It will not actually be applied on the nodes.

How do I submit a change to the documentation in Ansible?
Documentation for Ansible is kept in the main project git repository, and complete instructions for contributing can be found in the docs.

How do you access Shell Environment Variables?
If you are just looking to access the existing variables then you can use “env” lookup plugin.
For example: Accessing the value of Home environment variable on management machine:

How do I copy files recursively onto a target host in Ansible?
 In Ansible, The copy module has a recursive parameter. However, take a look at the “synchronize” module if you want to do something more efficient for a large number of files. The “synchronize” module wraps resync.

How do I disable cowsay in Ansible?
In Ansible, if cowsay is installed, Ansible takes it upon itself to make your day happier when running playbooks. If you decide that you would like to work in a professional cow-free environment, you can either uninstall cowsay, or set the ANSIBLE_NOCOWS environment variable: export ANSIBLE_NOCOWS=1(ref ansible doc)

How do I generate crypted passwords for the user module in Ansible?
The mkpasswd utility that is available on most Linux systems is a great option:
mkpasswd --method=sha-512
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.using(rounds=5000).hash (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 Using Vault in playbooks to encrypt sensitive data. (Ref ansible doc)

How do i see all the inventory vars defined for my host?
You can see the resulting vars you define in inventory running the following command:
ansible -m debug -a “var=hostvars[‘hostname’]” localhost.

What is the best way to make content reusable/redistributable?
If you have not done so already, read all about “Roles” in the playbooks documentation. This helps you make playbook content self-contained, and works well with things like git submodules for sharing content with others.
If some of these plugin types look strange to you, see the API documentation for more details about ways Ansible can be extended.

How can you speed up management inside in EC2?
It is not advised to manage a group of EC2 machines from your laptop. The best way is to connect to a management node inside Ec2 first and then execute Ansible from there.

What is ask_sudo_pass in Ansible?
This control is very similar to ask_pass
The ask_sudo_pass controls the Ansible Playbook to prompt a sudo password. Usually, the default behavior is no:
ask_sudo_pass= True
One has to make sure and change this setting where the sudo passwords are enabled most of the time.

What is ask_vault_pass in Ansible?
Using this control we can determine whether Ansible Playbook should prompt a password for the vault password by default. As usual, the default behavior is no
ask_vault_pass= True
Request to Download PDF


Vestibulum bibendum felis sit amet dolor auctor molestie. In dignissim eget nibh id dapibus. Fusce et suscipit orci. Aliquam sit amet urna lorem. Duis eu imperdiet nunc, non imperdiet libero.

Post A Comment: