How Do Quotes Affect Python if Conditional Tests of Equality for a Variable?

Problem scenario
You are programming in Python, and you want to use conditional logic.  You want to know how variables are evaluated and tested.  You want to use the keyword “if” to evaluate a variable assignment.

Solution
This program below shows how the evaluation of a variable in Python behaves when quotes are involved. Errors are not thrown or displayed to the programmer.  Therefore in some instances the programmer must know how quotes affect logical evaluations with variables.

 » Read more..

How Do You Iterate through Data Members (the Individual Components) of a Groovy Object?

Problem scenario
You have an object that you want to sequentially pass through.  That is, you want to print either the value or the key/name and value pair of every member data item of the object.  How do you print every individual data member of a given object in Groovy?

Solution
Invoke the “.properties.each” keyword.  This built-in feature will allow you to do just this.  There is one “if” condition you will use to avoid printing the “class=class …” feature.

 » Read more..

How Do You SSH to a GCP server?

Problem scenario
You cannot SSH into a Linux Google Cloud Platform server.  How do you create new GCP servers that you can SSH into?

Solution
Summary
Use the “Startup script” in Google Cloud Platform.  This script comes with precautions.  Be careful when pasting it.  The lines can potentially not wrap properly.  Carriage returns could be introduced to make this script fail.  Be very careful because this script creates a user with sudoer privileges. 

 » Read more..

How Do You Troubleshoot “Redirecting to /bin/systemctl start docker.service ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units”?

Problem Scenario
You try to configure Docker such that you can run “docker” commands without sudo.  You run these three commands:

sudo groupadd docker
sudo gpasswd -a $USER docker
newgrp docker

You then installed Docker and rebooted the server.  You then run this:

docker run hello-world

But you received this:

/usr/bin/docker-current: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

 » Read more..

How Do You Use docker-compose?

Problem scenario
You want to create an example of a docker compose file.  How do you use docker-compose?

Prerequisites
i.  This assumes you have Docker installed and running.  If you need assistance, see this posting.
ii.  This assumes that you have installed docker-compose.  If you need assistance, see this posting.
iii.  This assumes the Docker host has access to the internet.

 » Read more..

How Do You Get Jenkins Working in a Docker Container?

One of the following problems apply:

Problem scenario #1
You have no idea how to start Jenkins in a Docker container.  What should you do?

OR

Problem scenario #2
You have run some Docker commands to try to start deploy Jenkins in a container.  You get output like this:

[4213] [10236] Disconnected
[9146] Connection from [::1]:41118
[9146] Extended attributes (16 bytes) exist <host=localhost>

 » Read more..

How Do You Delete Servers in AWS with Python?

Problem scenario
You want to write a Python program to delete servers.  How do you delete EC-2 instances in AWS with Python?

Solution
Prerequisites

a.  You have installed Boto3.  If you do not know how, see this posting
b.  You know the instance IDs.  If you do not know them, see this posting.

Procedures
Read the “Usage instructions” of this Python program we call “deleteec2.py”.

 » Read more..

How Do You Run a Docker Container as a Non-root User?

Problem scenario
You run this command: docker run -it ubuntu bash

“docker: Got permission denied while trying to connect to the Docker daemon sockes/create: dial unix /var/run/docker.sock: connect: permission denied.”

You do not want to run a Docker container as a privileged user (as a recommended practice).  What should you do?

Solution
Prerequisites

Install Docker.  If you need assistance, see this posting.

 » Read more..

How Do You Troubleshoot an ldapsearch -x command Returning “No such object”?

Problem scenario
You want to test your OpenLDAP configuration.  You run an “ldapsearch -x” command in hope that it wil l return a “Success.”  You run the “ldapsearch -x” command, and you see this:

“# search result
search: 2
result: 32 No such object”

What should you do?

Solution
Verify your /etc/ldap/ldap.conf is configured correctly.  The BASE stanza should have one or possibly three “dc=” entries separated by commas.

 » Read more..

How Do You Troubleshoot the Bash Error “unary operator expected”?

Problem scenario
You run a Bash script with an if condition that uses the -Z flag.  It looks like this:

if [ $foovar -Z ]; then

The script seems to run with an ignorable error message “unary operator expected”.  How do you get this error to not appear?

Solution
Use ‘= “”‘ instead of “-Z”.  Here is one way to re-write the if condition above:

if [ $foovar = “” ];

 » Read more..