When you want to crack an interview, preparation is the essential thing that you need to focus on and we do understand the necessity of it. Therefore, our experts and professionals come with the relevant Ansible interview questions and answers that will help you in cracking the interviews with ease so that you can get into a job smoothly. There will not be many hassles or issues in learning the questions and answers that we prepare as it is quite self-explanatory and easy to remember. So, what are you waiting for? Just start learning from today onwards.
Ansible is basically a cloud computing format service that is introduced by Microsoft to build, test, deploy, and manage all the tools and services through the data centers that are controlled by Microsoft. It offers SaaS (Software as a Service), PaaS (Platform as a Service), and IaaS (Infrastructure as a Service), and is known to support lots of various programming languages, applications, and frameworks that include both the Microsoft-based and third-party application centers or systems. It was launched in the year of October 2008 and since then it is known to dominate the market because of the types of services it offers.
Ansible is a configuration management system. It is used to set up and manage infrastructure and applications. It allows users to deploy and update applications using SSH, without needing to install an agent on a remote system.
Ansible is used for managing IT infrastructure and deploy software apps to remote nodes.
For example, Ansible allows you to deploy as an application to many nodes with one single command. However, for that, there is a need for some programming knowledge to understand the ansible scripts.
Ansible can communicate with configured clients from the command line by using the ansible command. It also allows you to automate configuration by using the ansible-playbook command. To create the base directory structure, you can use a tool bundled with Ansible which is known as ansible-galaxy.
Command:
$ ansible-galaxy init azavea. packer
azavea.packer was created successfully
Continuous delivery is a practice of delivering the software as soon as it is developed. In this method, we need to use a versioning control system. The software is constantly updated in live production systems.
In Ansible, if you want to access existing variables, the user needs to use the ‘env’ lookup plugin. Example, to access the value of the Office environment on the management machine:
You need to write the following code:
# ... vars: local_home: "{{ lookup(env,Office) }}" I {{ ansible_env.SOME_VARIABLE }}
Variable names can be built by adding using the following method:
{{ hostvars[inventory_hostname][ansible_ + which_interface][ipv4][address] }}
The method of using host vars is important because it’s a dictionary of the entire namespace of variables. ‘inventory_hostname’ variable specifies the current host you are looking over in the host loop.
If cowsay is installed then executing playbooks inside the Ansible you can disable coway by using the following options:
export ANSIBLE_NOCOWS=1
The “copy” module has a recursive parameter. However, if you want this to perform more efficiently for a large number of files, then the “synchronize” module is the best option for you.
Documentation for Ansible is kept in the project git repository. It contains complete instructions for contributing can be found in the docs.
You can read everything about “Roles” in the playbooks documentation section. This helps to make playbook content self-contained and shareable with other ansible users.
Ansible Tower is a tool that makes Ansible very easy to use. It acts as a hub for task automation. The tower is free for usage till 10 nodes.
For that use this command:
ansible -m debug -a "var=hostvars[hostname]" localhost
Variable Name | Environment Variables |
It can be built by adding strings. | To access the environment variable, you need to access existing variables. |
{{ hostvars[inventory_hostname][‘ansible_’ + which_interface][‘ipv4’][‘address’] }} | # … vars: local_home: “{{ lookup(‘env’,’HOME’) }}” |
Allows to add strings | To set environment variables, we need to see the advanced playbooks section. |
Ipv4 address type use for Variable names we use the ipv4 address. | For Remote environment variables, use {{ ansible_env.SOME_VARIABLE }} |
You can think of ad-hoc commands as a way for us to take action on our hosts without writing a playbook. For example, if we want to reboot all hosts in a particular group(webservers). Then you can write a playbook or simply run a one-off ad-hoc command.
You can think of ansible facts as a way for ansible to get information about a host and store them in variables for easy access. This information stored in predefined variables is available to use in the playbook. To generate facts, ansible runs the setup module.
You can see them using the host very variable. This stores host variables with the hostname as key. For example, to look at the variables defined for localhost, you can run;
ansible -m debug -a "var=hostvars[inventory_hostnam
Modules in Ansible are idempotent. From a RESTful service standpoint, for the operation to be idempotent, clients can perform the same result by using modules in Ansible. Multiple identical requests become a single request.
There are two different types of modules in Ansible:
Core Modules
The Ansible team maintains these types of modules, and they will always ship with Ansible software. They will also give higher priority for all requests than those in the “extras” repos.
Extras Modules:
These modules currently are bundled with Ansible but might be available separately in the future. They are also mostly maintained by the Ansible Community. These modules are still usable, but they can receive a lower rate of response to issues and pull requests.
Step 1:Create user for ansible useradd -d /home/tadmin -m tadmin passwd tadmin
Step 2:Switch to ansible user so – admin
Step 3:Create .ssh directory mkdir .ssh
Step 4:Change permission to 700 for .ssh chmod 700 .ssh/
Step 5:Change Ownership to tadmin for .ssh chown tadmin:tadmin .ssh/
Step 6:create an authorized_keys file under .ssh and paste the public key from controller and save it
Step 7:;cd .ssh/ , vi authorized_keys
Step 8:Copy & paste the public key from the Controller server to this file [/home/tadmin/.ssh/id_rsa.pub]
Now you can access the server without a password.
Example:ansible -i cmdb.inv main.yml Update default Inventory file/etc/ansible/hosts (as root user) [clients]
Running ansible command #ansible all -m ping
The playbook is a .yml file that contains a piece of code called a module. You can have multiple tasks in a playbook and these tasks would be executed by Ansible. Playbooks have a list of remote hosts, user variables, tasks, handlers inside them.
Below is the sample playbook:
- name: Install Docker and restart service hosts: webapp become: true tasks: - name: Install Docker yum: name: docker state: latest - name: Restart Docker Service service: name: docker state: restarted
list-task: List all the tasks that will be executed when you run a playbook.
The main difference between the two is that an instance of a web role runs IIS, while an instance of a worker role does not. Both are managed in the same way, however, and it’s common for an application to use both. For example, a web role instance might accept requests from users, then pass them to a worker role instance for processing.
The Windows Azure Fabric Controller is a resource provisioning and management layer that manages the hardware and provides resource allocation, deployment/upgrade, and management for cloud services on the Windows Azure platform.
Ansible roles consist of many playbooks. Roles are a way to group multiple tasks into one container. These are reusable scripts.
As most of the institutions in the current day depend on the software that is managed by Microsoft, there are lots of companies that are hiring software developers who possess good skills and expertise in managing this product. Therefore, if you know that you have the right skills and expertise to work on this platform, then try to apply for jobs in your country as there are lots of scopes and opportunities available for you. For a fresher, he or she can grab this opportunity to earn about 86,900 dollars to 90,000 dollars per year, while an experienced worker can earn up to 214,500 dollars per year.
What you need to do is starting preparing using our Azure Interview questions and answers and we assure you that you will easily convince the interviewers. In case of any issues or questions, you can drop us a message at any given time.