How Do You Install Molecule on RHEL v. 8.x with Python 3?

Problem scenario
You want to make and test Ansible roles, and therefore you want to use Molecule. You are using RHEL version 8.x. You want to use Python 3 and Molecule. What should you do?

Solution
Prerequisites
i. You should install Docker. If you need assistance, see this posting.
ii. You should install these packages before hand:

sudo yum -y install gcc python3-devel
sudo dnf install -y redhat-rpm-config

Procedures
1.

How Do You Troubleshoot the Message “ImportError: cannot import name ‘pubsub_v1′”?

Problem scenario
From the Python command prompt or when running a Python program, you receive this message “ImportError: cannot import name ‘pubsub_v1′”. What should you do?

Solution
Possible Solution #1
Try to run the program as sudo: sudo python nameOfProg.py

Possible Solution #2
Prerequisite
This assumes that pip has been installed.

How Do You Troubleshoot the Message “ImportError: No module named ‘google'”?

Problem scenario
From the Python command prompt or when running a Python program, you receive this message “ImportError: No module named ‘google'”. What should you do?

Solution
Possible Solution #1
Try to run the program as sudo: sudo python nameOfProg.py

Possible Solution #2
Prerequisite
This assumes that pip has been installed.

How Do You use the Built-in Exception Handling Functionality of Python?

Problem scenario
You want to use the built-in exception handling in your Python program. You know some part or parts of the code may throw an error. How do you use the “except” keyword?

Solution
Use the “try” key word. Here is an example of a program that throws an error:

commandthatdoesnotexist
x = 1 + 1
print(x)

python3 progwitherror.py
Traceback (most recent call last):
File “progwitherror.py”,

How Do You Write a Python Program to Show the Status of the Servers in AWS?

Problem scenario
You want to list the statuses of each EC-2 instance in AWS using Python. How do you do this for a given region in AWS (e.g., us-west-1)?

Solution
Prerequisites
This assumes you have installed Boto3. If you do not know how, see this posting “How do you install Boto 3 on a RHEL server in AWS?

How Do You Write the Equivalent of a “hello world” Program with Machine Learning in Python?

Problem scenario
You want to be able to say you ran a machine learning program. You know some Python basic. What do you do to write a very simple machine learning program?

Solution
Prerequisite
This assumes that pip has been installed. If you need assistance see this posting.

Procedures

1.

In Python, What Are Some Advantages with Calling a Function or as a New Thread?

Question
Python supports the creation of new threads for [bound or unbound] functions. They can help with multiprocessing. New threads are ideal for non-blocking operations like serving a GUI. If you want a server to begin certain operations in parallel with others, you may want to use new threads as opposed to new processes (which can provide the same parallel processing benefit).

In Python, What Are Some Disadvantages with Calling a Function as a New Thread?

Question
Python supports the creation of new threads for [bound or unbound] functions. They can help with multiprocessing. If you want a server to begin certain operations in parallel with others, you may want to use new processes as opposed to new threads. Both threads and processes can provide the same parallel processing benefit. What are some disadvantages of using a thread to call a function?

How Do You Use Testinfra (the Python module)?

Problem scenario
You prefer Python to Ruby for certain tasks, and you want to have a way of testing your configuration management tools. You want to use Testinfra to accomplish this (https://testinfra.readthedocs.io/en/latest/). You want to install Testinfra to test it out. What do you do?

Solution
Prerequisites
i. You must have pip3 installed on the server.