How Do You Install Docker on an AWS Instance of Ubuntu?

Problem scenario
You want to install Docker on an AWS instance of Ubuntu.  But you do not know how.  How can you quickly do this?

Solution
Run these two commands:
sudo apt-get -y update
sudo apt -y install docker.io

An alternative set of directions is here.  For a variety of different directions for all different types of Linux, see this posting.

Using Ubuntu, How Do You Install a C++ Compiler and Run a Basic C++ Program?

Problem scenario
You want to install a C++ compiler in Ubuntu.  You want to write a basic C++ program and run it.  How do you do these things?

Solution
1. As root, install a C++ compiler with this command:

apt install g++

2. Create a basic program.  Here is an example.  Name this file hello.cpp and put this as the content:

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello from ContinualIntegration.com!" << endl;
    return 0;
}

3.  Compile the code with this command:

g++ hello.cpp

4.  Run the byte code with this command:

./a.out

How Do You Deploy Docker to Ubuntu Linux Servers Using Puppet?

Problem scenario
You want to deploy Docker to Ubuntu Linux using Puppet.  How do you write a manifest to install Docker an Ubuntu server?

Solution
This solution demonstrates transferring a file with Puppet.  

1.  Install Puppet master on an Ubuntu Server.  See this link if you want directions.
2.  Install Puppet agent on a different Ubuntu server.  See this link if you want directions.
3.  On the Puppet Master server, run this command (taken from this link):

puppet module install puppetlabs-docker_platform --version 2.2.1

4.  On the Puppet Master server, go to /etc/puppet/module/docker/.  Create a directory named "files".

5.  Still on the Puppet Master server, in the "files" directory, create a file named "docker_inst.sh" with the following content:

#!/bin/bash
apt-get update
apt-get install apt-transport-https ca-certificates
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo 'deb https://apt.dockerproject.org/repo ubuntu-trusty main' > /etc/apt/sources.list.d/docker.list
echo 'deb http://cz.archive.ubuntu.com/ubuntu trusty main' >> /etc/apt/sources.list.d/docker.list
apt-get update
apt-cache policy docker-engine
apt-get --assume-yes install linux-image-extra-$(uname -r) linux-image-extra-virtual
apt-get --assume-yes install docker-engine
sudo service docker start
sudo groupadd docker
sudo usermod -aG docker ubuntu
docker run hello-world

6.  Still on the Puppet master server, go to /etc/puppet/manifests/.  Modify site.pp to have these stanzas:

file { '/tmp/docker_inst.sh':
   mode => '0644',
   source => 'puppet:///modules/docker/docker_inst.sh',
 }
exec { 'install_docker':
    command => "/bin/bash /tmp/docker_inst.sh"
}

7.  On the Puppet Agent server, run this:

puppet agent -t -d

How Do You Deploy Docker to RedHat Linux Servers Using Puppet?

Problem scenario
You want to use Puppet to deploy Docker to a RHEL server in AWS.  How do you do this?

Solution
Warning: This may not work for Puppet versions 5 or higher. It should work for Puppet version 4 or lower. This solution is not a best practice.  It is quick way to deploy a version of Docker made for CentOS to RHEL instances.  It demonstrates transferring a file with Puppet.  This solution is for educational purposes only.

1.  Install Puppet master on a RedHat Server.  For directions, see this link.
2.  Install Puppet agent on a different RedHat server.  For directions, see this link.
3.  On the Puppet Master server, run this command (taken from this link):
puppet module install puppetlabs-docker_platform --version 2.2.1

4.  On the Puppet Master server, go to /etc/puppet/module/docker/.  Create a directory named "files".
5.  Still on the Puppet Master server, in the "files" directory, create a file named "docker.repo" with the following content:

