How to migrate the DevOps development environment to another workstation

Terraform

Copying Terraform scripts from a Windows workstation

If the Terraform scripts reference modules, terraform creates symbolic links to those modules in the .terraform/modules directories. When you try to copy those symbolic links on a Windows machine the copy process stops. To copy the Terraform scripts

  • Start Windows explorer in the folder above the Terraform script folders,
  • Search for .terraform,
  • In the search result list delete the .terraform folders.

DevOps Engineering part 1. (Mac) – Install the DevOps development tools on Macintosh

Set up your computer

Lock the screen

To be able to lock the screen from the menu bar:

  • In Finder search for Keychain Access and start it,
  • In the Keychain Access menu select Preferences,
  • Check the Show keychain status in menu bar checkbox,
    This will place a lock icon in the menu bar.

To lock your screen

  • Click the lock icon on the menu bar
  • Select Lock Screen

Show hidden files and folders

  • Open the terminal and execute the following line
    defaults write com.apple.finder AppleShowAllFiles YES
  • Press the ‘Option/alt’ key, right click on the Finder icon in the dock and click Relaunch

Apple Id

If you don’t have an Apple ID create one. You can obtain one without a credit card:

  • Start iTunes on your Macintosh,
  • Click the drop down menu in the upper right corner,
    apple-id-01
  • If Apps is visible, select it, otherwise click Edit Menu…
    • Select Apps to display it in the drop down.
      apple-id-02
  • Search for a free app in the App Store and start to download it,
    apple-id-03
  • Create a new Apple Id and select None for credit card type.

Show the user home directory

  • Open Finder
  • In the Finder menu select Preferences
  • In the Favorites section select the checkbox next to your user name
    show-home-directory

Create a directory for optional applications

Create the opt folder in the root of the harddisk.

Homebrew

Homebrew can install packages on your Macintosh that apple does not provide.

Installation instructions are at http://brew.sh/

Remote Desktop Client

Download the Microsoft Remote Desktop app from the App Store

  • Open the App Store
  • Search for “microsoft remote desktop”
  • Click the Microsoft Remote Desktop icon
  • Click the blue Get button
  • Click the green Install App button

Text Editor

Atom

  • Download it from https://atom.io/
  • Double click the downloaded ZIP file to extract the application,
  • Drag the Atom application into Applications

Terminal Window

iTerm2

Install iTerm2, a smart terminal emulator to issue Bash commands and log into Linux servers.

iTerm2 configuration

Enable unlimited scroll back

  • Start iTerm2 and open the preferences window by pressing ⌘, (command-comma)
  • On the Terminal tab click the Unlimited scrollback check box.

Start iTerm2 from Finder

To be able to open iTerm2 in any folder from Finder follow the steps below based on https://gist.github.com/shuntaroy/e5ce3ad61c0deb7e27f0

  • Start Automator,
  • On the top of the screen set Service receives selected to files and folders,
  • Set in to Finder,
  • On the second side bar from the left double click Run AppleScript,
  • Paste the code from the website referenced above into the editor window replacing the sample script in the editor window,
  • In the File menu save the script,
  • Do not run it, it does not execute in the Automator.
To use it
  • Open Finder and navigate to the location you want to work in,
  • Right click a folder to work in that folder or a file to work in the current folder
  • Select Services, iTerm2 in Finder


 

“Solarized” color scheme

  • Download the color scheme to the Desktop with the following Bash command:
    curl -o ~/Desktop/solarized.itermcolors https://raw.githubusercontent.com/altercation/solarized/master/iterm2-colors-solarized/Solarized%20Dark.itermcolors
  • Import the color scheme to iTerm2
    • Press ⌘, (command-comma) to open the Preferences window
    • Select Profiles
    • In the lower right corner of the Colors tab click the Color Presets… drop down
    • Select Import
    • On the Desktop select the downloaded solarized.itermcolors file
    • In the  Color Presets… drop down select Solarized Dark

 Meslo Powerline font

  • Import the Meslo Powerline font with the following bash command:
    git clone https://github.com/powerline/fonts.git && cd fonts && ./install.sh
  • Select the font in iTerm2
    • Press ⌘, (command-comma) to open the Preferences window
    • Select Profiles
    • On the Font section of the Text tab click the Change Font button
    • Select the 12pt Meslo LG L Regular for Powerline

