How Do You Eliminate the “Namespace”, Quotes and Brackets from the Variable You Are Printing with Python?

Problem scenario
You are trying to print a variable, but it prints out like this:

Namespace(string=['foobar'])

How do you print out just "foobar" with no quotes?

Solution

Overview
The key word here is "string".  The "string" text in this is the attribute you will want.

Background
Your program may have something like this:

args = parser.parse.args()     # Assuming this is the variable assignment of "foobar"
print (args)     

 Procedures
1.  Eliminate the "print(args)" line.

2.  Insert these lines into your code:

var1 = args.string  # this retrieves the string attribute per the "string" that was printed out
newvar = var1[0]    # This retrieves the content of the item without the quotes and brackets.
print (newvar) 

How Do You Troubleshoot the Artifactory REST API Error of a Hanging Command?

Problem scenario
You issue a call to an Artifactory URL.  You see something like this: "TCP_NODELAY set".  There is a delay, and nothing happens.  What should you do?

Solution
Does the URL have a port number in it?  The socket may be incorrect depending on what port number you use.  If you can go to the back-end of the Artifactory and install nmap, run this command to find what port Artifactory listens on:

nmap -Pn x.x.x.x  # replace x.x.x.x with the external IP address of the Artifactory server

Make sure the URL you use has the correct port number for Artifactory.

If you need assistance installing and configuring Artifactory for the first time, see this posting.

How Do You Install a Yum Package from a Reachable yet Unconfigured Repository on an Ad Hoc Basis?

Problem scenario
You want to install a package with a yum command.  But you receive an error about the package not being available.  You know that a reachable, yet unconfigured, repository has the package.  You know the repository's name too.

You cannot use "subscription-manager register" to configure a new repository because you do not have the proper credentials or there is a firewall blocking the Red Hat derivative Linux server.  What should you do to install a package from a different repository on a one-time basis?

Solution
Run a command such as this:
sudo yum install foobar --enablerepo=SPECIAL_REPO

# replace "foobar" with the package you want to install
# replace "SPECIAL_REPO" with the name of the repo that has it.

How Do You Get Your Smart Phone’s Flashlight to Work?

Problem scenario
You need illumination to see in a dark room (e.g., a data center or behind a server in a server room).  How do you get your smart phone to illuminate its flashlight?

Solution
It depends what type of phone you have.  See the bullet below that corresponds with the type of phone you have.

  • For an iPhone, see this website.
  • For an Android smart phone:

           1.  Drag the top bar down until you see different options such as "Bluetooth", "Wi-Fi", and "Airplane mode".
           2.  Toggle the option for "Flashlight".
           3.  If that does not work, see this external link.  If you want a new Android phone, click here.

  • For a BlackBerry:

           1.  Press the BlackBerry icon button.  It will look like this:

(Courtesy of simpleicon.com.)

2.  Click the option for "Flashlight".

            If you want a new BlackBerry, click here.

How Do You Troubleshoot Sonarqube Not Starting with Log Messages about “failed to load plugin”?

Problem scenario
You are using SonarQube Community Edition.  SonarQube will not start.  You recently moved a .jar file into a plugins directory.  You want to use this plugin to analyze code.  

The SonarQube logs may register something like "Background initialization failed. Stopping SonarQube java.lang.IllegalStateException: Fail to load plugin C / C++ / Objective-C [cpp]"

The logs may also say something like this: "Unable to register extension com.A.A.A.B.F from plugin 'cpp' or "NoClassFoundError...PropertiesDao".

What should you do to get SonarQube to start?

Solution
Stop SonarQube services.  Remove the recently added plugin (e.g., move the .jar file from a plugin directory).  Restart SonarQube services.

You cannot use the C / C++ plugin without a paid version of SonarQube such as the Developer Edition.

How Can You Get SUPERAntispyware Updates to Download Reliably?

