How Do You Troubleshoot the Ansible Error “Only one –vault-id can be used for encryption.”?

Problem scenario
You try to run ansible-vault, but you get this error:
"ERROR! Only one --vault-id can be used for encryption.  This includes passwords from configuration and cli."  You want a fast solution, and you have complete control of the Ansible server. You do not need to use encryption or decryption for your Ansible operation(s).  What should you do?

Solution
Modify the ansible.cfg file. Comment out a stanza like this:

# vault_password_file = ~/.vault_pass.txt

If there is no leading pound "#" mark, add one to comment it out

How Do You Install pip or pip3?

Problem scenario
You think you installed pip (e.g., using this posting for Debian/Ubuntu, using this posting with Linux SUSE, using this posting for a CentOS/RHEL/Fedora server, or this posting as an alternative), but when you run pip, you get "command not found."  How do you install pip and get it working?

Solution
pip or pip3 may actually be installed despite the fact that things may seem otherwise. The path to it (pip or pip3) may not be in your environment (e.g., env) variables.  Run these commands:

sudo find / -name pip
sudo find / -name pip3

Use the full directory path and the pip file when calling the pip command.  For example, use one of the following as a command:

/usr/bin/subdirectory/version/pip
/usr/bin/subdirectory/version/pip3

How Do You Use Azure Functions?

Problem scenario
You want a REST API program to write to logs in a serverless way.  You want to have a program (or some very basic lines of code to) execute upon certain events happening (e.g., to write intelligent pre-processed logs and potentially gather data from multiple sources).  You want to use an Azure PaaS for this.  How do you use Azure functions?

