Table of contents
1.
Introduction
2.
Troubleshooting
2.1.
Register and Debug
2.2.
Make Use of Verbosity
3.
Important Points
3.1.
Solution
4.
 Common Playbook Issues
5.
Frequently Asked Questions
5.1.
Is Ansible a programming language?
5.2.
What is Ansible used for?
5.3.
What tool is Ansible?
5.4.
Is Ansible based on Python?
5.5.
What is the Ansible playbook?
6.
Conclusion
Last Updated: Mar 27, 2024
Easy

Troubleshooting in Ansible

Author soham Medewar
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Ansible Automation Platform is an enterprise framework for developing and running IT automation at scale, from fused cloud to the edge. Ansible Automation Platform allows users from development and operations to security and network teams to create, share, and manage automation.

ansible

IT administrators can give recommendations for how automation should be applied to individual teams, while automation designers can write activities that make use of pre-existing information. Ansible Automation Platform provides a more secure and stable base for end-to-end automation deployment.

Troubleshooting

troubleshooting

When you begin writing and testing more complicated playbooks, you will require certain troubleshooting techniques. Examples include:

  • Examining the Ansible task flow.
  • Confirming your variables' data types.
  • Even pausing at a certain point to verify their values.

The modules listed below are the most often used strategies for debugging Ansible playbooks.

Register and Debug

These are the modules that are accessible in Ansible. We must utilize the two modules with caution when troubleshooting. An example is provided below.

Make Use of Verbosity

The verbosity level can be specified using the Ansible command. The commands can be executed with verbosity levels one (-v) or two (-v) (-vv).

Important Points

important

In this section, we will look at some instances to help us comprehend some concepts.

If you are not citing a variable-starting argument. As an example,

vars: 
  age_path: {{soham.name}}/demo/ 
{{soham.name}} 


This will result in an error.

Solution

vars: 
  age_path: "{{soham.name}}/demo/" - marked in yellow is fix. 
 
Using Register -> Copy the code into a yml file, say test.yml, and run it  
--- 
#Testing 
- hosts: tomcat-node 
  tasks: 
 
  - shell: /usr/bin/uptime 
      register: myvar 
      - name: Just debugging usage 
        debug: var = myvar 


When you run this code with the command Ansible-playbook -i hosts test.yml, I receive the following result.

If you look at the yaml, you will notice that we have registered the output of a command into a variable - myvar - and then just printed the output.

The yellow text describes a characteristic of the variable -myvar that can be utilized for additional flow control. This way, we can learn about the properties of a specific variable that are revealed. The following debug command can assist.

$ ansible-playbook -i hosts test.yml
PLAY [tomcat-node] ***************************************************************
**************** ****************************************************************
*************** ****************************** 

TASK [Gathering Facts] *****************************************************************
************** *****************************************************************
************** ************************** 
Saturday 27 August 2022  23:26:08 +0530 (0:00:00.051) 0:00:00.051 ******* 
ok: [server1] 

TASK [command] ******************************************************************
************* ******************************************************************
************* ********************************** 
Saturday 27 August 2022  23:26:10 +0530 (0:00:01.697) 0:00:01.748 ******* 
changed: [server1] 

TASK [Just debugging usage] ******************************************************************
************* ******************************************************************
************* ********************* 
Saturday 27 August 2022  23:26:10 +0530 (0:00:00.226) 0:00:01.974 ******* 
ok: [server1] => { 
 "myvar": { 
     "changed": true, 
     "cmd": "/usr/bin/uptime", 
     "delta": "0:00:00.011306", 
     "end": "2022-08-27 23:26:10.424647", 
     "rc": 0, 
     "start": "2022-08-27 23:26:10.413341", 
     "stderr": "", 
     "stderr_lines": [], 
     "stdout": " 23:26:10 up 7 days, 35 min,  1 user,  load average: 0.18, 0.15, 0.14", 
     "stdout_lines": [ 
       " 23:26:10 up 7 days, 35 min,  1 user,  load average: 0.18, 0.15, 0.14" 
     ] 
 } 
} 

PLAY RECAP ****************************************************************************
**********************************************************************************
************************************** 
server1 : ok = 3    changed = 1    unreachable = 0    failed = 0 

 Common Playbook Issues

In this part, we'll go over a few frequent playbook concerns. The problems are:

  • Quoting 
  • Indentation 

Playbook is written in yaml, and the two faults mentioned above are the most common in yaml/playbook.

Yaml does not support tab-based indentation but does support space-based indentation, so be cautious.

Frequently Asked Questions

Is Ansible a programming language?

Ansible is a configuration management system built in Python that employs a declarative markup language to describe configurations.

What is Ansible used for?

Ansible can be used to provision your environment's underlying infrastructure, network devices, virtualized hosts, bare metal servers, and hypervisors. It can also install services, add compute hosts, and provision cloud resources, services, and applications.

What tool is Ansible?

Ansible® is a free and open-source IT automation software that automates configuration management, application deployment, provisioning, orchestration, and a variety of other manual IT tasks.

Is Ansible based on Python?

Ansible is developed in Python and has a relatively short learning curve. Ansible is a straightforward installation process and does not require any additional software, servers, or client daemons. It maintains nodes over SSH by default and is parallel.

What is the Ansible playbook?

Ansible Playbooks are a set of tasks that are executed automatically against hosts. Your Ansible inventory is made up of host groups. Each module in an Ansible Playbook is in charge of a specific task. Each module has metadata indicating when and where a task is completed, as well as which user completes it.

Conclusion

In this article, we have discussed troubleshooting. Also, we have discussed the modules that can be used to troubleshoot problems in Ansible Framework.

If you want to learn more, check out our articles on Ansible Interview Questions1Ansible Interview Question2, and Ansible Interview Questions3.

Happy Coding!

Live masterclass