Top 50 Interview questions in Configuration Management – Ansible

1. What is Ansible?

Ansible is an open-source automation platform. It can help us with configuration management, task automation or application deployment. It can deploy an application using SSH with no downtime. Ansible is developed or written in Python language.

2. What are the benefits and use of Ansible?

Ansible has many strengths, including:

  • It’s agentless and only requires SSH service running on the target machines
  • Python is the only required dependency and, fortunately, most systems come with the language pre-installed
  • It requires minimal resources, so there’s low overhead
  • It’s easy to learn and understand since Ansible tasks are written in YAML.
  • Unlike other tools, most of which are Procedural, ansible is declarative; define the specified state, and Ansible fulfills the wants needed to realize it

3. How Ansible Works?

Ansible is weakened into two sorts of servers: controlling machines and nodes. Ansible is installed on the controlling computer, and therefore the controlling machines manage the nodes via SSH.

The controlling machine contains an inventory file that holds the node system’s location. Ansible works, runs the playbook on the controlling machine and to deploy the modules. Since Ansible is agentless, there’s no need for a third-party tool to connect the nodes.

4. What’s the use of Ansible?

Ansible is especially utilized in IT infrastructure to manage or deploy applications to remote nodes. Suppose we would like to deploy one application in 100 nodes by just executing one command, then Ansible is really coming into the image, but should need some knowledge on Ansible script to understand or execute.

5. What are CD and CI, and what is Ansible’s relationship with them?

CD stands for continuous delivery, and CI stands for continuous integration; both are software development practices.

In CD, developers build software that can be released into production at any given time. CI, on the opposite hand, consists of every developer uploading regularly scheduled integrations (usually daily), leading to multiple integrations a day . Ansible is a perfect tool for CI/CD processes, providing a stable infrastructure for provisioning the target environment then deploying the appliance thereto .

6. Explain what a “playbook” is?

A playbook has a series of YAML-based files that send commands to remote computers via scripts. Developers can configure entire complex environments by passing a script to the required systems rather than using individual commands to configure computers from the command line remotely. Playbooks are one of Ansible’s strongest selling points and often referred to as the tool’s building blocks.

7. How do you set up Ansible?

You can use either the Python installer or a Linux-based installation process, like apt or yum.

8. What is Ansible Tower?

It’s an enterprise-level web-based solution that increases Ansible’s accessibility to other IT teams by including an easy to use UI (user interface). Tower’s primary function is to serve as the hub for all of an organization’s automation tasks, allowing users to monitor configurations and conduct rapid deployments.

9. What is Ansible Galaxy?

This is a tool bundled with Ansible to make a base directory structure. Galaxy is a website that lets users find and share Ansible content. You can use this command to download roles from the website:

$ ansible-galaxy install username.role_name

10. What’s an ad hoc command?

Users initiate unplanned commands to initiate actions on a number without employing a playbook. Consider it a one-shot command.

11. Explain the difference between a playbook and a play?

A play is a set of tasks that run on one or more managed hosts. Plays consist of one or more tasks. A playbook consists of one or more plays.

12. How do you upgrade Ansible?

Upgrading Ansible is easy. Just use this command: sudo pip install ansible==

13. When do you use {{ }}?

One of Ansible’s most elementary rules is: “Always use {{ }} except when:”

14. How do you keep data secret in a playbook?

If you want to keep secret data but still be able to share it publicly, then use Vault in playbooks. But if you’re using –v (verbose) mode and don’t want anyone to see the results, then use:

name: secret task

shell: /usr/bin/do_something –value={{ secret_value }}

no_log: True

15. What is an Ansible Task?

Ansible Tasks allow you to interrupt up bits of configuration policy into smaller files. These are blocks of code that can be used to automate any process. For example, if you wish to install a package or update a software, you can follow the below code snippet:

Install , update

16. What are Ansible Vaults and why are they used?

Ansible Vault may be a feature that permits you to stay all of your secrets safe. It can encrypt entire files, entire YAML playbooks or maybe a couple of variables. It provides a facility where you’ll not only encrypt sensitive data but also integrate them into your playbooks.

Ansible Vault is implemented with file-level granularity where the files are either entirely unencrypted or entirely encrypted . It uses an equivalent password for encrypting also as for decrypting files which makes using Ansible Vault very user-friendly.

17. Explain Ansible facts?

You can consider ansible facts as how it is possible to urge information to a few hosts and store them in variables for straightforward access. This information stored in predefined variables are available to use within the playbook. To generate facts, ansible runs the setup module.

