Migrating from Chef Client version 13 to 15

Syntax changes

There are breaking changes between Chef Client version 13 and the newer versions, make sure you update your Chef cookbooks to make them work with the new version of the Chef Client.

ResourceSince versionOld syntaxNew syntaxNotes
loggerClient 14.0keyword, cannot use it as a variable or parameter name
windows_firewall_rule resourceClient 14.7localportlocal_portMoved from the Windows cookbook to the Chef cookbook

Computer failed to join domain from its current workgroup ‘WORKGROUP’ with following error message: The system cannot open the device or file specified.

When you use PowerShell to join a Windows server to the domain make sure the -OUPath is correct.

Computer failed to join domain from its current workgroup ‘WORKGROUP’ with following error message: The system cannot open the device or file specified.

In this case we wanted to place the joined computers in the Computers folder, so no OUPath specification is necessary. The solution was to omit the -OUPath option from the command:

Add-Computer -DomainName $domain -Credential $credential -Server $domaincontroller -ComputerName $old_computername -NewName $new_computername

Computer ‘…’ failed to join domain. The value provided as the current password is incorrect.

Computer ‘…’ failed to join domain ‘…’ from its current workgroup ‘WORKGROUP’ with following error message: Unable to update the password. The value provided as the current password is incorrect.

If you can join the computer to a domain using the UI, but the PowerShell script fails with the error message above, make sure you add the name of the domain to the username that joins the computer to the domain.

domain\\username

When you use the UI, Windows knows the user belongs to the new domain. The configuration tools run as a local admin, so you need to specify the name of the domain with the user name.

Set the environment name in Chef Test Kitchen

To specify the environment name in the .kitchen.yml file

Create a JSON environment file. Chef Zero used by Test Kitchen does not understand YAML or Ruby, we need to use JSON.

  • In your cookbook’s root directory create a directory for environment files
mkdir environments
  • Create the myenv.json environment file in the environments directory.
{
    "name": "myenv",
    "description": "Test environment",
    "chef_type": "environment"
}
  • Specify the environment name in the .kitchen.yml file
provisioner:
  name: chef_zero
  client_rb:
    environment: "myenv"
  • Set the environment file location in the suite
suites:
  - name: default_envtest
    environments_path: "environments"

The node.chef_environment value will be “myenv” during the Test Kitchen run.

Using Makefiles

Makefiles are great to self-document frequently executed commands in a repository. They provide easy access to the bash code by easy to remember tags.

Formatting

Only tabs are allowed to indent lines. The indentation groups the commands under the rules.

Set Bash as the shell

On some systems Bash is not the default shell when Makefiles run. To set the shell add the line to the top of the Makefile:

SHELL := /bin/bash

Using pushd

Make executes every line in a new context. If you need to use pushd, popd you need to write all commands between them in one line separated with semicolons.

cluster-create:
	pushd ../terraform; terraform apply; popd

DevOps Engineering part 1. (Ubuntu server) – Install the DevOps development tools on Ubuntu server

Ubuntu server does not have a user interface, we will use the terminal to install the DevOps tools.

Terraform

  • On your workstation open a web browser and navigate to https://www.terraform.io/downloads.html to get the version of the latest Terraform release.
  • Substitute the x.x.x with the latest version
# Use the temp directory
cd /tmp

# Update the package repository
sudo apt-get update

# Install unzip
sudo apt-get install unzip

# Download the latest version of Terraform (substitute the x.x.x with the latest version)
wget https://releases.hashicorp.com/terraform/XX.XX.XX/terraform_XX.XX.XX_linux_amd64.zip

# Unzip the downloaded file (substitute the x.x.x with the latest version)
unzip terraform_XX.XX.XX_linux_amd64.zip

# Move the executable to a directory in the path
sudo mv terraform /usr/local/bin/

# Check the installed version
terraform --version

AWS CLI

To install AWS CLI with the package manager.

# Update the package repository
sudo apt-get update

# Install aws cli
sudo apt-get install awscli

# Check the version
aws --version

Update AWS CLI to the latest version

Older versions of the AWS CLI do not contain the EKS tools, you may get the error message:
Invalid choice: ‘eks’, maybe you meant:

To update AWS CLI

# Install Pip
apt install python-pip

Using the Windows Subsystem for Linux (WSL)

Sharing files between Windows Subsystem for Linux and Windows

Access the Windows files from Linux

  • Start WSL
  • In the terminal navigate to the /mnt directory
cd /mnt
  • The drives are mounted to sub-directories
root@P70:/mnt# ls -l
total 0
drwxrwxrwx  c
drwxrwxrwx  d

Access the Linux files from Windows

  • Start the WSL application in Windows 10 (in this case with the Ubuntu distro)
  • Open Windows Explorer in Windows 10
  • Navigate to \\wsl$

Enable copy/paste

To enable copy/paste in the default WSL terminal

  • Right-click the top bar and select Properties
  • On the Options tab check Use Ctrl+Shift+C/V as Copy/Paste
  • You can also enable a larger command history buffer.

Build a Docker container image for your application

Create the image

A Docker container image is one of the best formats to distribute your application. The container provides an immutable environment, so the application runs the same way on your workstation and on any server.

We will use the simple Go application we have created in the Your first Go application post. In the main application directory open the text editor and create the Dockerfile

code Dockerfile

We will create a multi-stage build script. The advantage is that the final image is very small, as it only contains the compiled Go application, not the source code, not even the Go compiler. Enter the code

FROM golang:alpine as builder

WORKDIR /src

COPY . /src

RUN go build -o myapp cmd/myapp/*

FROM alpine:3.11.3

 WORKDIR /app

 COPY --from=builder /src/myapp /app

 ENTRYPOINT ["/app/myapp"]

Build the image

docker build -t myapp .

Check the image. myapp should be the image on the top

docker images

The output should be something like this

REPOSITORY        TAG        IMAGE ID            CREATED           SIZE
myapp             latest     267e26010d88        2 minutes ago     7.66MB

Run the image to test it.

docker run --rm -it myapp

If you want to run the image with Docker Compose create a compose file

code docker-compose.yml

Enter the code

version: '3'

services:
  myapp:
    image: myapp

Run the image in Docker Compose

docker-compose up

The output should be

Creating network “myapp_default” with the default driver
Creating myapp_myapp_1 … done Attaching to myapp_myapp_1
myapp_1 | Application config
myapp_1 | MyPackage running
myapp_myapp_1 exited with code 0

Runt the image in Docker Swarm

Initialize the Docker Swarm

docker swarm init

Run the container in the swarm

docker stack deploy -c docker-compose.yml myapp

The output should be

Creating network myapp_default
Creating service myapp_myapp

Check if the stack is running

docker stack ls

The output should be

NAME                SERVICES            ORCHESTRATOR
myapp               1                   Swarm

Check if the service is running

docker service ls

Remove the stack

docker stack rm myapp