How Do You Fix the Ansible Problem about “libselinux-python”?

Problem scenario
You try to run an Ansible playbook, but you get an error like this: "msg: Aborting target uses selinux but python bindings (libselinux-python) aren't installed!"

You are using a Red Hat derivative of Linux (e.g., Red Hat Enterprise Linux, CentOS or Fedora) and Python 3. What should you do?

Solution
Prerequisite

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

Procedures
Run this command: sudo pip3 install selinux

How Do You Get yum Commands to Work?

Problem scenario
You run run commands, but they fail. The error you see is "Trying other mirror [Errno 14] curl #7…"

What should you do?

Solution

  1. If the output refers to a DNS name, see if the DNS name is for a load balancer (e.g., an ELB), a router, or a server. See if it is pingable. If it is not, find a Linux server in your network that has yum commands working. See if you can ping the DNS name from that Linux server.
  2. If another server on your network has yum commands working, compare /etc/yum.conf files of both. Compare /etc/yum.repos.d/*.repo files too.
  3. See if a firewall, network ACL, AWS Security Group, or Azure Network Security Group is preventing communication with the internet. In other words see if you can ping 8.8.8.8.
  4. See also How Do You Troubleshoot Yum Commands Not Working with the Error “Could Not Resolve Host: mirror.centos.org Unknown Error?

How Do You Troubleshoot the Postfix Error “454 4.7.1 jdoe@acme.com: Relay access denied”?

Problem scenario
You are trying to send an email on a Postfix server. But you keep getting this error: "454 4.7.1 jdoe@acme.com: Relay access denied"

What should you do?

Solution

  1. Back up the /etc/postfix/main.cf file just in case. (This is an optional step.)
  2. Find you server's internal IP address with a command like this: ip addr show | grep eth0 | grep inet | awk '{print $2}'
  3. Modify the /etc/postfix/main.cf file. Go to the "mynetworks" stanza. Verify you see the server's IP address there with a shorthand notation of a relevant subnet mask (e.g., a CIDR). It should look something like this:

172.5.4.0/24 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128

  1. Either reboot the server or run this command to have the changes take effect: sudo postmap /etc/postfix/generic

How Do You Troubleshoot Ansible Errors about SELinux?

Problem scenario
You have Python 3 installed, but you do not have pip3 installed. One of the following also apply to your situation:

Problem scenario #1
You run an Ansible playbook. You receive the error message "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed."

Problem scenario #2
You run an Ansible playbook. You receive the error message "module 'selinux' has no attribute 'is_selinux_enabled'".

What should you do?

Solution
Assuming you pip has been installed, do the following:

1. Run this command (where /path/to is the directory path to where pip is installed):
sudo /path/to/pip install --upgrade pip

2. Run this command:

sudo pip3 install selinux

You are done.

If you cannot install pip (and it is not installed), see this posting How Do You Get the libselinux-python to Work with Python 3?.

How Do You Get the libselinux-python to Work with Python 3?

Problem scenario
You have Python 2 and Python 3 installed. When you run Python 3 programs, you get an error message about selinux. The message is consistent with libselinux-python not being installed.

When you enter the Python interpreter for Python 2, you can run this command without errors: import selinux

But when you enter the Python interpreter for Python 3 (e.g., python3), you get errors when you run this command: import selinux

Security of the server is not critical, and you have no access to download packages from the internet. What should you do?

Solution

  1. Run this command from a terminal: python -v
  2. From the Python 2 interpreter line, run this command: import selinux
  3. The output of the above should show where selinux is. Enter this command to get back to a command prompt: quit()
  4. Find where Python 3's packages should be with this command: sudo find / -name site-packages | grep python3
  5. Run a command like this to create site-packages in a Python 3 directory if you found nothing from step #4.
sudo mkdir -P /path/to/destination/site-packages
  1. Run a modified version of this command: sudo cp -R /path/to/source /path/to/destination/site-packages
    But replace /path/to/source with the site-packages directory found in step #2's results. Replace /path/to/destination with the site-packages directory found in step #4 or created in step #5.

How Do You Troubleshoot the “aws ssm” Command Failing with a Message about “InvalidInstanceId”?

Problem scenario
In AWS Systems Manager you run an "aws ssm" command. You get "An error occurred (InvalidInstanceId) when calling the Send Command operation." What should you do?

Solution
Are there spaces or braces inside the double quotes? These symbols are not part of the instance ID. If you are running a script or complex command, extraneous symbols may be getting injected into your instance ID.

Considerations when Negotiating the Fine Print of an Employment Contract

Bill Gates' father was an attorney, and President of the Washington State Bar Association (according to this site). Bill Gates was concerned with the details of contracts in Microsoft's early days.

I.T. Contractors need to understand American law. To learn about how the contract language works, you may want to hire an attorney. To prepare yourself beforehand, you should try to learn more. If you are an independent contractor who performs software consulting, DevOps engineering, or programming services click here and use this form to protect your status as a worker. (We do not warrant the services of other products. This website is for information only.)

How Do I Write a Script to Test if a File Exists?

Problem scenario
You want a script to test if a file is in a specific location or not. You are using Linux. What should you do?

Solution
Use this script (but modify "/path/to/file" to be the path and name of the file you are searching for):

if [ -f "/path/to/file" ]
then
echo "file exists"
else
echo "file does not exist"
fi

How Do You Troubleshoot the ActiveMQ Build Failure “No plugin found for prefix ‘activemq-perf'”?

Problem scenario
You run this command:

sudo /opt/maven/bin/mvn activemq-perf:broker -Durl=broker:tcp://localhost:61616

You get this result:

[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (14 kB at 17 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (20 kB at 25 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.815 s
[INFO] Finished at: 2020-04-28T15:33:05Z
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'activemq-perf' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/root/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

What should you do?

Solution
Change directories to where the correct pom.xml file is. You could try this command:

sudo find / -name pom.xml

Here is the content of a pom.xml file that could work:

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.acme</groupId>
  <artifactId>run-amq</artifactId>
  <version>1.0-SNAPSHOT</version>
  <build>
    <plugins>
      <plugin>
    <groupId>org.apache.activemq.tooling</groupId>
    <artifactId>activemq-perf-maven-plugin</artifactId>
    <version>5.15.12</version>
      </plugin>
    </plugins>
  </build>
</project>

For future reference, here is a potential directory of the correct pom.xml file: /usr/local/apache-activemq/activemq-tooling/

How Do You Make an Indefinite Linux Command Go to the Background So That You Have Another Prompt?

Problem scenario
You want a non-terminating (or hanging) Linux command that never finishes to go to the background. You want to use the next command line prompt. The process starts from a command you issue at the command line. How do you do you get to the next prompt?

Solution

  1. This will suspend the process momentarily. Hold control and tap "z." Ctrl-z
  1. The above command will result in something like this:
    [555]+ Stopped python3 goodprogram.py

Craft a command like this, but replace 555 with the integer in the output of the command above:

bg 555
# Normally the value will be "1" -- not "555"