18. When should you test playbooks and roles?

In ansible, Tests are often added either in new Playbooks or to existing Playbooks. Therefore, most of the testing jobs offer a clean hosting each time. By using this testing methodology, you would like to form little or no to no code changes.

19. How do you access Shell Environment Variables?

If you’re just looking to access the prevailing variables then you’ll use “env” lookup plugin.

For example:

Accessing the worth of Home environment variable on management machine:

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

20. What is that Ansible can do?

Ansible can do the following for us:

1. Configuration management

2. Application deployment

3. Task automation

4. IT orchestration

21. What’s the best way to generate crypto passwords for the user module?

The availability of mkpasswd utility in Linux is the best option for generating the crypto passwords. OS X users who do not have this utility installed on the system, they can also generate crypto passwords by using Python.

22. What are Ansible server requirements?

If you’re a windows user then you would like to possess a virtual machine during which Linux should be installed.

It requires Python 2.6 version and higher.

23. Can you build your own modules with Ansible?

Yes, we can create our own modules within Ansible.

which primarily works on Python and It is an open source tool . If you are good at programming in Python you can start creating your own modules in a few hours from scratch and you don’t need to have any prior knowledge of the same.

24. Explain Module utilities in Ansible?

Ansible provides a good sort of module utilities which help the developers while developing their own modules. The basic.py may be a module which provides the most entry point for accessing the Ansible library and using those as basics one can begin working.

25. Where is the unit testing available in Ansible?

All the Unit tests modules are available in .test/units/modules.

Firstly you have to setup your testing environment

26. How to set up Ansible?

There are two ways to install it.

  • Using Linux based installation procedure (e.g. using apt or yum)
  • For this first add the repository to the APT using command on terminal ‘sudo apt-add-repository -y ppa:ansible/ansible’
  • Update the repository using command ‘sudo apt-get update’
  • Now install Ansible using command ‘sudo apt-get install -y ansible’
  • Using python installer
  • first install python for this on the local machine
  • Then use the sudo pip install ansible command on terminal install Ansible
  • Later on, it can be updated using ‘sudo pip install –upgrade ansible’ command
  • Once Ansible is installed, verify it with command ‘ansible –version’ on the terminal.

27. Compare Ansible and Chef?

Ansible is easier to setup than Chef

  • Network Management more easy to using Ansible
  • In Terms of scalability, both are highly scalable
  • For ‘Ansible YAML’ + Python and for ‘DSL + Ruby’ is employed as a configuration language
  • Ansible Costing in production is cheaper than Puppet.
  • Ansible is agentless but the Chef wants a customs agent on the remote nodes.

28. Compare Ansible and puppet?

Ansible is easier to setup than Puppet

Network Management more easy to using Ansible

In Terms of scalability, both are highly scalable

For Ansible ‘YAML + Python’ and for Puppet ‘DSL + PuppetDSL’ is employed as a configuration language

Ansible Costing in production is cheaper than Puppet.

Ansible is agentless but the Puppet wants a customs agent on the remote nodes.

29. What are the variables in Ansible?

The variable is very similar to using the variables in a programming language. It helps you to assign a value to a variable and use it anywhere in the playbook. You can put the conditions around the value of the variables and use them in the playbook accordingly.

30. What is the best way to make content reusable/redistributable?

If you’ve not done so already, read all about “Roles” within the playbooks documentation. This helps you create playbook content self-contained and works well with things like git submodules for sharing content with others.

If a number of these plugin types look strange to you, see the API documentation for more details about ways Ansible are often extended.

31. How do I see all the inventory vars defined for my host?

You can see the resulting vars you define in inventory running the subsequent command:

ansible -m debug -a “var=hostvars[‘hostname’]” localhost

32. How do I copy files recursively onto a target host?

The “copy” module features a recursive parameter, though if you would like to try to do something more efficient for several files, check out the “synchronize” module instead, which wraps rsync. See the module index for information on both modules.

33. Explain different modules in Ansible?

There are two sorts of modules in Ansible namely core modules and additional modules. Modules in Ansible are idempotent and therefore the clients can perform an equivalent result by using modules in Ansible for the operation to be idempotent.

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

Extra modules– Ansible community maintains these modules and are reusable but receive a lower rate of response to issues. These modules are bundled with Ansible but are often separately available in future.

34. When should I use {{ }}? Also, the way to Interpolate Variables or Dynamic Variable Names?

