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.

How Do You Make an Environmental Variable Persist through a Reboot on a Linux server?

Problem scenario
Every time a server is rebooted, you have to manually set environment variables with the "export" command. You want a variable to persist through a reboot so you do not have to do this manual work. You want a variable to be in the environment of the OS every time you log in. You want the solution to be specific to one user but you want it to work for any distribution of Linux (a Debian or Red Hat derivative including SUSE, CentOS/RHEL/Fedora, and Ubuntu). How do you get a variable to be in the environment of a Linux OS for your user every time you log in?

Solution

  1. Modify the .bashrc file in your home directory: vi ~/.bashrc
  2. At the very end of the file add a new line. Place the "export …" command without the initial "export " (export and space). Here is an example:
    JAVA_HOME=/usr/lib/jvm/java-9-openjdk
  3. The above is specific was one user. If you want every user to get this variable, see this link titled How Do You Set an Environment Variable for Every User Upon Rebooting a Linux Server?.

How Do You Troubleshoot the Groovy Error “JAVA_HOME is not defined correctly”?

One of the following situations apply to you:

Problem scenario #1
You try to run a Groovy command (e.g., groovy foobar.groovy), but you get this error:
"groovy: JAVA_HOME is not defined correctly, can not execute: /usr/lib/jvm/java-9-openjdk/bin/java"

Problem scenario #2
You get this error when you run an "hdfs" command:

ERROR: /usr/bin//bin/java is not executable.

What should you do?

Solution

  1. Set the JAVA_HOME variable. Run this command: which java
  2. Mentally eliminate the trailing "/bin/java" from the above command. If Java was not found, follow these directions to install Java.
  3. Draft this command but replace "foobar" with the results of step #2 (with the elimination of "/bin/java" from the end of step #1's results): export JAVA_HOME=foobar
  4. Run the drafted command from above.
  5. Try to use Groovy again.

If you want the solution to persist a reboot, we recommend rebooting the server and seeing if your original problem is reproducible. Then run a command like this but replace "foobar" with the results of step #2 (with the elimination of "/bin/java" from the end of step #1's results):

echo 'export JAVA_HOME=/foobar' >> ~/.bashrc

How Do You Install Helm on Any Type of Linux?

Problem scenario
You want to use Helm to manage Kubernetes applications. Helm helps you with packages for changes to Kubernetes (in ways that are similar to yum or apt). Helm uses what are called Charts (.yaml files) that enable you to do more with Kubernetes with less trouble. Helm consists of these two things: a CLI tool and a server component that runs as a pod in a Kubernetes cluster (page 531 of Kubernetes in Action by Luksa).

You want to install Helm. You want a script that will work on any type of Linux. You have access to the internet. What should you do?

Solution
Run these commands:

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

(The above commands were taken from this website.)

The script below no longer works as of January 2022.
1. Create this script /tmp/helm.sh:

version=2.9.1

curl -Lk https://kubernetes-helm.storage.googleapis.com/helm-v$version-linux-amd64.tar.gz > /tmp/helm-v$version-linux-amd64.tar.gz

mv -i /tmp/helm-v$version-linux-amd64.tar.gz /bin/
cd /bin/
tar -zxvf helm-v$version-linux-amd64.tar.gz
cp linux-amd64/helm /usr/local/bin/helm

2. Run it like this: sudo bash /tmp/helm.sh

If you are using Debian/Ubuntu Linux without internet access, you can try this posting.