Make the prompt shorter

to remove your username@computername from the prompt

  • Edit the ~/.zshrc file
  • Add the following line
    DEFAULT_USER="YOUR_USER_NAME"

Colored prompt

To color the prompt:

  • Download the agnoster theme
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
  • Edit the ~/.zshrc file and set the ZSH_THEME to ZSH_THEME=”agnoster”

More configuration suggestions are at

https://ruigomes.me/blog/perfect-iterm-osx-terminal-installation/
https://gist.github.com/kevin-smets/8568070

Information on how terminals read settings at https://shreevatsa.wordpress.com/2008/03/30/zshbash-startup-files-loading-order-bashrc-zshrc-etc/

Git

  • Navigate to https://git-scm.com/download/mac to download Git for Windows. The page automatically downloads the installer for the operating system you use.
  • This app is not trusted by Apple, so to install it
    • Control-click the downloaded file and select Open
    • Click the Open button to confirm the action

Configure Git

If you use two factor authentication

Create a Personal Access Token to use it as password in the command line tools,

  • Log into GitHub and in the pull down at the upper right select Settings,
  • On the left select Personal access tokens and click the Generate new token button,
  • Enter a description for your token (so you can keep track and revoke them individually later, should you have a security breach),
  • Select all options to be able to use the token for administration,
  • Click the Generate button,
  • Copy the token (40 characters long) and use that as your password on the command line.git

Move the Git repositories to a new workstation

If you want to move Git repositories to your new workstation

  • Commit and push all repositories to GitHub on the old workstation
  • Copy the folders from your old workstation to the new
  • Execute the following command in all Git repositories on the new workstation
    git reset --hard

Virtual Box

Download Virtual Box from https://www.virtualbox.org/wiki/Downloads and follow the instructions to install it.

At the time of writing this was the section where the installer files were referenced

virtual-box-01-download

Run the downloaded installer file and accept all default values.

The installer starts the application. You can close it, we will use other tools to start it in the future.

Vagrant

Important

The default credentials of a Vagrant server are:

  • UserName: vagrant
  • Password: vagrant

Ruby

Ruby is already a part of the operating system.

Chef Development Kit

Terraform by Hashicorp

 Terraform Installation

  • Download Terraform from https://www.terraform.io/downloads.html
  • Double click the downloaded ZIP file to extract the application
  • Create a directory, terraform for the Terraform application in the /opt folder
  • Move the Terraform application into the terraform directoryin the /opt folder

Add the location to the path

Depending on the terminal window you use, it may open different configuration files. If you use iTerm2 you need to update the path in the~/.zshrc file.  Other terminal windows usually read the configuration from the  ~/.bash_profile file. To be safe you can add the following to both configuration files:

# PATH Export
PATH=/opt/terraform:$PATH
export PATH
unset DYLD_LIBRARY_PATH

Graphviz

Graphviz is a Dependency Graph Visualization Software. We will use this utility to display the Terraform graphs.

To install execute the following in the terminal

brew install graphviz

Next:

Set up the DevOps development environment in Beginner’s Guide to DevOps Engineering part 2.

Back:

to the Tutorials page

DevOps Engineering part 1. (Win) – Install the DevOps development tools on Windows

Set up your computer

Display the file extensions

In Windows 10

  • Open Windows explorer
  • On the View tab select
    • File name extensions
    • Hidden items
      windows-03-show-file-extensions

In Windows 7

  • Open Windows Explorer and select Organize
  • Select Folder and search options
    windows-02-show-file-extensions
  • On the View tab
    • Select Show hidden files, folders, and drives
    • Uncheck Hide extensions for known file types
      windows-01-show-file-extensions

Text Editor

Notepad ++

Install a good text editor. If you do not have a favorite, I recommend Notepad ++

Configure Notepad ++

Tab settings

  • In the Settings menu select Preferences
  • In the Tab Settings section set the Tab size to 2 and select Replace by space
    tab-settings-01