[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

6.  Still on the Puppet master server, go to /etc/puppet/manifests/.  Modify site.pp to have these stanzas:

file { '/etc/yum.repos.d/docker.repo':
   mode => '0644',
   source => 'puppet:///modules/docker/docker.repo',
 }
 exec { 'install_docker':
    command => "/bin/yum -y install docker-engine"
} 

7.  On the Puppet Agent server, run this:  puppet agent -t -d

How Do You Install a Kitchen or Bath Faucet Aerator When It Does Not Want to Screw On?

Problem scenario
When replacing an aerator to a kitchen or bathroom sink, you cannot easily install a new one.  What is the problem?

Possible solution #1
There is a gasket attached to the new aerator that needs to be removed.

Possible solution #2
The new aerator is a male aerator and you need a female aerator.

Possible solution #3
The new aerator is a female aerator and you need a male aerator.

Possible solution #4
The new aerator is not the correct size.

Possible solution #5
The old aerator *appeared* to be a male or female aerator but it was BOTH male and female.

How Do You Deploy Puppet Agent 3.x to a RedHat Linux Instance in AWS?

Update on 12/4/17
If you want to install Puppet Agent 5.x (a much newer version), see this posting instead.

Problem scenario

You installed Puppet Master on an AWS instance of RedHat Enterprise Linux.  (See this link if you want to install Puppet Master). You now want another AWS instance of RHEL 7.x to be configured as a Puppet Agent node. You want to run a manifest to make sure that this new Puppet Agent node (i.e., server) is working with your Puppet Master server.  What do you do to install Puppet Agent 3.x on a RedHat Linux server and configure it to work with Puppet Master?

Solution
This solution is for RHEL 7.3 instances in AWS.  You could easily adapt this solution to other RedHat servers in different environments.  It explains how to deploy Puppet and apply a manifest (in combination with these directions) from scratch.

Prerequisite
Using AWS change the Security Group so that the inbound rules will allow connections from the Puppet Agent server.  One way of doing this is to find the internal IP addresses of the Puppet Agent server.  This command should help you if it is run on a Linux server:

ip addr show | grep inet | grep -v 127.0.0.1 | grep -v inet6 | cut -c 10-24 | awk -F "/" '/1/ {print $1}'

Configure the relevant AWS Security Group allow an inbound connection from the IP address in the result above. 

Here is a detailed explanation of how to create an inbound connection:

Go to Security Groups.  Find the relevant security group and click the Inbound tab.  Then click "Edit."  Click "Add Rule."  Then choose for "Type" in the dropdown menu "Custom TCP Rule."  For "Port Range" choose 8140.  For the "Source" drop down option, choose "Custom."  Enter the internal IP address of the Puppet agent like this:

x.x.x.x/32

Substitute x.x.x.x with the internal IP address (as found with the above "ip addr show" command).

Procedures
On the Puppet Master server, do the following two steps:

1.  Mentally decide how much RAM you want Puppet Master application to have.  If you are not sure, try
run this command:  cat /proc/meminfo | grep Mem

2.  Create this file:  /etc/default/puppetserver
In this file put a stanza like one of the following:

JAVA_ARGS="-Xms512m -Xmx512m"

JAVA_ARGS="-Xms1g -Xmx1g"

JAVA_ARGS="-Xms2g -Xmx2g"

3.  As root run these three commands:

puppet master restart
hostname -f
ip addr show | grep inet | grep -v 127.0.0.1 | grep -v inet6 | cut -c 10-24 | awk -F "/" '/1/ {print $1}'

# Remember the IP address from the last command above.  Disregard any trailing backslash "/" or numbers thereafter.

4.  On the Puppet Agent server, modify the /etc/hosts file.  It should have this stanza where x.x.x.x is the internal IP address from the Puppet Master server (the result of the last command ran in step #2):

x.x.x.x puppet

5.  On the Puppet Agent node, run these two commands:

rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm
yum -y install puppet

6.  On the Puppet Agent node update this file: /etc/puppet/puppet.conf
The last line of the [main] section of this puppet.conf file should have this stanza (where FQDNofPuppetMasterserver with the result of the "hostname -f" command ran on the Puppet Master server (in step #2)):

server=FQDNofPuppetMasterserver

7.  Run this command on the Puppet agent node:  puppet agent start

8.  Go to the Puppet Master server.  Run this command:  puppet cert list

9.  Assuming the above had some output such as puppet.agent.continualintegration.com, from the Puppet  Master server run this command (but substitute puppet.agent.continualintegration.com with the FQDN that resulted from the command in step #7):

puppet cert sign puppet.agent.continualintegration.com

Alternative step #8: Assuming that step #7 showed no other servers that you do not want signed, run this command:

puppet cert sign --all

10.  Test it.

a) On the Puppet Agent server, run

puppet agent --enable

b) On the Puppet Master server go to /etc/puppet/manifests/.  Create site.pp with the following content (replace the FQDN):

  exec { 'somethingneat':
        command => '/bin/date > /tmp/continual.txt'
       }

c)  On the Puppet Agent node, run this:  puppet agent -t -d

d)  Check the /tmp/ directory for the file named "continual.txt."

How Do You Install Puppet Master on a RedHat Linux Server (an AWS Instance)?

Problem scenario
You want to install Puppet Master on RHEL 7.x running in AWS.  You only have five minutes to complete this task.  How do you install Puppet Master immediately?

Solution
1.  Create puppetinstaller.sh in the /tmp directory.  It should have the following lines (stop before you get to step #2):

#!/bin/bash
# Written by continualintegration.com

yum -y install ntp
echo '
server 0.us.pool.ntp.org
server 1.us.pool.ntp.org
server 2.us.pool.ntp.org
server 3.us.pool.ntp.org' >> /etc/ntp.conf

systemctl start ntpd

yum -y update
rpm -ivh https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm
# rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm
# To install a legacy version of Puppet (3.x), comment out the first rpm stanza and uncomment out the second.

yum -y install puppetserver
ln -s /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet

2. Run this command:  sudo bash /tmp/puppetinstaller.sh

3.  Verify it worked by running this command:  puppet -V

How Do You Troubleshoot the Error “Failed to restart puppetserver.service: Unit puppetserver.service not found.”?

Problem scenario
You try this command from the Puppet Master server:

service puppetserver restart

But you get this error:

"Failed to restart puppetserver.service: Unit puppetserver.service not found."

What should you do?

Solution
Do not use "puppetserver" in the command.  The correct command is:

service puppetmaster restart

How Do You Get PHP to Have a Separate Line for an Input Field in a Submit Form?

Problem scenario
In a PHP "submit form" you have various fields.  Two of the fields are on the same row.  That is, when you open the page with a web browser, two input box fields are the same distance from the top and bottom of the page.  You want each field to be on its own line.  How do you do you get the PHP form to render the way you want?

Possible solution
This problem can be caused by a missing ">".  

Field3 and Field4 in this example below (<html> to </html>) would appear on the same row when the below is saved as a .php file and viewed with a web browser:

<html>
<body>

<form action="cool.php" method="post">
Field1: <input type="text" name="field1"><br>
Password: <input type="password" name="password"><br>
Field3: <input type="text" name="field3"<br>
Field4: <input type="text" name="field4"<br>

<input type="submit">
</form>

</body>
</html>

Note the lack of a closing ">" on the "Field3" line.  On the Field3 line before the "<br>", there is no ">".  This code below will put Field3 on a different line from Field4:

<html>
<body>

<form action="cool.php" method="post">
Field1: <input type="text" name="field1"><br>
Password: <input type="password" name="password"><br>
Field3: <input type="text" name="field3"><br>
Field4: <input type="text" name="field4"<br>

<input type="submit">
</form>

</body>
</html>