How Do You Troubleshoot the Python Error “subprocess.CalledProcessError: Command ‘…’ returned non-zero exit status 1”?

Problem scenario
You are automating a Linux infrastructure task with Python using subprocess calls. You get this error “subprocess.CalledProcessError: Command ‘…’ returned non-zero exit status 1”, what should you do?

Run the Linux command without Python. Then run echo $? to determine the exit code. If you see a 1, that means Python notices this command is not considered to have run successfully.

 » Read more..

How Do You Retrieve an Application-Level Secret from AWS?

Problem scenario
You want to obtain a non-database secret from AWS and you know the name of the secret (in Secrets Manager) and the region it is in. What should you do?

You have installed and configured the AWS CLI. If you need assistance with this, click on this posting if you can use pip or this posting if you cannot use pip.

 » Read more..

Python Tips when Dealing with Lists

Here are some tips when using Python and dealing with lists.

  1. Never call a variable “list”. (If you are using a variable for a list, use something like lista or list1 — not “list”.) Any word that is not a reserved word and not a built-in data type will work. You need to know the reserved words in Python because if you accidentally use them, it can cause a problem.

 » Read more..

How Do You Get PowerShell to Run Scripts?

Problem scenario
One of the following apply to you.

Problem scenario #1
You try a PowerShell command but you get an error like this “The ‘Login-AzureRmAccount’ command was found in the module ‘AzureRM.profile’, but the module could not be loaded.”


Problem scenario #2
You try a PowerShell command but you get an error like this:

Files\WindowsPowerShell\Modules\AzureRM.profile\5.8.2\AzureRM.Profile.psm1 cannot be
loaded because running scripts is disabled on this system.

 » Read more..

In Python How Do You Print Just The Values of The Two-dimensional List without The Quotes, Commas or Brackets?

Problem scenario
In Python your program has a two-dimensional list. It prints out like this:

[‘ ‘, ‘X’, ‘ ‘, ‘ ‘, ‘ ‘]
[‘ ‘, ‘X’, ‘X’, ‘ ‘, ‘ ‘]
[‘ ‘, ‘X’, ‘X’, ‘X’, ‘ ‘]
[‘ ‘, ‘X’, ‘X’, ‘X’, ‘X’]

You want it to print out like this:


Assuming that there are n rows of your matrix (aka two-dimensional array),

 » Read more..

How Do You Troubleshoot a Java Compilation Error “class fooBar is public, should be declared public class…”?

Problem scenario
You try to compile a java program, but you get this error: error: class HelloWorld is public, should be declared in a file named
public class HelloWorld {
1 error

What is wrong?

The .java file must have a name of “HelloWorld” like the public class in the error.

 » Read more..

How Do You Create a Puppet Manifest to Install Java?

Problem scenario
You have Puppet agent and Puppet Master set up and configured to work together. You are are running open source Puppet 5.x on Ubuntu servers in AWS. You want to install Java on the Puppet agent nodes. You tried to use the Java module.

On the Puppet Master server, you ran this: puppet module install puppetlabs-java –version 2.2.0

This is your site.pp file:

class { ‘java’ :
package =’java-1.8.0-openjdk-devel’,  » Read more..

How Do You Install Grails on Any Type of Linux server?

Problem scenario
You want to install Grails on a Linux server. What do you do?

Your server has access to the internet.

Run these commands:

sudo curl -s | sudo bash
sudo su –
sdk install grails

# We know this isn’t a best practice to install things as root,

 » Read more..

In Python How Do You Print Three Integers Separated by a Space on the Same Line?

Problem scenario
You want to print three integers. You do not want to convert them to be part of a string. You want a space to separate each integer. How do you do this in Python?

Assuming your variables are x, y, and z, and they are integers, use a line like this:

print(x, y, z)

Here is a complete program that proves it works:

x = 5
y = 3
z = 100
print(x,  » Read more..

How Do You Write a Python Program to Download the Images of a Website?

Problem scenario
You want to download pictures (e.g., .png, .jpeg etc.) from websites. How do you use Python to download such files?

Use this program with a subdirectory in the directory that this program resides to receive the picture files.

Downloads all the images on the supplied URL, and saves them to the
specified output file (“/test/” by default)

python /tmp/test/ # where /tmp/test/ is the directory you want to save the image files to.  » Read more..