How Do You Use AKS with the Azure CLI?

Problem scenario
You want to use Azure's PaaS for Kubernetes without using a web UI. What do you do?

Solution
Warning: this will cost money. This will create resources in Azure.

Prerequisites
i. You have the Azure CLI installed. If you need assistance with this, see How Do You Install the Azure CLI on a Debian/Ubuntu Linux Server?

ii. Your Azure account needs to allow you to create relevant services. If you have already been hacking around in your Azure account, you are probably fine. If you want to see the details of what you need, see this external posting.

Procedures
The words "contintapp" and "excellent" are arbitrary. In the examples below you can draft your own commands. Replace "excellent" with the name of your managed cluster. Replace "contintapp" wih the name of your resource group.

az group create --name contintapp --location centralus

az aks create --resource-group contintapp --name excellent --node-count 3 --node-vm-size Standard_A2_v2 --generate-ssh-keys

# The above command can take 10 minutes.

az aks show --name excellent --resource-group contintapp

az aks delete --name excellent --resource-group contintapp
# Respond with "y" to the prompt.
# It may take 10 minutes to process.

How Do You Generate 10,000 Random Numbers in a Tuple in Python?

Problem scenario
You want to generate 10,000 random numbers in a tuple. That is, you want a tuple with 10,000 numbers. The numbers can be chosen at random. How do you do this?

Solution
See this posting first and follow it: How Do You Generate 10,000 Random Numbers in a list in Python?
See this posting second and follow it: How Do You, in Python, Make a Tuple from a List?

How Do You Install OpenLDAP on Debian Linux?

Problem scenario
You have a Debian Linux server. You want to install OpenLDAP on it. What do you do?

Solution
(These directions were tested to work on Debian 9 in Google Cloud Platform.)

1. Run this command:
sudo apt-get -y install slapd ldap-utils

2. Set a new password for the administrator.

3. Uncomment the "BASE" and "URI" stanzas in /etc/ldap/ldap.conf.

sudo vi /etc/ldap/ldap.conf # remove the leading hash "#" marks

4. While in this file, modify the newly uncommented BASE and URI stanzas. For the BASE, the values should be one, two, three or possibly more of strings like this:

dc=,dc=,dc=

Use the hostname -f command on the server. Ignore the left most value. value1 will be the string after the leftmost period. value2 will be the string after the second period from the left. You may have one or five values. There is no terminating comma. If you want a Python script to tell you what to put, see this link. (How do you write a Python script to find the ldap.conf's BASE stanza value?)

For URI, you may want to use an internal IP address of the server instead of an FQDN. Here is an example:

URI ldap://10.142.0.2 ldap://10.142.0.2:666

You can use an FQDN name or base the format on the example you see in the unmodified version of the file.

5.a. Run this command: sudo dpkg-reconfigure slapd

5.b. To the prompt about "Omit OpenLDAP server configuration?" choose "No".

5.c. To the prompt about a DNS domain name, enter whatever you think is best. If you are setting this up in Google Cloud Platform as a proof-of-concept, you may want to keep the default option and choose "Ok".

5.d. For the "Organization name" prompt you may enter your company name and choose "Ok".

5.e. For the "Database backend to use:" prompt choose MDB unless you know a different option would be best for your situation.

5.f. For the "Do you want the database to be removed when slapd is purged?" prompt, choose whichever you think is best. If you are setting this up as a proof-of-concept, choose "Yes".

5.g. For the "Move old database?" prompt, choose "Yes".

6. Test your set up by running this command:

ldapsearch -x

# You should see the word "Success" in the output.

How Do You Troubleshoot This Ansible Message “module_stderr…Shared connection to server closed. [Errno 13] Permission denied…MODULE FAILURE”?

Problem scenario
You try to run an Ansible playbook, but you get this problem:

"module_stderr…Shared connection to server closed. [Errno 13] Permission denied…MODULE FAILURE"

How do you fix it?

Solution
Is the Ansible playbook configuring the mode settings to not allow other users to execute the file? It could be that lower in the Ansible playbook, after the file is protected from other users executing it, the Ansible playbook is attempting to modify it. One solution would be to rearrange your playbook or eliminate the "mode: 644" settings. (Ironically the file may have the equivalent of 644 permissions settings by default if you comment out such a "mode" stanza; the error may also go away too.) Another solution would be to change the file permissions settings to something that will allow the user who is running the playbook to write to the file.

How Do You Get Bitbucket to Render Text in a Regular Size when There Are Hashtag (or Hashmarks, “#”)?

Problem scenario
Bitbucket's GUI renders Bash code with large text on lines with a "#" hash sign (aka tic-tac-toe sign, number sign, or hash symbol). How do you get the lines to be the same size in Bitbucket GUI rendering?

Solution
Usually the hash sign "#" is a comment (for many programming languages). If you have a space after the hash sign like this "# comments here" (instead of "#comments here"), it should look fine. Often having a space after the hash sign introduces no problems if comments follow.

How Do You Troubleshoot This Error “error executing access token command /google/google-cloud-sdk/bin/gcloud”?

Problem scenario
You run a command like this to view your Google Kubernetes Engine (GKE) clusters:

kubectl get pods

You see this:
'Unable to connect to the server: error executing access token command "/google/google-cloud-sdk/bin/gcloud config config-helper --format=json": err=fork/exec /google/google-cloud-sdk/bin/gcloud: no such file or directory output= stderr='

What should you do?

Solution
Check your config file in the .kube directory. What is the value for "cmd-path"? Does it match up which where your gcloud file is on your Linux server? Make sure the two match.

How Do You Troubleshoot This Error “org.apache.bsf.BSFManager or javax.script.ScriptEngineManager”?

Problem scenario
You are running Ant and you get this error:

"Unable to load a script engine manager (org.apache.bsf.BSFManager or javax.script.ScriptEngineManager"

What should you do?

Solution

Uninstall Ant (e.g., sudo apt-get -y remove ant). Install the latest version of Ant. If you need directions, see this posting as it works on any distribution of Linux.

How Do You Write an Ansible Playbook to Retrieve Files from a Directory Relative to where the .YAML File Is?

Problem scenario
You want to refer to files in a subdirectory of the parent directory that houses your Ansible playbook. You have Git repositories with .yaml files and subdirectories. You want the Git repo to be transferred to a variety of different servers. The absolute path to the directory where the files are will vary. How do you have a variable or relative path reference in the playbook so as long as the directory structure is in place, your playbook will run correctly?

Solution

  1. This assumes you have a directory called "files" in the directory with your Ansible playbook (e.g., called good.yaml).
  2. In your playbook (e.g., good.yaml) use this notation:

../files/foo.bar

Here is an example:

- copy:
    src: ../files/foo.bar
    dest:  /tmp/excellent.file
    mode: 0777

Why Does a Python Variable Keep Getting Assigned to 0 When the Output of the Bash Command Is a Different Number?

Problem scenario
In a Python script a variable that receives the output of a Bash command. When you run the Bash command on Linux or in a script, it works fine. But in the Python script it keeps being assigned to 0. What is wrong?

Solution

subprocess.call("bash command", shell=True) is NOT the same as subprocess.check_output("bash command", shell=True).

The subprocess.call will return a 0 if the Bash command was successful. The subprocess.check_output command will return the output of the Bash command itself.

For more information, see this posting https://stackoverflow.com/questions/25333537/performance-of-subprocess-check-output-vs-subprocess-call.