Git

  • Navigate to https://git-scm.com/download/win to download Git for Windows. The page automatically downloads the installer for the operating system you use.
  • Install the application
  • Accept the default values, including these:
    • Make sure the Windows Explorer integration for Git Bash is checked.
      git-for-windows-01-intergration
    • Enable the Git tools in the command prompt too
      git-for-windows-02-command-prompt
    • Line endings for Windows computers
      git-for-windows-03-line-endings
    • Terminal emulator
      git-for-windows-04-terminal
    • Caching
      git-for-windows-05-caching
    • Finish the installation
      git-for-windows-05-finish

Configure Git for Windows

Enable Page Up and Page Down

  • In Windows Explorer right click in the white area and select Git Bash Here,
  • Stretch the Bash window to the full width of the page to have more room to work later,
  • Right click the Bash window and select Options…,
  • On the Window tab,
    • Click the Current size button to save the size,
    • Select PgUp and PgDn scroll without modifier to be able to scroll quickly up and down in the window with the Page up and Page down buttons.
      bash-04-window

Set up Git Bash to always run as Administratort

Certain commands need elevated rights to run, so we will set up the Bash window to run as administrator.

  • In Windows 7 click the Windows Start button and type bash
    bash-01-admin
  • Right click the found link and select Properties
    bash-02-admin
  • On the Compatibility tab select Run this program as administrator
    bash-03-admin

Virtual Box

Download Virtual Box from https://www.virtualbox.org/wiki/Downloads and follow the instructions to install it.

At the time of writing this was the section where the installer files were referenced

virtual-box-01-download

Run the downloaded installer file and accept all default values.

The installer starts the application. You can close it, we will use other tools to start it in the future.

Vagrant

Important

The default credentials of a Vagrant server are:

  • UserName: vagrant
  • Password: vagrant

Ruby

  • Download Ruby from http://rubyinstaller.org/downloads
  • Install the 32 bit version, as the 64 bit version is fairly new and has compatibility issues. Download the latest Ruby installer. Pick the file that does not have the (x64) at the end.
  • Accept the default values but check Add Ruby executables to your PATH
    ruby-01-add-to-path

 Ruby Development Kit

The Ruby Development Kit is need for certain Ruby gems, so install it.

  • Download the Ruby Development Kit from the DEVELOPMENT KIT section of  http://rubyinstaller.org/downloads
  • If you have installed the 32 bit version of Ruby make sure you install the 32 bit version of the DevKit. Select the Development kit that matches the Ruby version you installed. At the time of writing the latest development kit is under “For use with Ruby 2.0 and above (32bits version only)
    • Run the installer to extract it to a permanent location (C:\RubyDevKit)
    • Open a command window in the C:\RubyDevKit folder
    • Run these commands in the command prompt to install it.
      • ruby dk.rb init
      • ruby dk.rb install
  • For more information see  http://github.com/oneclick/rubyinstaller/wiki/Development-Kit

Chef Development Kit

Terraform by Hashicorp

Installation

  • Unzip the downloaded package to C:\HashiCorp\Terraform
  • Add the Terraform directory to the path of the computer. It is not added automatically on 64 bit Windows.
    • In Windows Explorer right click Computer and select Properties,
    • On the left side select Advanced System Settings,
    • At the bottom click the Environment Variables… button,
    • In the System Variables box select Path and click the Edit… button,
    • Add the following to the end of the Variable value. (Don’t forget to start with the semicolon as the separator).
      ;C:\HashiCorp\Terraform
  • To create RDS (Relational Database Service) instances in AWS, install the Amazon Web Services Command Line Interface (See instructions below)
  • Configure the GitBash window to run as administrator to be able to execute the “terraform get” command to get local modules during development
    • Right click the shortcut of the Bash window you use and select Properties
    • On the Compatibility tab check Run this program as an administrator

For more details see https://www.terraform.io/intro/getting-started/install.html

Graphviz

Graphviz is a Dependency Graph Visualization Software. We will use this utility to display the Terraform graphs.

  • Download from http://www.graphviz.org/Download..php
    There are really two dots in the address :-)
  • Execute the installer
  • You may need to add the location to the Path environment variable. Make sure you use the actual folder name, as it contains the version of the application.
    ;C:\Program Files (x86)\GraphvizX.XX\bin


Next:

Set up the DevOps development environment in Beginner’s Guide to DevOps Engineering part 2.

