How Do You Troubleshoot an Ansible Playbook That Has No Visible Errors when It Runs?

Updated 8/1/21

Problem scenario
An Ansible playbook appears to run with no errors or explicit failures.  But the playbook is not working as you expect.  There is no message indicating what could be wrong.  What should you do to troubleshoot it so the intended effect(s) will happen? 

Tips and Possible Solutions in Nearly Random Order
1.  When you run the ansible-playbook command,

How Do You Use Testinfra (the Python module)?

Problem scenario
You prefer Python to Ruby for certain tasks, and you want to have a way of testing your configuration management tools. You want to use Testinfra to accomplish this (https://testinfra.readthedocs.io/en/latest/). You want to install Testinfra to test it out. What do you do?

Solution
Prerequisites
i. You must have pip3 installed on the server.
For Ubuntu/Debian systems,

How Do You Use the Python self Keyword?

Problem scenario
You have seen Python functions defined using the self keyword. You want to test it out. How do you do this?

Solution
First of all, self is NOT a keyword in Python. Yes, you should probably use the word “self” when it is invoked. This is a well-accepted convention. It may be an unwritten rule. But you do not need to use the word “self”.

How Do You Set up Nginx as an HTTP Load Balancer So Client Requests (from Web Browsers) Do Not Go to Certain Nginx Servers unless Others Are Down?

Problem scenario
You have a web server running Nginx that acts as a reverse proxy server.  On occasion your regular web (Nginx) servers go down.  You want to have one or two web (Nginx) servers that are  reserved as backups exclusively.  You do not want traffic going to these servers unless the main Nginx servers are unavailable (either due to network or server failure).  You can allocate RAM and CPU to these reserved servers on demand. 

In Linux without the Internet, How Do You Enter Left Double Quotes (“) or Right Double Quotes (”)?

Problem scenario
You are trying to search a file for left double quotes and right double quotes (e.g., using a Linux command terminal or a vi editor). How do you enter left double quotes or right double quotes using a keyboard (without copying the apparently italicized double quotes from a web page)?

Solution
Hold Alt, and then enter the sequence 8220 for left double quotes.

How Do You Write a Python Program to Test if a Word is a Substring of Another Word?

Problem scenario
You want to write a program that will test if a pattern is in another word. You are looking for the SQL equivalent of “contains” in Python. How do you test if a string is a substring of another word?

Solution
Use this program:

# Change “micro” and “microsoft” to the substring and string to be searched respectively:

a = “micro”
b = “microsoft”
if a in b:
print(a + ” is in ” + b)
else:
print(a + ” is NOT in ” + b) …

How Do You Find the URL of Your Kubernetes Cluster?

Problem scenario
You want to view the website that is powered by Kubernetes. But you do not know which URL to go to. What should you do from the back-end server with kubectl?

Solution

1. Run this: kubectl get services
With the resulting output, find a name that you want the URL for. (Services have names.) Let’s assume the name was “foobar”.

How Do You Troubleshoot the Error “Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock”?

Problem scenario
You try to run a Docker command, but you get this error: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.29/containers/json?all=1: dial unix /var/run/docker.sock: connect: permission denied

What should you do?

Solution
Have you added the user who was trying to execute the command to the “docker” group?

This command would add the user jdoe to the “docker” group:
sudo usermod -aG docker jdoe

If you ran the above command as the jdoe user,

How Do You Get a PHP Script to Invoke a Bash Command?

Problem scenario
You are trying to get a PHP file to invoke a bash script. When you run it from the command line with “php foobar.php” you just see the content of the PHP file. What do you do to get PHP to invoke a bash script?

Solution
Make sure you have the correct header and closing symbols. Here is the content of foobar.php:

<?php
exec(‘bash /var/www/html/testScript.sh’); …