Solution
1.  Log into Azure.
2.  Click "Create a resource" in the upper-right hand corner.
3.  Click "Serverless Function App"
4.  For the "App name" enter something unique (e.g., adkeui37672hd73hx)
5.  For "Runtime Stack" select "JavaScript".
6.  Adjust other settings as needed.  Click "Create" near the bottom.
7.  Processing will occur.  There will be a laser-like horizontal bar that will scroll near the top of the Azure Portal GUI.  When this bar disappears, the "Function" has been created. 
8.  Click "Function Apps" (either on the left or in the middle of the screen).  (Or go here: https://portal.azure.com/#blade/WebsitesExtension/FunctionsIFrameBladeMain )
9.  On the left you should see the unique name you gave it.  Find the name you entered and click on it [to expand it].
10.  Underneath that should be an icon and the word "Functions". 
11.  Expand Functions and click on plus sign.
12.  Click the "In-portal" option in the middle of the screen.
13.  Click "Continue"
14.  Click "Webhook + API" and then click "Create"
15.  Click "</> Get function URL "
16.  The pop-up window should have a section called "URL".  Copy that URL text (e.g., by clicking the hyperlinked, blue "Copy text" on the right of the pop-up window).
17.a.  Draft a URL by pasting the copied text into a text editor.
17.b.  Append "&name=MikeSmith" to the text. 
17.c.  Replace "Mike Smith" with your name. 
17.d.  This text is the draft or "composed URL".

It will look something like this:
https://mkwjeu1857234.azurewebsites.net/api/HttpTrigger1?code=v3dkeE651Kh29xmnwbRE/N4c6ej393MBN==&name=Hello Mike Smith

18.  Open a new web browser and go to this composed URL.  You should see something like "Hello Mike Smith"

19.  You are done.  To learn about the details (e.g., pricing) see this link.

How Do You Troubleshoot the Sonar-Scanner Problem “java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.ProjectLock”?

Problem scenario
You run sonar-scanner from the command line.  You receive an error such as this:  "Error during SonarQube Scanner execution ... java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.ProjectLock at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java.64"

What should you do?

Possible solution #1
Is the sonar-project.properties file in the directory from which you ran sonar-scanner?  This command expects this file to be in that directory.

Possible solution #2
Does the user that ran sonar-scanner have permissions to read sonar-project.properties?  This file needs to be readable.  You may need to use sudo before the sonar-scanner command or log in as a different user.

Possible solution #3
Does the sonar-project.properties file have a sonar.sources stanza?  If so is there a subdirectory that is at the same level as sonar-project.properties with the name assigned by the sonar.sources stanza?

If you see "sonar.sources=foobar", you would need a subdirectory named "foobar" in the directory with the sonar-project.properties file?

How Do You Use tar to Create a Single File That Is a Copy of a Subdirectory and All of Its Files and Subdirectories?

Problem scenario
You want to recursively copy subdirectories from on Linux machine to another.  How do you copy them into one file with the directory structure for the purpose of transferring it later?

Solution
On the source server go to the parent directory that you want to compress into one file.  Run this tar command:

tar cvfz target.tgz subdirsource/

Now target.tgz will have all the directories of  subdirsource.

# If you want to uncompress target.tgz, run this command from a directory where you can write to (e.g., have permissions to create subdirectories):

tar zxvf target.tgz

How Do You Get ansible-vault to Prompt You for a Password to Encrypt a File That You Create?

Problem scenario
You are using the ansible-vault command.  You are not being prompted for a password as the documentation suggests you would be.  You want to use ansible-vault create or ansible-vault edit and be prompted for a password. How can you specify a password manually?  How can someone on a different Ansible server decrypt your encrypted files?  

Possible solution #1
Modify the ansible.cfg file. Comment out a stanza like this:

# vault_password_file = ~/.vault_pass.txt

If there is no leading pound "#" mark, add one to comment it out.

Possible solution #2
Upgrade or downgrade Ansible from 2.4.  There is a documented bug about this.

Possible solution #3
When you run ansible-vault, use this flag: --ask-vault-pass

Here is an example:  ansible-vault create contint.yml --ask-vault-pass

What Should You Do It You See Duplicate Plugins in Jenkins List of “Available” Plugins?

Problem scenario
You log into Jenkins.  You go to Manage Jenkins -> Manage Plugins -> Available.   You see the same plugin listed twice (e.g, under different categories such as "Build Reports" or "External Site/Tool Integrations").  What should you do?

Solution
This is a workaround: look at the version of the plugins.  Are there duplicates the same version?  If the versions are the same, ignore one duplicate as we do not think it will cause a problem.  For convenience Jenkins displays plugins in different categories if the plugin is a member of two categories.

What Is the Python Requests Syntax Equivalent of a curl “-X DELETE”?

Problem scenario
You are invoking requests.get() in a Python program (after an "import requests" statement near the top of your code).  You want to pass the equivalent of "-X DELETE" in curl in your Python program.  How do you use the DELETE option with a REST API call in Python?

Solution
Prerequisites

This assumes you have "requests" installed (e.g., sudo pip install requests).  If you need assistance installing pip, see this link for Debian/Ubuntu, this link for a Linux SUSE server, and this link for CentOS/RHEL/Fedora.

Procedure
Use requests.delete() in your code.  This external page http://docs.python-requests.org/en/master/user/quickstart/ used to have more information.

How Do You Troubleshoot the SonarQube Problem “Service unavailable” in the Web UI?

Problem scenarios
Your situation is described in one of two ways.

#1  You go to the SonarQube web UI to log in.  You see nowhere to log in.  You see this error: "Service Unavailable    The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later."  What should you do?

Or your situation is like this:

#2  You have installed SonarQube and Apache web server.  You go to the SonarQube website and the error message in the web browser is "Service Unavailable."  You see some listening activity from the back-end.  The Sonar service is active.  

In the /var/log/httpd/ directory (the path may vary depending on how your web service is configured), the error log has entries like these:
"Connection refused: AH00957: HTTP: attempt to connect to...failed"

Why cannot you log into the web UI?  Why does the web UI logon page not load correctly?

Solution
Possible Solution #1

1.  Go to the back-end (the command prompt of the Linux server). 
2.  Go to the sonarqube directory (e.g., with conf, logs, and other subdirectories).  
3.  Go to logs.  Look at web.log.  
4.  Is the sonar.properties file in the conf subdirectory configured properly?  An incorrect password for the underlying SQL database could cause this problem.

Possible Solution #2
1.  Find the sonar*.conf file.  Use this command: sudo find / -name sonar*.conf
2.  See how it refers to the server (e.g., with localhost, the hostname, the internal IP address, the loopback IP address, the external IP address).  Is the reference to the server the same as the sonar.properties file for the sonar.web.host stanza?  This stanza should be consistent with the httpd.conf or apache2.conf file.
3.  To find the file you could run this command: sudo find / -name sonar.properties
4.  Then you could run this command: cat <resultFromPreviousCommand> | grep -i sonar.web.host
5.  Change the sonar.properties file so it uses the same reference to the server that the sonar*.conf file.

Possible Solution #3 (applicable if you use Apache web server with SonarQube)
1.  A server reboot may be an option.  If you do not do this, continue to step 2.  If you do reboot the server, skip to step 3.
2.  Start and stop the SonarQube service.

You may or may not do it with these two commands:
sudo systemctl sonar stop
sudo systemctl sonar start

Start and stop the Apache web server service.  You may or may not do it with these two commands:

sudo systemctl httpd stop
sudo systemctl httpd start

3.  Look at the /opt/sonarqube/temp/ directory.  Does the subdirectory "conf" have an owner root and group root?  If so, this is generally a sign of a problem.

If the "Service unavailable" problem persists look at your  /etc/systemd/system/sonar.service file.  Does it have these two stanzas?

User=root
Group=root

The "root" for user should be changed to the user who is the owner of the /opt/sonarqube directory.  The "root" for group should be changed to one of the groups for the user who is the owner of the /opt/sonarqube/ directory.  To find out the groups for that user, log in as that user.  Run the command "groups" to display those groups.  If you need to change the owner and groups of the /opt/sonarqube directory (and subdirectories and files), run this command:

sudo chown -R sonar:sonargroup # but change sonar and sonargroup as needed.

(Remember that just because you change it once does not mean that the .../temp/conf directory will retain those changes.  Cycling the Sonar services will change the ownership based on the sonar.service file's settings.)

4.  After you change the sonar.service file, run this command:  sudo system daemon-reload

Then restart the sonar and web services (as described in the above step 2).  You should be able to get to the web UI of SonarQube.  If you need to redeploy SonarQube, see this posting.

How Do You Troubleshoot PHP Not Displaying the Output of a Bash Command?

Problem scenario
You have a PHP program that works from the back-end (from a command terminal executing like php foobar.php). When you view the program in a web browser, it is not running the Bash commands properly. What should you do?

Solution
The root cause is probably the user execution context and a variety of permissions or configuration settings on the Linux system.

If the output of the Bash command is multiple lines, you may be capturing only the last line and sending that to a variable in PHP. If the last line was empty, you may see just white.

The user account that invokes the PHP program when it is executed via someone browsing to it on a web page is different from your back-end user account. This may be what is wrong. Here is one important diagnostic for you. Create a file called good.php and place it where a user can browse to it (e.g., /var/www/html/).

<?php
    $output = shell_exec('/usr/bin/env | /usr/bin/xargs');
    echo $output;
?>

<html>
<body>

HELLO!

</body>
</html>

When you go to the above web page in a web browser, you will get an idea of what issues your PHP program is running into when it is executed from someone browsing to it. (The apache or nginx users may be executing the PHP program; these users may not have sufficient back-end permissions on the Linux system.) You may need to change the location of the "env" executable in the program above; you could use which env to find the appropriate location. Here is another tip if Linux commands are not processing properly from a PHP program: the /tmp/ directory has the sticky bit set. So you should choose a different directory to write to. You may want to run sudo ls -lhd /foobar (where "foobar" is the destination directory where the bash script is supposed to write to).