One of the quality rules is ‘always use {{}} except when:’. Conditionals are always run through Jinja2 to resolve the expression. So when:failed_when: and changed_when: are always templated and that we should avoid adding {{}}.

In other cases except when clauses we have to use brackets, otherwise distinguish between an undefined variable and String will be very difficult.

35. What exactly is a configuration management tool?

Configuration management tools help keep a system running within the desired parameters. They help reduce deployment time and substantially reduce the effort required to perform repetitive tasks. Popular configuration management tools on the market today include Chef, Puppet, Salt, and in fact , Ansible.

Finally, let us go through the Ansible interview questions at an advanced level.

36. Explain what an ask_pass module is?

It’s a playbook control module used to control a password prompt. It’s set to True by default.

37. What are “facts” in the context of Ansible?

Facts are newly discovered and known system variables, found within the playbooks, used mostly for implementing conditionals executions. Additionally, they gather ad-hoc system information.

You can get all the facts by using this command:

  • $ ansible all- m setup

38. How can you connect other devices within Ansible?

Once Ansible is installed on the controlling machines, an inventory file is created. This inventory file specifies the connection between other nodes. A connection can be made using a simple SSH. To check the connection to a different device, you can use the ping module.

ansible -m ping all

The above command checks the connection to all the nodes specified in the inventory file.

39. Explain the callback plugin in Ansible?

It enables adding new behaviors to Ansible when responding to events. By default, callback plugins control most of the output you see when running the command line program. It also can be wont to add additional output, integrate with other tools, etc.

40. Does Ansible support AWS?

Ansible has many modules supporting AWS and a few of them include:

  • Autoscaling groups
  • CloudFormation
  • CloudTrail
  • CloudWatch
  • DynamoDB
  • ElastiCache
  • Elastic Cloud Compute (EC2)
  • Identity Access Manager (IAM)
  • Lambda
  • Relational Database Service (RDS)
  • Route53
  • Security Groups
  • Simple Storage Service (S3)
  • Virtual Private Cloud (VPC)

41. Explain What is ask_sudo_pass?

This control is very similar to ask_pass

It controls the Ansible Playbook to prompt a sudo password. Usually, the default behavior is no:

ask_sudo_pass= True

One has got to confirm and alter this setting where the sudo passwords are enabled most of the time.

42. Explain what is ask_vault_pass?

Using this control we will 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

43. What is the difference between the Variable Name and Environment Variable in Ansible?

Variable NameEnvironment Variable
You need to add strings to create variable names.You need existing variables to access environment variables.
You can easily create multiple variable names by adding strings.To create environment variables, you must refer to the advanced Ansible playbook.
Use the IPV4 address for variable names.Use {{ansible_env.SOME_VARIABLE}} for remote environment variables.

44. Give a brief about Ansible architecture?

The Ansible is highly based on the agentless architecture. This structure enables you to connect your nodes. The pool of modules can linger over any system with none daemons, server or the database. It removes them as soon as work is done.

45. Name the different components of Ansible?

Ansible automation is consist of the following elements:

Inventories

Modules

APIs

Host

Playbooks

Cloud

Networking

46. What is an Ansible Playbook?

The Playbooks are a different way for one to use Ansible than in ad hoc task execution mode and they are particularly powerful. The Playbooks are Ansible configuration, deployment and orchestration. They may describe a policy you’d like your remote systems to enforce or variety of steps within the overall IT process. Ansible refers to a configuration management tool that automates the configuration of various servers through the utilization of Ansible PLAYBOOKS. The playbook is the main element of any Ansible configuration. The playbook has one or multiple plays, which each define the work that is to be done for a configuration on the managed server. Ansible plays are all written in YAML. Every one of the plays is completed by an administrator and with particular parameters for the target machines so there are not any standard plays.

47. Why doesn’t one ship in X format?

There are some reasons for not shipping the usage of X format. It caters toward the maintenance. Within the market there are different means of shipping software and it can be tedious to support each and every one of them.

48. Briefly Explain Pipelining in Ansible?

Pipelining allows Ansible to use stream commands over one connection rather than opening connection for every ansible command.

49. Define Continuous Delivery?

Continuous Delivery is a carry out of delivering the software as soon as it is urbanized. In this process, we require a versioning control system. The software is continually updated in live production systems.

50. What is Forks in Ansible?

Forks may be a thanks to improve your ansible performance defining what percentage ansible processes are going to be created to speak with remote hosts.

Add a Comment

Your email address will not be published. Required fields are marked *