How Do You Write a Hello World Program in Golang?

Problem scenario
You want to test out the Golang compiler.  You want to know how to write a basic Go program and run it.  What do you do?

Solution
Prerequisites

You must have the Golang compiler installed.  If you need help, see this posting.

Procedures
1.  Create a file called hw.go with the following five lines:

package main
import "fmt"
func main() {
    fmt.Println("This is a Hello World program!")
}

2.  Run the program by executing this command:  go run hw.go

How Do You Install the Lua Compiler on a CentOS/RHEL/Fedora Server?

Problem scenario
You want to run Lua programs on your Red Hat derivative distribution of Linux server (e.g., CentOS/RHEL/Fedora).  

Solution
1.  Make a script like this called lua.sh with the following lines:

yum -y install readline-devel gcc
curl https://www.lua.org/ftp/lua-5.3.5.tar.gz > /tmp/lua-5.3.5.tar.gz
mv /tmp/lua-5.3.5.tar.gz /opt/
cd /opt/
tar -xzvf lua-5.3.5.tar.gz
cd lua-5.3.5
sudo make linux test
echo "ENV=$ENV:/opt/lua-5.3.5/src/" >> /etc/environment
rm /usr/bin/lua
ln -s /opt/lua-5.3.5/src/lua /usr/bin/lua
a=$(lua -v)
echo $a

2.  Run the script with this command: sudo bash /tmp/lua.sh

What Are The Differences between CMD and ENTRYPOINT in Docker?

Question
Dockerfile has reserved words CMD and ENTRYPOINT.  They seem to do the same thing.  What are the differences between CMD and ENTRYPOINT in Docker besides their words' lengths?

Answer
There are many similarities between these two reserved words in Dockerfile "language."  But here are three differences:

#1  "...CMD can be overwritten by an argument to docker run, while ENTRYPOINT can be overwritten only by using the --entrypoint option of docker run." is a quote taken from page 43 of Docker Cookbook by Sebastien Goasguen.

If you want your Docker container to use different executables or parameters each time, CMD is preferable to ENTRYPOINT.

"If you would like your container to run the same executable every time, then you should consider using ENTRYPOINT in combination with CMD." taken from Docker's official website.

#2  CMD has three forms whereas ENTRYPOINT has only two forms.  The syntax associated with each of these forms will tell the Docker engine which to form to use.  The CMD forms are these: exec form (which is recommended), the default parameters method, and the shell form.  The ENTRYPOINT forms are these: exec form (recommended) and shell form.

You can read more about them here:
https://docs.docker.com/engine/reference/builder/#cmd
https://docs.docker.com/engine/reference/builder/#entrypoint

#3   In the history of Docker, CMD was a command before ENTRYPOINT become a supported reserved word.  This is relevant, external posting states this fact.  The Dockerfile used to be considered a manifesto (according to page 43 of Docker Cookbook by Sebastien Goasguen).  You can read more about the ways Docker has changed here.

How Do You Install docker-compose on Any Distribution of Linux?

Problem scenario
You want a Bash script to install Docker on any distribution of Linux.  You want to use the same script for each Linux server.  How do you write a script that will install docker-compose on any type of Linux including CentOS/RHEL/Fedora, Debian/Ubuntu and Linux SUSE?

Solution
Overview

This will work with AWS or Azure servers or on-premise servers.  It requires that the server have access to the internet.

Procedures

1.  Create a file call dc.sh with these lines:

#script to install Docker compose
version=1.20.1  #change the version as needed
curl -L https://github.com/docker/compose/releases/download/$version/docker-compose-`uname -s`-`uname -m` > ./docker-compose
mv ./docker-compose /usr/bin/docker-compose
chmod +x /usr/bin/docker-compose

2.  Run this script dc.sh like this: sudo bash dc.sh

How Do You Troubleshoot the Ansible Message “AnsibleOptionsError…ansible.cfg…File contains no section headers”?

Problem scenario
You try to run an Ansible playbook but you get this error "AnsibleOptionsError...ansible.cfg...File contains no section headers"

Your ansible.cfg file has headers. What should you do?

Solution
Eliminate indentations.  The [header] should be on the far left of the screen with no leading spaces.

How Do You Troubleshoot the Bash Error “syntax error near unexpected token”?

Problem scenario
You run a Bash script with a function that you developed yourself.  When you run the script, you get the error "syntax error near unexpected token".  What should you do to solve this?

Solution
Call the function without the parentheses.  Do not use this: contintfunc()

Use this when you call, not define, your previously defined function:

contintfunc

How Do You Use an .sls File to Push down Configuration Changes Using SaltStack?

Problem scenario
You want to leverage the CM tool SaltStack.  You have Salt Master installed, and now you want to push down files to Salt Minion client servers.  How do you do this?

Solution
Prerequisites

This solution requires Salt Master to be configured.  If you need assistance, see this posting.

