How Do You Access the SonarQube Web UI When It Is Only Listening on the 127.0.0.1 IP Address?

Problem scenario
SonarQube is listening on the loopback IP address on port 9000.  SonarQube is not listening on the external IP address.   You want to access the web UI for SonarQube. What should you do?

Solution
Install a web server and configure it to connect to port 9000.  Here are the details for using Apache web server on a Red Hat derivative (e.g., CentOS/RHEL/Fedora).

1.  Run this command:  sudo yum -y install httpd

2.a  Run this command, but replace x.x.x.x with the external IP address of your server (or the URL that you will present with this server):  

sudo vi /etc/httpd/conf.d/sonar.x.x.x.x.conf

2.b.  Place these lines in the file (where the top and bottom lines have "VirtualHost" in them):

<VirtualHost *:80>
    ServerName sonar.x.x.x.x
    ServerAdmin admin@continualintegration.com
    ProxyPreserveHost On
    ProxyPass / http://localhost:9000/
    ProxyPassReverse / http://localhost:9000/
    TransferLog /var/log/httpd/sonar.x.x.x.x_access.log
    ErrorLog /var/log/httpd/sonar.x.x.x.x_error.log
</VirtualHost>

2.c.  Replace x.x.x.x with the IP address or domain name of your server.

2.d.  Replace "admin@continualintegration.com" with an email address of yours.

3.  Run these two commands:

sudo systemctl start httpd
sudo systemctl enable httpd

How Do You Create a .ppk File from a .pem File?

Problem Scenario
You want to use a key kair to log into AWS instances. You created an AWS EC-2 instance (aka a virtual machine or server) running Linux.  You want to connect to this Linux server (a VM).  You created a key pair when you created this VM.  You downloaded the .pem file.  You need a .ppk file to log in.  What should you do?

Solution
1.  Download a puttygen.exe file from this location. (If you have a 32 bit version of Windows, use this link.  If you have a 64 bit version of Windows, use this file.)

2.  Open puttygen.exe (as nothing needs to be installed).

3.  In PuTTY Key Generator, go to File -> Load Private Key.  Find the .pem file that you have.

4.  You should get a "PuTTYgen Notice."  Click "OK" to that.

5.  Enter a Key Passphrase in the field for "Key passphrase". Remember this password and click "Confirm passphrase".

6.  Click "Save Private Key."  Give it a name that you want.  