Problem scenario
Your Super AntiSpyware updates are not downloading properly.  You tried reinstalling the application.  The problem happens on Windows 7 and Windows 10.  What should you do?

Possible solution #1
Do not use a VPN connection for your internet browsing.  This can cause a problem with getting the updates.

Possible solution #2
See if your have a firewall blocking special ports.  Strict TCP security measures can prevent the application from getting the proper updates.

Possible solution #3
Apply the updates manually.  Download this for the most recent updates.  You do not need to uninstall and reinstall the application.

Possible solution #4
You could consider posting the details of your problem on the old website http://forums.superantispyware.com. But apparently it is gone.

Possible solution #5
Buy the supported version and open a ticket.

How Do You Get Variables That Are Assigned a Value in an Ansible Playbook (i.e., a .yaml file) to Be Assigned from a Different File?

Problem scenario
You have a complex Ansible playbook (a .yaml file) that you want to be more modular with discrete component files.  You want to assign variables in a different file.  This will make your Ansible playbook have fewer lines.  Your playbook must  read in the variables from a separate file and inject them into the playbook when it is run.  You appreciate Unix philosophy of having things be modular.

You tried creating a vars file and placed it in a group_vars directory.  But when you run the playbook you get "The task includes an option with an undefined variable."

How do you have a separate file for variables for your playbook?

Solution
1.  In the directory with the playbook, create a subdirectory called "group_vars". 
2.  In group_vars create a subdirectory called "all". 
3.  Create the file named "vars" in this subdirectory named "all". 
4.  The variables can be assigned in this "vars" file.  The formatting is the same as the Ansible playbook.

What Command Would Test If sudo Was Working without Making Any Changes?

Problem scenario
To see if Ansible can run commands with sudo without being prompted, you want to run a test.

You want to see if sudo works for certain on your Linux server.  But you do not want to destroy anything or change any files.  What should you do for a test that would tell you if sudo is working or not?

Solution
Run a command such as this:  sudo ls /root

The above would not ordinarily work for a regular Linux user.  

If you have Ansible installed and configured with an inventory (e.g., /etc/ansible/hosts) file that is ready, you can run a command like this to see if you are prompted for a password when elevating to sudo:

ansible -m shell -a 'sudo ls /root' all

If you want to test a specific managed node, you could modify the command above by replacing "all" with the hostname of the managed node you want to test.

How Do You Troubleshoot the Error “java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver”?

Problem scenario
You run a Java program and receive "java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver".  You need to get a program working despite reading that this driver has been deprecated.  What should you do?

Solution
1.  Find the JRE/lib/ext directory.  
2.  Place an ojdbc14.jar file (e.g., downloaded from Oracle.com or some trustworthy website) in that directory.
3.  Without recompiling your program, run the Java program again.

For future reference:
If you want to reinstall Java or install the JDK on any type of Linux see this posting.  For more information about database connectivity from a Java program, see this website.

How Do You Use the .gitignore File?

Problem scenario
You want certain files to be ignored when you do a git add --all.  Later you want to run a "git commit" and a "git origin push master" but you do not want certain files included.  While developing a solution and modifying files, you place binary files or change source code to include sensitive passwords in the same directory as your locally saved Git repo that you pulled down.  These files to be excluded are files you do not want stored in a Git repository on the centrally available server (e.g., BitBucket or GitHub).  How does the .gitignore file help you keep files private that should not be stored in a repository while also being in a convenient location that allows you to develop solutions rapidly?

Solution
There are multiple settings and variations of how to use a .gitignore file.  A basic way to use it is to create a .gitignore file (via vi) in a base directory of the Git repo.  Then have a list of the file names that you do not want to include in the Git repository.  List the files case sensitively and one file per line.  If your repository has subdirectories, files that have the same name as those in the .gitignore file will all be excluded (regardless if they are in the base, or root, directory of the Git repo or in a subdirectory).

To never add .jar files (something that you would not want in a Git repo) use this as the .gitignore file in the Git repo:

*.jar