Procedures
1.  The Salt Minion client servers will need to run this:  sudo systemctl start salt-minion

2.a.  On the Salt Master server create a directory /srv/salt/ (e.g., sudo mkdir -p /srv/salt)

2.b.   Create this file: /srv/salt/top.sls with the following three lines of content:

base:
'*':
- funfun

2.c.  Create this file: /srv/salt/funfun.sls with the following three lines of content:
/tmp/great.txt:
file:
- managed
- user: cooluser
- mode: 644
- source: salt://good.txt

2.d.  Create this file: /srv/salt/good.txt with whatever content you want.

3.  Restart salt-master serivce with this command:  sudo systemctl restart salt-master

4.  Push the file down with this command: sudo salt '*' state.apply

5.  Go to the Salt Minion client servers. The /tmp/ directory should have a file called great.txt.

How Do You Use Python to Create a Server in AWS?

Problem scenario
You want to be able to create EC-2 instances in AWS with a Python script.  How do you do this?

Solution
Prerequisites

This assumes you have installed Boto3.  If you do not know how, see this posting.

Procedures
As a reference, you may go here to learn more about Boto's features:  http://boto3.readthedocs.io/en/latest/guide/migrationec2.html
Use this program:

""" Usage instructions
  1. replace "aaa111" with the aws_access_key_id of your account
  2. replace "bbb222" with the aws_secret_access_key of your account
     If you are not sure how to find these credentials do the following:
     To find the AWS Access Key ID and AWS Secret Access Key, in the AWS console, click on your name in the upper right hand corner.
     Then click on "My Security Credentials."  Click "Create New Access Key"  Click "Show Access Key."
  3.  Replace us-west-1 with the region that you want to list Ec-2 instances for.
  4.  Change the "t2.micro" to be the flavor of server that you want to create.
  5.  Change the "3" in MaxCount to the number of servers you want to be created.
  6.  Change the "ami-0b1e356e" to the AMI you want.  One way to browse is to manually log into the AWS console and click "Launch Instance".  The first step will allow you to see IDs of AMIs.
  7.  To run it, call it test3.py and run it with a command like this: "python test3.py"

 Warning: THIS WILL CREATE THREE SERVERS in AWS!
 Warning:  This could be more expensive than you are used to.
"""

import boto3

ec2 = boto3.resource('ec2', aws_access_key_id='aaa111', aws_secret_access_key='bbb222', region_name='us-west-1')

ec2.create_instances(ImageId='ami-0b1e356e', MinCount=1, MaxCount=3, InstanceType='t2.micro')

How Do You Get a Head Set (Or Pair of Ear Buds) to Work with Your Windows Machine?

Problem scenario
You insert 3.5 mm jack for your headphones (audio cable) that is known good into your laptop.  You cannot hear sound out of it.  You go to different parts of the Control Panel, but you cannot see evidence that your Windows computer (laptop or desktop) sees the device.  How do you get your headphones to work?

Root cause
Some I.T. policies disable the 3.5 mm audio jack on the Windows computers.  Sometimes the 3.5 mm jack is defective or loses its connectivity to the motherboard.

Possible Solution #1
Use the docking station.    If you have a docking station with an audio outlet (3.5 mm) use that.  

Possible Solution #2
Use a headset with a USB connector or a USB adapter to 3.5 mm convertor.  This may not be disabled.

How Do You Solve the Error “failed to push some refs” after a “git push origin master”?

Problem scenario
You have two Linux servers (server A and server B).  You have a Git repository on server A.  You are logged into server B as jdoe. You cloned a Git repository from server A (with a "git clone git@gitlabFQDN:/path/to/nameOfRepo.git" command).  You added some files and used "git commit" on server B.  From server B you run this command as the Linux user jdoe: git push origin master

You get this problem:

remote: GitLab: You are not allowed to upload code for this project.
To GitLabServerFQDN:/var/opt/gitlab/git-data/repositories/root/nameOfRepo.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@GitLabServerFQDN:/var/opt/gitlab/git-data/repositories/root/nameOfRepo.git'

How do you upload the new files?

Solution
1.  Log into the web UI for GitLab.  
2.  Click on the Project that has the repository you want.
3.  On the left click on "Settings".
4.  Click on "Repository" under "Settings."  
5.  Click on the "Expand" button for "Deploy Keys".
6.  Provide an arbitrary phrase in the "Title" field.
7.  For the "Key" field input the content of the id_rsa.pub file for the jdoe user (e.g., /home/jdoe/.ssh/id_rsa.pub).  If one does not exist, go to the back-end of the Linux server, log in as jdoe, run 'ssh-keygen -t rsa -P ""' and press enter to the next prompt.
8.  Check the option for "Write access allowed"
9.  Click the green "Add key" button.
10.  Now go back to server B and run: git push origin master

(This solution could potentially work with BitBucket (but probably not step-by-step).  You may need to check the branch name; it may not be "master" but "development" or something else.)