{"id":26963,"date":"2022-02-17T05:53:03","date_gmt":"2022-02-17T05:53:03","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=26963"},"modified":"2022-04-13T16:56:44","modified_gmt":"2022-04-13T16:56:44","slug":"top-50-ansible-interview-questions-and-answers","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/top-50-ansible-interview-questions-and-answers\/","title":{"rendered":"Top 50 Ansible interview questions and answers"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"497\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/db-nginxseriesanisibleplaybook-1024x497.jpg\" alt=\"\" class=\"wp-image-26966\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/db-nginxseriesanisibleplaybook-1024x497.jpg 1024w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/db-nginxseriesanisibleplaybook-300x146.jpg 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/db-nginxseriesanisibleplaybook-768x373.jpg 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/db-nginxseriesanisibleplaybook-1536x746.jpg 1536w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/db-nginxseriesanisibleplaybook-2048x995.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption><em><strong>Ansible interview questions and answers<\/strong><\/em><\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q1-what-is-ansible\">Q1) What is Ansible?<\/h2>\n\n\n\n<p>Ansible is developed in Python language. It is a software tool. It is useful while deploying any application using ssh without any downtime. Using this tool one can manage and configure software applications very easily.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q2-what-are-the-advantages-of-using-ansible\">Q2) What are the advantages of using Ansible?<\/h2>\n\n\n\n<p>The main three advantages of using this tool are,i.e. Ansible<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Agentless<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li> Very low overhead<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li> Good performance<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q3-what-s-the-use-of-ansible\">Q3) What\u2019s the Use of Ansible.<\/h2>\n\n\n\n<p>Ansible can be used in IT Infrastructure to manage and deploy software applications to remote nodes. For example, let\u2019s say you need to deploy a single software or multiple software to 100\u2019s of nodes by a single command, here ansible comes into the picture, with the help of Ansible you can deploy as many applications to many nodes with one single command, but you must have a little programming knowledge for understanding the ansible scripts.<\/p>\n\n\n\n<p>We\u2019ve compiled a series on Ansible, title \u2018Preparation for the Deployment of your IT Infrastructure with Ansible IT Automation Tool\u2018, through parts 1-4 and covers the following topics.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q4-what-is-ci-cd-and-how-ansible-is-related-to-it\">Q4) What is CI\/CD? And how Ansible is related to it?<\/h2>\n\n\n\n<p>CI\/CD is one of the best software development practices to implement and develop code effectively. CI stands for Continuous Integration, and CD stands for continuous delivery. Continuous Integration is a collection of practices that drive developers to implement and check-in code to version control repositories. Continuous delivery picks up where continuous Integration ends. This process builds software in such a way that software will be released into production at any given time.<\/p>\n\n\n\n<p>Ansible is an excellent tool for CI\/CD processes, which provide a stable infrastructure to a provision target environment and then deploy the application to it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q5-can-you-create-reusable-content-with-ansible\">Q5) Can you create reusable content with Ansible?<\/h2>\n\n\n\n<p>Yes, Ansible has the concept of roles that helps to create reusable content. To create a role, you need to follow Ansible&#8217;s conventions of structuring directories and naming files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q6-is-ansible-a-configuration-management-tool\">Q6) Is Ansible a Configuration management tool?<\/h2>\n\n\n\n<p>Configuration management is the practice to handle updates and manage the consistency of a product&#8217;s performance over a particular period of time. Ansible is an open-source IT Configuration Management tool, which automates a wide variety of challenges in complex multi-tier IT application environments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q7-how-to-create-an-empty-file-with-ansible\">Q7) How to create an empty file with Ansible?<\/h2>\n\n\n\n<p>To create an empty file, Ansible uses a file module. For this, we need to set up two parameters.<\/p>\n\n\n\n<p>Path &#8211; This place represents the location where the file gets created, either the relative or an absolute path. Also, the name of the file includes here.\nState &#8211; For creating a new file, this parameter should be set to touch.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q8-how-will-you-set-the-environment-variable-or-any-path-for-a-task-or-entire-playbook\">Q8) How will you set the environment variable or any path for a task or entire playbook?<\/h2>\n\n\n\n<p>To set the environment variables, we use the environment keyword. We&#8217;ll use it at the task or other levels in the play:<\/p>\n\n\n\n<p>environment:<br>PATH: &#8220;{{ ansible_env.PATH }}:\/thingy\/bin&#8221;<br>SOME: value<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q9-how-would-you-describe-yourself-in-terms-of-what-you-do-and-how-you-d-like-to-be-remembered\">Q9) How would you describe yourself in terms of what you do and how you\u2019d like to be remembered?<\/h2>\n\n\n\n<p>Obviously, I\u2019d like to be remembered as a master of prose who forever changed the face of literature as we know it, but I\u2019m going to have to settle for being remembered as a science fiction writer (and, more and more, critic) who wrote the occasional funny line and picked up a few awards.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q10-why-are-you-attracted-to-science-and-science-fiction\">Q10) Why are you attracted to science and science fiction?<\/h2>\n\n\n\n<p>Early imprinting, maybe, for the science fiction. When I was quite small a family friend let me read his 1950s run of \u2018Galaxy\u2019 magazine. My favorite aunt pressed John Wyndham\u2019s \u2018The Day of the Triffids\u2019 on me; a more terrifying great-aunt gave me G.K. Chesterton\u2019s fantastic novels; and so on.<\/p>\n\n\n\n<p>The incurable addiction had begun. Meanwhile, science classes just seemed to be the part of a school that made the most sense, and I fell in love with Pelican pop-maths titles \u2013 especially Kasner\u2019s and Newman\u2019s \u2018Mathematics and the Imagination\u2019 and all those books of Martin Gardner\u2019s \u2018Scientific American\u2019 columns.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q11-describe-your-newsletter-ansible-and-who-it-s-aimed-at\">Q11) Describe your newsletter Ansible and who it\u2019s aimed at.<\/h2>\n\n\n\n<p>It appears monthly and has been called the \u2018Private Eye\u2019 of science fiction, but isn\u2019t as cruel and doesn\u2019t (I hope) recycle old jokes quite as relentlessly. Though I feel a certain duty to list some bread-and-butter material like conventions, award winners, and deaths in the field, \u2018Ansible\u2019 skips the most boring SF news \u2013 the long lists of books acquired, books published, book sales figures, major new remainders \u2013 in favor of quirkier items and poking fun at SF notables. The most popular departments quote terrible lines from published SF\/fantasy and bizarre things said about SF by outsiders (\u2018As Others See Us\u2019). All the back issues of \u2018Ansible\u2019 since it started in 1979 can be read online.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q12-so-how-does-ansible-work-please-explain-in-detail\">Q12) So how does Ansible work? Please explain in detail?<\/h2>\n\n\n\n<p>Within the market, they are many automation tools like Puppet, Capistrano, Chef, Salt, Space Walk, etc.<\/p>\n\n\n\n<p>When it comes to Ansible, this tool is categorized into two types of servers:     <\/p>\n\n\n\n<p>1. Controlling machines     <\/p>\n\n\n\n<p>2. Nodes Ansible is an agentless tool so it doesn\u2019t require any mandatory installations on remote nodes. So there are no background programs that are executed while it is managing any nodes. Ansible is able to handle a lot of nodes from a single system over an SSH connection. Playbooks are defined as a bunch of commands where they are capable of performing multiple tasks and they are in YAML file format.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q13-what-does-ansible-offer\">Q13) What does Ansible offer?<\/h2>\n\n\n\n<p>Ansible offers:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Security and Compliance policy integration. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Automated workflow for Continuous Delivery. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Simplified orchestration. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>App deployment. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Configuration management. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Streamlined provisioning.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q14-can-we-manage-windows-nano-server-using-ansible\">Q14) Can we manage Windows Nano Server using Ansible?<\/h2>\n\n\n\n<p>No, it is not possible to manage Windows Nano Server using Ansible as it doesn&#8217;t have full access to the .Net framework, which is primarily used by internal components and modules.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q15-do-we-have-any-web-interface-rest-api-etc-fo\">Q15) Do we have any Web Interface\/ Rest API etc fo<\/h2>\n\n\n\n<p>Yes, Ansible Inc makes a great efficient tool. It is easy to use.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q16-what-is-ansible-tower\"><br>Q16) What is Ansible Tower?<\/h2>\n\n\n\n<p>Ansible is classified as a web-based solution which makes Ansible very easy to use. 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q17-what-are-the-features-of-the-ansible-tower\"><br>Q17) What are the features of the Ansible Tower?<\/h2>\n\n\n\n<p>Features of the Ansible Tower are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Ansible Dashboard. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Real-time job status updates. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Multi-playbook workflows. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Who Ran What Job When. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Scale capacity with tower clusters. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Integrated notifications. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Schedule ansible jobs. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Manage and track inventory. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Remote command execution. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>REST API &amp; Tower CLI Tool. <\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q18-how-do-change-the-documentation-and-submit-it\">Q18) How do change the documentation and submit it?<\/h2>\n\n\n\n<p>Usually, the documentation is kept in the main project folder in the git repository. For complete instructions on this can be available in docs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q19-how-do-you-access-shell-environment-variables\">Q19) How do you access Shell Environment Variables?<\/h2>\n\n\n\n<p>If you are just looking to access the existing variables then you can use the \u201cenv\u201d lookup plugin.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<p>Accessing the value of Home environment variable on management machine:<\/p>\n\n\n\n<p>local_home:\u201d{{lookup(\u2018env\u2019,\u2019HOME\u2019)}}\u201d<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q20-how-can-you-speed-up-management-inside-ec2\">Q20) How can you speed up management inside EC2?<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q21-what-are-the-features-of-ansible\">Q21) What are the features of Ansible?<\/h2>\n\n\n\n<p>It has the following features:<\/p>\n\n\n\n<p>Agentless \u2013 Unlike puppet or chef there is no software or agent managing the nodes. Python \u2013 Built on top of python which is very easy to learn and write scripts and one of the robust programming languages.<\/p>\n\n\n\n<p> SSH \u2013 Passwordless network authentication which makes it more secure and easy to set up. <\/p>\n\n\n\n<p>Push architecture \u2013 The core concept is to push multiple small codes to the configure and run the action on client nodes. <\/p>\n\n\n\n<p>Setup \u2013 This is very easy to set up with a very low learning curve and any open source so that anyone can get hands-on.<\/p>\n\n\n\n<p> Manage Inventory \u2013 Machines\u2019 addresses are stored in a simple text format and we can add different sources of truth to pull the list using plugins such as Openstack, Rackspace, etc.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q22-explain-infrastructure-as-code\">Q22) Explain Infrastructure as Code?<\/h2>\n\n\n\n<p>Infrastructure as Code or IaC is a process that DevOps teams should follow to have a more organized way of managing the infra. Instead of some throwaway scripts or manually configuring any cloud component, there should be a code repo where all of these will lie and any change in configuration should be done through it. It is wise to put it under source control also. This improves speed, consistency, and accountability.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q23-what-is-ansible-galaxy\">Q23) What is Ansible Galaxy?<\/h2>\n\n\n\n<p>Galaxy is a repository of Ansible roles that can be shared among users and can be directly dropped into playbooks for execution. It is also used for the distribution of packages containing roles, plugins, and modules also known as collection. The ansible-galaxy-collection command implements similar to init, build, install, etc like an ansible-galaxy command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q24-explain-ansible-modules-in-detail\">Q24) Explain Ansible modules in detail?<\/h2>\n\n\n\n<p>Ansible modules are like functions or standalone scripts which run specific tasks idempotently. The return value of these are JSON string in stdout and input depends on the type of module. These are used by Ansible playbooks.<br>There are 2 types of modules in Ansible:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">Core Modules<\/code><\/span><\/pre>\n\n\n<p>The core Ansible team is responsible for maintaining these modules thus these come with Ansible itself. The issues reported are fixed on priority than those in the \u201cextras\u201d repo.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">Extras Modules<\/code><\/span><\/pre>\n\n\n<p>The Ansible community maintains these modules so, for now, these are being shipped with Ansible but they might get discontinued in the future. These can be used but if there are any feature requests or issues they will be updated on low priority.<\/p>\n\n\n\n<p>Now popular extra modules might enter into the core modules anytime. You may find these separate repos for these modules as ansible-modules-core and ansible-modules-extra respectively.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q25-how-to-automate-the-password-input-in-playbook-using-encrypted-files\">Q25) How to automate the password input in playbook using encrypted files?<\/h2>\n\n\n\n<p>To automate password input we can have a password file for all the passwords of encrypted files will be saved and ansible can make a call to fetch those when required.<\/p>\n\n\n\n<p>ansible_ssh_common_args: &#8216;-o ProxyCommand=&#8221;ssh -W %h:%p -q user@gateway.example.com&#8221;&#8216;<\/p>\n\n\n\n<p>This can also be achieved by having a separate script that specifies the passwords. But in this case, we need to print a password to stdout to work without annoying errors.<\/p>\n\n\n\n<p>ansible-playbook launch.yml &#8211;vault-password-file ~\/ .vault_pass.py<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q26-what-are-callback-plugins-in-ansible\">Q26) What are callback plugins in Ansible?<\/h2>\n\n\n\n<p>Callback plugins basically control most of the output we see while running cmd programs. But it can also be used to add additional output. For example log_plays callback is used to record playbook events to a log file, and mail callback is used to send email on playbook failures. We can also add custom callback plugins by dropping them into a callback_plugins directory adjacent to play, inside a role, or by putting it in one of the callback directory sources configured in ansible.cfg.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q27-explain-how-you-will-copy-files-recursively-onto-a-target-host\">Q27) Explain how you will copy files recursively onto a target host?<\/h2>\n\n\n\n<p>There\u2019s a copy module that has a recursive parameter in it but there\u2019s something called synchronize which is more efficient for large numbers of files.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>synchronize:<br>src: \/first\/absolute\/path<br>dest: \/second\/absolute\/path<br>delegate_to: &#8220;{{ inventory_hostname }}&#8221;<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q28-what-is-the-best-way-to-make-content-reusable-redistributable\">Q28) What is the best way to make Content Reusable\/ Redistributable?<\/h2>\n\n\n\n<p>To make content reusable and redistributable Ansible roles can be used. Ansible roles are basically a level of abstraction to organize playbooks. For example, if we need to execute 10 tasks on 5 systems, writing all of them in the playbook might lead to blunders and confusion. Instead we create 10 roles and call them inside the playbook.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q29-what-are-handlers\">Q29) What are handlers?<\/h2>\n\n\n\n<p>Handlers are like special tasks which only run if the Task contains a \u201cnotify\u201d directive.<\/p>\n\n\n\n<p>tasks:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>name: install nginx apt: pkg=nginx state=installed update_cache=true notify:<ul><li>start nginx<br>handlers:<\/li><\/ul><\/li><li>name: start nginx<br>service: name=nginx state=started<\/li><\/ul>\n\n\n\n<p>In the above example after installing NGINX we are starting the server using a <code>start nginx<\/code> handler.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q30-how-does-dot-notation-and-array-notation-of-variables-are-different\">Q30) How does dot notation and array notation of variables are different?<\/h2>\n\n\n\n<p>Dot notation works fine unless we stump upon few special cases such as<\/p>\n\n\n\n<p>If the variable contains a dot(.), colon(:), starting or ending with an underscore or any known public attribute.\nIf there\u2019s a collision between methods and attributes of python dictionaries.\nArray notation also allows for dynamic variable composition.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q31-what-is-the-code-you-need-to-write-for-accessing-a-variable-name\">Q31) What is the code you need to write for accessing a variable name?<\/h2>\n\n\n\n<p>Variable names can be built by adding using the following method:<\/p>\n\n\n\n<p>{{ hostvars[inventory_hostname][&#8216;ansible_&#8217; + which_interface][&#8216;ipv4&#8217;][&#8216;address&#8217;] }}<\/p>\n\n\n\n<p>The method of using hostvars is important because it\u2019s a dictionary of the entire namespace of variables. \u2018inventory_hostname\u2019 variable specifies the current host you are looking over in the host loop.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q32-explain-how-you-can-disable-cowsay\">Q32) Explain how you can disable cowsay?<\/h2>\n\n\n\n<p>If cowsay is installed then executing playbooks inside the Ansible you can disable coway by using following options:<\/p>\n\n\n\n<p>Uninstall cowsay<\/p>\n\n\n\n<p> Setting up value for the environment variable<\/p>\n\n\n\n<p>export ANSIBLE_NOCOWS=1<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q33-explain-how-you-can-copy-file-recursively-onto-a-target-host\">Q33) Explain how you can copy file recursively onto a target host?<\/h2>\n\n\n\n<p>The \u201ccopy\u201d module has a recursive parameter. However, if you want this to perform more efficient for a large number of files, then \u201csynchronize\u201d module is the best option for you.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q34-how-can-you-submit-a-change-to-the-documentation-in-ansible\">Q34) How Can you submit a change to the Documentation in Ansible?<\/h2>\n\n\n\n<p>Documentation for Ansible is kept in the project git repository. It contains complete instructions for contributing can be found in the docs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q35-what-is-the-best-method-to-make-content-reusable-redistributable\">Q35) What Is the Best Method to Make Content Reusable\/redistributable?<\/h2>\n\n\n\n<p>You can read everything about \u201cRoles\u201d in the playbooks documentation section. This helps to make playbook content self-contained and shareable with other ansible users.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q36-what-is-ansible-tower\">Q36) What is Ansible Tower?<\/h2>\n\n\n\n<p>Ansible tower is a tool which makes Ansible very easy to use. It acts as a hub for the task automation. The tower is free for usage till 10 nodes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q37-what-s-the-method-to-check-the-inventory-vars-defined-for-the-host\">Q37) What\u2019s the method to check the inventory vars defined for the host?<\/h2>\n\n\n\n<p>For that use this command:<\/p>\n\n\n\n<p>ansible -m debug -a &#8220;var=hostvars[&#8216;hostname&#8217;]&#8221; localhost<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q38-state-the-difference-between-variable-name-and-environment-variables\">Q38) State the difference between Variable name and Environment Variables.<br>   <\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>                 <strong>Variable Name<\/strong><\/td><td>                       <strong>Environment Variables<\/strong><\/td><\/tr><tr><td>It can be built by adding strings.<\/td><td>To access the environment variable, you need to access existing variables.<\/td><\/tr><tr><td>{{ hostvars[inventory_hostname][\u2018ansible_\u2019 + which_interface][\u2018ipv4\u2019][\u2018address\u2019] }}<\/td><td># \u2026 vars: local_home: \u201c{{ lookup(\u2018env\u2019,\u2019HOME\u2019) }}\u201d<\/td><\/tr><tr><td>Allows to add strings<\/td><td>To set environment variables, we need to see the advanced playbooks section.<\/td><\/tr><tr><td>Ipv4 address type use for Variable names we use the ipv4 address.<\/td><td>For Remote environment variables, use {{ ansible_env.SOME_VARIABLE }}<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q39-explain-what-is-ask-vault-pass\">Q39) Explain what is ask_vault_pass?<\/h2>\n\n\n\n<p>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<\/p>\n\n\n\n<p>ask_vault_pass= True<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q40-what-are-ad-hoc-commands\">Q40) What are ad-hoc commands?<\/h2>\n\n\n\n<p>You can think of ad-hoc commands as a way for us to take actions 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q41-explain-ansible-facts\">Q41) Explain Ansible facts<\/h2>\n\n\n\n<p>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 are available to use in the playbook. To generate facts, ansible runs the setup module.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q42-what-makes-ansible-different-from-other-tools\">Q42) What makes ansible different from other tools?<\/h2>\n\n\n\n<p>For automation from the start and scratch, Ansible works better than other tools.<\/p>\n\n\n\n<p>For Configuration Management &#8211; the life cycle, code, and changes can be done by playbooks, roles, and inventory in Ansible.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q43-is-ansible-written-in-python-explain\">Q43) Is Ansible written in Python, explain?<\/h2>\n\n\n\n<p>Yes, Ansible is written in Python and the learning curve is very simple and easy. Ansible follows a simple deployment process such as there is no requirement of daemons, servers, and clients. It manages the nodes through the SSH and operates parallel in use.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q44-differentiate-ansible-and-ansible-galaxy\">Q44) Differentiate Ansible and Ansible Galaxy?<\/h2>\n\n\n\n<p>Ansible Galaxy is the repository for the ansible roles. And the ansible-galaxy command is used that retrieves roles from Ansible Galaxy and installs them. Ansible is the tool that is used for configuration management using inventory and playbooks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q45-which-are-the-os-ansible-can-work-upon\">Q45) Which are the OS Ansible can work upon?<\/h2>\n\n\n\n<p>The Ansible server supports the Unix\/Linux machines and the client machines support the windows Operating Systems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q46-how-to-get-connected-to-an-ansible-server\">Q46) How to get connected to an Ansible server?<\/h2>\n\n\n\n<p>Follow the steps given in the question number 7.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"9\"><li>Run Ansible command on targets? The &#8216;command&#8217; module is used for taking the command name and list of space-delimited arguments.<br>The provided command will get executed on all the modules.<br>To create the command tasks without the space-delimited arguments use the &#8216;args&#8217; or &#8216;cmd&#8217; parameters<br>For windows targets use the \u2018win_command\u2019 module instead.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q47-how-are-ansible-and-jenkin-associated\">Q47) How are Ansible and Jenkin associated?<\/h2>\n\n\n\n<p>Ansible and Jenkin can be integrated using the following steps,<\/p>\n\n\n\n<p>Create a Jenkins Job and configure the SCM repository using the code in GitHub\nThen configure the build\nRoles directory is created in the Jenkins workspace<\/p>\n\n\n\n<p>Create the tomcat role in the Jenkins workspace location with the following command<\/p>\n\n\n\n<p>sudo ansible-galaxy init tomcat &#8211; offline\nAnsible playbook is called after the configuring the Jenkins post-build. Then, call the site.yml file and save the job.\nNext, call the build job and launch the Tomcat URL to check if the application is installed properly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q48-where-are-the-ansible-playbooks-stored-what-language-is-the-playbook-written-in\">Q48. Where are the Ansible playbooks stored? What language is the playbook written in?<\/h2>\n\n\n\n<p>The inventory file is the hosts and group of hosts on which the modules, tasks, commands in a playbook operates. The default location for the inventory file is \/etc\/ansible\/hosts. Playbooks are the file where the Ansible code is written. The Playbooks are written in YAML.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q49-what-is-yaml-and-how-is-used-in-ansible\">Q49. What is YAML and how is used in Ansible?<\/h2>\n\n\n\n<p>YAML stands for Yet Another Markup Language, Ansible uses YAML syntax for coding the Ansible Playbooks. It is English like language and is easy to write, read, and understand than other language formats such as JSON and XML.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"q50-is-there-an-alternative-to-ansible-if-yes-why-and-what-are-they\">Q50. Is there an alternative to Ansible? If yes why and what are they?<\/h2>\n\n\n\n<p>Yes, there are alternatives to Ansible such as Chef and Puppet. They have some additional features such as Node management, orchestration, code management, and visualization. However, each has its pros and cons. Please read the question#3 for the comparison.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"related-video\">Related video:<\/h4>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\"  id=\"_ytid_75910\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/jqqy1rQnNnQ?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  epyt-is-override  no-lazyload\" title=\"YouTube player\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Q1) What is Ansible? Ansible is developed in Python language. It is a software tool. It is useful while deploying any application using ssh without any downtime. Using this tool one can manage and configure software applications very easily. Q2) What are the advantages of using Ansible? The main three advantages of using this tool&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[499,52],"tags":[1729,639,4624,1517,585,1646,1072,3347,7208,325,2239,176,594,341,637,5141],"class_list":["post-26963","post","type-post","status-publish","format-standard","hentry","category-python-programming-scripting-languages","category-interview-questions-answers","tag-advantages","tag-ansible","tag-ci-cd","tag-configuration-management","tag-development","tag-documentation","tag-environment","tag-interview-questions-answers","tag-interview-questions-and-answers","tag-language","tag-machine","tag-python","tag-tomcat","tag-tool","tag-top","tag-tower"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/26963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=26963"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/26963\/revisions"}],"predecessor-version":[{"id":27124,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/26963\/revisions\/27124"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=26963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=26963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=26963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}