7.  Open the regular putty.exe.  Expand Connection -> SSH -> Auth.  Near the text field for "Private key file for authentication" field, click the "Browse" button.  Open the .ppk file you just created (in step #6 above).

8.  In Putty go to the "Session" field.  Then click on "Host Name."  Enter the IP address of the EC2 instance you just created.  Click "Open."

9.  The username will be ec2-user if the server is running RHEL or SUSE.  If the server is running Ubuntu, the username will be ubuntu.  The password will be the one you entered in the step that created the .ppk file.

How Do You Troubleshoot “permission denied” when Trying to Clone a Git Repository That You Should Have Access to?

Problem scenario
You configured the source repository (in GitHub, GitLab, in BitBucket or elsewhere) to allow your user to have permissions to read the repository.  You run git clone but you get a "permission denied" error.  What should you do?  

Possible solutions
The Linux server you are on may not give your Linux user permissions to write to the destination directory.  Can you clone the repository to the /tmp/ directory?  This should help you isolate the problem if it works.  See if other users can clone the repository to other servers.  Does the repository path (e.g., ssh:// or http://) have problems in it?  Could a character or two be incorrect and happen to match another repository accidentally?

What Do You Do when an Ansible Playbook Is Not Removing a File or Directory or Unmounting a Directory when There Are No Errors?

Problem scenario
You run a playbook, and there are no errors.  But the playbook's simple logic is not working.  The file or directory is not being eliminated.  Or the unmount of the directory is not working via the mount module.  What should you do about a silently failing playbook?

Solution
1.  Verify there are no [trailing] spaces in the directory path.  If you accidentally quote a space after the last subdirectory or file, the playbook may not work but there may be no errors alerting you that it did not work.

2.  Verify the path in the playbook, i.e., that of a variable, is what you think it is.  Try to "echo" the value to a /tmp/ file to verify it is being computed and substituted consistent with what you expect.  You will have to run the playbook once purely for diagnostic purposes.

3.  Verify the playbook does not later recreate the file or mount the file/directory near the end of the playbook.  It may be that it does what you want, but near the end it independently reverts some of the deletion or unmounting.

4.  The Ansible modules are preferred to the shell commands.  If the error is difficult to troubleshoot, try the shell commands in addition to the Ansible modules.  The "ignore_errors: yes" is an attribute that can help out if the shell commands are prone to errors.  

5.  Verify the key part of the Ansible playbook is not commented out.  Maybe you need to uncomment a relevant stanza or variable assignment.

6.  It could be the root cause is purely for a Linux-related reason (if the managed node is Linux).  If you are using the mount module check the /etc/fstab or /etc/exports.  These files could be configured in a conflicting way with the playbook's operation such that there is no error, but your playbook is not doing what you want.  We do think that if the destination directory of the mount module does not work, Ansible ought to throw an error.  At the time of writing, we believe most (or all) Ansible versions will not throw an error.

7. Look at the relevant logs. See this posting if you need assistance.

8. For a guide to troubleshooting a generic Ansible playbook with no errors that is not working correctly, see this posting.

Why Is a GitLab Webhook That Integrates with Jenkins Failing with a “500 …instance_identity.InstanceIdentity.get …” error?

Problem scenario
A GitLab webhook (aka integration) fails.  It used to work as an integration mechanism with Jenkins.  The GitLab error message says:

"500 <!DOCTYPE html> ... at org.jenkinsci.main.modules.instance_identity.InstanceIdentity.get(InstanceIdentity.java:133)"

Solution
Go to the Jenkins server and reinstall the GitLab plugins.

How Do You Troubleshoot the Ansible Playbook Error “fatal: FAILED! => {“msg”: “The conditional check “?

Problem scenario
You run an Ansible playbook that uses a variable, but you get the message "fatal: FAILED! => {"msg": "The conditional check ...The error was: error while evaluating conditional (ansible_hostname == ):".  What should you do?

Solution
When testing a variable's value to another fixed string, put quotes around the string.  

Here is an incorrect example of a playbook using such a comparison:

      when: ansible_hostname == contintserver

Here is a correct example of an Ansible playbook using a string comparison:

      when: ansible_hostname == "contintserver"

To see more correct syntax and context, see this playbook:

- name: This is a test.
  hosts: contintserver
  tasks:
    - shell:  "free -m > /tmp/memory.txt"
- name: Second section.
  hosts: contintserver
  tasks:
    - shell: "echo  > /tmp/date.txt"
      when: ansible_hostname == "contintserver"

How Do You Use a Dictionary in Python?

Problem scenario
You want to use a dictionary in Python, but you do not know how. What should you do?

Solution
1.  For a very simple dictionary, you could use "{}" with no quotes.  This makes var1 a dictionary in Python:

var1 = {}

Normally with no colons, two matching curly braces would signify a set.  (You can find out more about this Python syntax here.)

2.  To really learn about dictionaries, create a file called test.py with the following content:

# The two lines below show how to create two dictionaries
dict1 = { 1:'Mark Zuckerberg', 2:'Sheryl Sandberg'}
dict2 = { 2:'Sheryl Sandberg', 1:'Mark Zuckerberg'}

# This if clause demonstrates testing the equivalence of the two dictionaries
if dict1 == dict2:
  print 'The contents of the dictionaries are identical!'
else:
  print 'The contents of the dictionaries are dissimilar.'

# This line demonstrates adding a key-value pair to a dictionary
dict1['Peter Thiel'] = 3
# This proves that dictionaries are mutable.
print dict1

3.  Run the program test.py (using python test.py) to see how Python dictionaries work.

How Do You Troubleshoot the Git Error Fatal Foobar.Git Does Not Appear to Be a Git Repository?

Problem scenario
You run a git command and you get an error like this:

"fatal: 'root/contint.git' does not appear to be a git repository
fatal: Could not read from remote repository."

The git command works on the server with the git repository.  But from another server you get the error above.  What should you do?

Solution
Find the full path to the git repo file.  Let's assume that you are using "git clone" and the full path is /var/opt/gitlab/git-data/repositories/root/.  From remote servers, you would run a command such as this:

git clone git@x.x.x.x:/var/opt/gitlab/git-data/repositories/root/contint.git

How Do You Use Amazon DynamoDB?

Problem scenario
You want to use a NoSQL solution from a public cloud provider. How do you deploy Amazon DynamoDB to try it out?

Solution
1.  Log into AWS.
2.  In the web browser, go to https://console.aws.amazon.com/dynamodb/home
3.  Click "Create table"
4.  Enter the fields as you find appropriate.  It should be self-explanatory.  Click "Create".
5.  You can now create items in the table, create new tables or create a cluster (e.g., the Amazon DynamoDB Accelerator called DAX which includes an in-memory cache service).

How Do You Troubleshoot SonarQube Not Working when the Logs Have a Comment about Not Being Able to Connect to the Database?

Problem scenario
In the SonarQube logs you get an error "java.lang.IllegalStateException: Can not connect to database.  Please check connectivity and settings (see the properties prefixed by 'sonar.jdbc')"

How do you troubleshoot this error?

Solution
1.  Verify you can ping the hostname.  

2.  Test the port with nmap (e.g., "nmap -p 1521 <databaseFQDN>" where <databaseFQDN> is the hostname of the database and 1521 is the port you configured in the stanza with "sonar.jdbc").  An intermediate firewall blocking connectivity over a specific port could cause problem.

3.  If the database is an Oracle database, test the credentials you were given.  If you do not know, see this posting.  Did you include a SID in the connection string?