Back:

to the Tutorials page

Your session has timed out. Please try again. Code 5107

To download apps from the Apple Store you need an Apple Id. If the app is free, you may not want to enter credit card information during the registration. If you try to create the Apple Id without the credit card in the App Store application, you may get the following error message:

Your session has timed out. Please try again. Code 5107

To create the Apple Id without a credit card

  • Start iTunes on your Macintosh,
  • Click the drop down menu in the upper right corner,
    apple-id-01
  • If Apps is visible, select it, otherwise click Edit Menu…
    • Select Apps to display it in the drop down.
      apple-id-02
  • Search for a free app in the App Store and start to download it,
    apple-id-03
  • Create a new Apple Id and select None for credit card type.

`block in filter_instances’: undefined method `empty?’ for nil:NilClass (NoMethodError)

When you try to execute any of the “kitchen” commands in Chef Test Kitchen you may get the following error message.

lib/kitchen/config.rb:182:in `block in filter_instances': undefined method `empty?' for nil:NilClass (NoMethodError)

This happened in my cookbook, when I have removed the value from the “excludes:” option in the .kitchen.yml file, but left the “excludes:” option there alone.

To make your cookbook work in Chef Test Kitchen again, remove the empty “excludes:” option form the .kitchen.yml file

Failed to open file ‘…’ , error 2 and error 22

How to restore a MySQL database in Windows

To restore a MySQL database on a Windows machine:

  • Place the database backup file in the root directory of your C: drive (trust me, this will make your life easier)
  • Open the Command Prompt
  • Start the MySQL command prompt
  • mysql -u root -p

    This command will prompt you for the MySQL root password

  • Switch to the new database
    use db;
  • Import the database
    source C:/BACKUP_FILE_NAME.sql

    To avoid the Failed to open file ‘…’ , error 2 and error 22 error message
    You can have spaces in the name of the backup file, but not in the directory names in the path
    Do not use quotes around the file path
    Use forward slashes
    Do not end the command with semicolon (;)

The FastCGI process exited unexpectedly

When you install WordPress on a Windows machine you may get the following error message:

HTTP Error 500.0 - Internal Server Error
C:\Program Files (x86)\PHP\v5.5\php-cgi.exe - The FastCGI process exited unexpectedly

Detailed Error Information:
Module
 FastCgiModule
Notification
 ExecuteRequestHandler
Handler
 PHP55_via_FastCGI1
Error Code
 0x000000ff

The error message is misleading. If you open the Application events in the Event Viewer you may find the following

Faulting application name: php-cgi.exe, version: 5.5.38.0, time stamp: 0x578fc02c
Faulting module name: MSVCR110.dll, version: 6.3.9600.18233, time stamp: 0x56bb4e1d
Exception code: 0xc0000135
Fault offset: 0x0009d3c2
Faulting process id: 0xcec
Faulting application start time: 0x01d24603ad650d40
Faulting application path: C:\Program Files (x86)\PHP\v5.5\php-cgi.exe
Faulting module path: MSVCR110.dll

The key is the MSVCR110.dll

This DLL is part of the Visual C++ Redistributable for Visual Studio 2012 Update 4. Download the 32 bit version, even if you have a 64 bit operating system, from http://www.microsoft.com/en-us/download/details.aspx?id=30679

After the installation WordPress will start to work without reboot.

 

Add an RSA private key to a Chef Data Bag

To send RSA private keys to instances, store them in encrypted data bags. The data bag item is a JSON file that contains keys and values.

To place the multi-line RSA key into the value part of the JSON file, we need to replace the new line characters with “\n”

On a Windows  workstation we can use Notepad++ to do the replacement:

  • Open the RSA key file in Notepad++,
  • In the Search menu select Replace…,
  • Select Extended mode in the Search Mode section,
  • Enter \r\n to the Find what text box
  • Enter * (star) to the Replace with text box 
  • Press the Replace All button

rsa-key-in-data-bag-01

  • Select Normal in the Search Mode section,
  • Enter *  (star) to the Find what text box
  • Enter \n to the Replace with text box
  • Press the Replace All button

rsa-key-in-data-bag-02

You can place the single line key into any encrypted Data Bag file. See Data Bags on Data Bag encryption.