How Do You Instantiate a class in Python?

Problem scenario
You inherited code from a different programmer. You want to test out an object. How do you create an object of a pre-made class?

Solution
Look at how many variables the class has. Take this code for example:

class Cartesian(object):
    def __init__(self,a = 0,b = 0):
        self.a = a
        self.b = b

    def distance(self):
        return (self.a**2 + self.b**2) ** 0.5 # Pythagorean theorem.

You find variables "a" and "b". So you should use two arguments when you create the object. Here is a line of code that should appear in the same program beneath the class definition:

contint = Cartesian(4, 1)

To test it out, place this line of code at the bottom:

print(contint.distance())

This program may show how it all works more clearly:

class Cartesian(object):
    def __init__(self,x = 0,y = 0):
        self.x = y
        self.y = x

    def distance(self):
        return (self.x - self.y)

contint = Cartesian(4, 1)

print(contint.distance())

How Do You Troubleshoot the Error “rsync mkdir failed… rsync error in rsync protocol data stream (code 12)”?

Problem scenario
You try to use rsync or you use Ansible's synchronize module.  It fails with this message: "rsync mkdir failed... rsync error in rsync protocol data stream (code 12)"

Solution
Is the destination directory writable?  Verify that the destination exists and has the correct permissions for being able to write to it with the user the Ansible playbook uses.

How Do You Address a Problem Message about a Directory Being Read-only when It Is Not Read-only?

Problem scenarios
One or both of the following applies to your situation:

#1  In Linux you try to move a directory that is not read only (e.g., its permissions are rwxrwxrwx or 777).  You get an error about it being read-only.  Your user is the owner of the directory.  

OR

#2  You are running an Ansible playbook and trying to change the attributes of the file.  You get a failure message like this: "Err no 30: read-only" when you run the playbook.

What should you do?

Possible Solution #1
With shared directories you can get an error about it being read-only when it is not read-only.  Try to copy the directory and its contents to a different location (e.g., cp -R /path/of/source /path/to/destination).  Delete or remove the problem directory.  Now use the backed up directory in the new location for whatever purposes you need.

Possible Solution #2
Stop sharing of the directory momentarily.  Then you may be able to perform the operation.

Possible Solution #3
Reboot the server that appeared to be the cause of the problem.  Perhaps there is a corruption issue or the apparent permissions need to be updated.  Rebooting may fix the problem or help you diagnose the problem.

How Do You Solve an Ansible Problem about an SSL Certificate Error?

Problem scenario
You run an Ansible playbook.  You receive an error about the SSL certificate not being valid.  What should you do to get the playbook to transfer a file from a website using SSL or TLS to a managed node?

Possible Solution #1
If the problem pertains to retrieving a file from a website URL, this may apply. If the problem is between the managed node and the website and not between the control node and the website, use the get_url module to download the file to the Ansible control server.  It can be easy to get one server (the control node) to have the SSL certificate. To learn how to bypass the managed node for bringing down the file from the website to the client (e.g., in situations where the control node has the SSL certificate), this posting has explicit directions for using the get_url module.
Once the file is brought down to the control node, the playbook could then use the copy module to transfer the file to the managed node.  There is an intermediate copy step, but this can save time if you have many managed nodes that need a big file.

Possible Solution #2
Modify the playbook and use "validate_certs: false" with the get_url module (underneath it and indented).

Possible Solution #3
Update the certificate on the managed node.

What Should You Do When Linux Is Not Finding Your USB Camera?

Problem scenario
In Linux in the /dev/ directory you looked for the camera.  In /dev/ and could not find a file associated with your web camera.  You verified the locally attached camera is connected via a USB cable to your physical computer.  

When you try to use it, you see this message:

"--- Opening /dev/video0...
stat: No such file or directory"

What should you do?

Solution
1.  Verify the camera is turned on.  It the camera is turned off, you may not see it.
2.  Verify the camera works on another computer.  If it does, try a different USB port on the Linux computer with the problem.  If it does not, the camera may need to be replaced.


See also How Do You Troubleshoot a Computer Camera That Is Not Rendering Images?

How Do You Get a Jira Instance to Work when The Web UI is Not Working but The Listener is Active on The TCP/IP port?

Problem scenario
A Jira deployment is failing.  The web services are listening on port 8080 or whichever port you configured.  But the web UI does not load.  What should you do?

Solution
Root cause: "...JIRA is not designed to import data from a new version into an older version." taken from Atlassian's website.

Has the database been used in the past?  If you downgraded your Jira instance, the database needs to be empty or restored from a backup.  Once Jira has been upgraded and connected to a SQL database, that database will not work for older versions of Jira.

How Do You Troubleshoot “postgresql.Driver Connection error: org.postgresql.util.PSQLException Fatal: Ident authentication failed for user”?

Problem scenario
You are trying to connect to a PostgreSQL database.  Your database username and password are not working, but you think they should.  You get the message:  "postgresql.Driver Connection error: org.postgresql.util.PSQLException Fatal: Ident authentication failed for user"

What should you do?

Possible solution #1
Make sure the pg_hba.conf file is configured correctly.

Here is an example if you are trying to connect from your local machine and you do not need your Postgres instance extremely hardened:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

Possible solution #2
If you want to be very proactive, try dropping the database and dropping the role.  Then recreate both.  This way you ensure you have the correct username (aka role) and password. 

To get to a SQL prompt, you may want to try to run these two commands:
sudo su postgres
pgsql

Then run these four SQL statements:
drop database foobar;
drop user jdoe;
create user jdoe with password 'goodpassword';
create database foobar with OWNER=jdoe;

How Do You Troubleshoot “Failed to start sonar.service: Unit not found” Error?

Problem scenario
You run "sudo systemctl start sonar", but you get this message: "Failed to start sonar.service: Unit not found"

What should you do?

Solution
Run this: sudo systemctl enable sonar

Now you should be able to run your command to start the "sonar" service.

How Do You Troubleshoot the GitLab Integration Webhook Error “No valid crumb was included in the request”?

Problem scenario
You are trying to configure GitLab to work with Jenkins (so the two are integrated to enable CI, continual integration, in your environment).  When you test a connection of an integration webhook from GitLab to reach out to Jenkins you receive this error:

"Hook executed successfully but returned HTTP 403... No valid crumb was included in the request."

What should you do?

Solution
Possible solution #1
Warning: This is not a recommended practice.  This solution will make your Jenkins system less secure.  

Log into Jenkins and go to Manage Jenkins -> Configure Global Security -> CSRF Protection.  Uncheck the option for "Prevent Cross Site Request Forgery exploits".  Click "Save".

Possible solution #2
Use the "Build Authorization Token Root Plugin" for Jenkins.  If you need directions for installing it and configuring it, see this posting (How do you troubleshoot the GitLab integration webhook error "Permission...)