Switching to a new Chef server

The administrator of the Chef organization

Download the validation key

Do this only once for the organization.

This step resets the validation key, so the existing server images will not be able to connect to the Chef organization.

  1. On the Administration tab on the left select Organizations > Reset validation Key
  2. Click the Reset Key button,
  3. This is the only time you are able to download the validator key. Click the Download button to save it on your workstation.

Every user

Download your personal key from the server and configure knife. See DevOps Engineering part 4. – Connect to the Chef server

Upload all cookbooks to the new Chef server

  1. Copy all cookbooks to the new chef directory
  2. Open a terminal in the cookbooks directory and start to upload all cookbooks
    knife cookbook upload --all --freeze --force
  3. When you get the message

    ERROR: Cookbook XXX depends on cookbooks which are not currently
    ERROR: being uploaded and cannot be found on the server.
    ERROR: The missing cookbook(s) are: ‘YYY’ version ‘>= 0.0.0’, ‘ZZZ’ version ‘>= 0.0.0’

    1. Change to that XXX cookbook directory and execute
      berks upload
  4. Repeat step 3 until all cookbooks have successfully uploaded to the server.

Upload the environment files

  1. Open a terminal in the environments directory.
knife environment from file qa.json uat.json prod.json

Upload the data bags

  1. Open a terminal window in the data-bags directory and upload the data bags.
knife data bag create MY_DATA_BAG
knife data bag from file MY_DATA_BAG MY_DATA_BAG/MY_ITEM1.json
knife data bag from file MY_DATA_BAG MY_DATA_BAG/MY_ITEM2.json
knife data bag from file MY_DATA_BAG MY_DATA_BAG/MY_ITEM3.json

 

 

MySQL Installation

To install the MySQL database server, download the installer from https://dev.mysql.com/downloads/

  1. Download the MySQL Community Server from https://dev.mysql.com/downloads/
  2. On the Generally Available (GA) Releases tab select the operating system and click the Go to Download Page button,
  3. Click the Download button next to the web or offline installer,
  4. If you don’t want to register at Oracle, click the No thanks, just start my download link,

On Windows

Install the Visual C++ Redistributable Packages for Visual Studio 2013

  1. In your web browser navigate to https://www.microsoft.com/en-us/download/details.aspx?id=40784
  2. Download both 32 and 64-bit packages
  3. Install both packages. The 64-bit package requires a reboot after installation.

Install MySQL

  1. Execute the downloaded MySQL installer.

Migrate a WordPress web site to DreamHost

DreamHost is one of the recommended WordPress hosting providers. The DreamHost website has an extensive knowledge base, but the necessary steps to move your live site from another provider are scattered over multiple pages at https://help.dreamhost.com/hc/en-us/articles/214693178-How-to-manually-migrate-WordPress-to-DreamHost.

These steps will guide you through the streamlined migration process.

At your old provider

Create a site and database backup of your site at the old provider and save them on your workstation.

At DreamHost

Create an account at DreamHost.

If you arrive at the DreamHost site from https://www.cnet.com/web-hosting/ you get 50% discount on your initial hosting plan terms. The price will increase to the regular amount when you renew your hosting contract after 1 or 3 years.

It can take DreamHost an hour to activate your account. You can log into the control panel, but you have to wait for the account activation to be able to set up your site.

Create a fully hosted site

  1. In the DreamHost Panel select DOMAINS, Manage Domains and click the Add hosting to a Domain / Sub-Domain button
  2. Enter the name of your domain, select Remove WWW:… , and make a note of the Web username and Web server name.  When you will upload the site, make sure you use the newly created Web username and Web server (+.dreamhost.com) with the SFTP protocol. (FTP will be disabled for that user). When you save your changes, the new username and password will display on the screen. Click the Fully host this domain button.

  3. DreamHost creates a directory for the new user in the home directory on the web server and a subdirectory for the website.

Temporary domain name

If you want to keep your existing domain name at the original location until the new site goes live at DreamHost,  create a free temporary subdomain, MYDOMAIN.dreamhosters.com

  1. Return to the Manage Domains page and click the Add Hosting to a Domain / Sub-Domain button again,
  2. Scroll down to the Mirrored section. Enter a sub-domain name using dreamhosters.com, select your site from the drop-down, and click the Mirror this domain button.
  3. Open a web browser and navigate to MYDOMAIN.dreamhosters.com. You should see this page:

Create a MySQL database

  1. On the left side select GOODIES and MySQL Databases
  2. If you use the temporary domain name, you need to use it for the database hostname too. If you move an existing WordPress site, for the easier configuration, you can keep the same database name, username, and password that you had at the old site.
  3. Update the wp-config.php file on your workstation with the new values. Even if you keep the database name, username, and password values, the DB_HOST will be different, because the site is now at a different provider.
    define('DB_HOST', 'mysql.MY_DOMAIN_NAME.dreamhosters.com');

Import data into your database

  1. On the left side select GOODIES, MySQL Databases, and in the middle select phpMyAdmin next to the database name
  2. Make sure the SQL script on your workstation starts with the database selection command. If the instruction is missing, add the line:
    USE MY_DATABASE_NAME;

    For some reason, the MySQL Workbench cannot interpret the encoding of the SQL file, use a better text editor to edit the file, otherwise international characters in the data will be corrupted.

    The Microsoft SQL Server Management Studio is perfect for this purpose.

  3. On the Import tab click the Choose File button to select the database backup SQL file on your workstation and click the Go button

Update the site URL in the database to match the temporary website address

With the user interface

On the phpMyAdmin web page

  1. Select the Browse tab, on the left side select your WordPress database, and in the database click the wp_options table.
  2. Click the Edit link in the siteurl row. This will automatically open the Insert tab,
  3. Update the siteurl value in the wp_options table and click the Go button,

  4. Do the same with the home row.

With an SQL query

update MY_DATABASE_NAME.wp_options set option_value = 'http://MY_SITE_URL' where option_name = 'siteurl'
update MY_DATABASE_NAME.wp_options set option_value = 'http://MY_SITE_URL' where option_name = 'home'

Upload the WordPress site files to the new web server

Use an FTP client to upload the files to the site. The site host user only has SFTP rights, so make sure you configure your FTP client accordingly. Use the web address, username, and password that you used, when you set up the fully hosted website above.

To rebalance the load between their web servers, DreamHost time-to-time moves websites from one server to the other. Use the subdomain we created above, to access the FTP directory, as it will always point to the correct web server.

  1. If you use FileZilla, create a new site for the web user, and select the SFTP protocol,
  2. Make sure you update the wp-config.php file with the new database connection values, and upload it to DreamHost,

Test your new site

The home page of the new site should be accessible at the MYDOMAIN.dreamhosters.com address we created above.

When you click on any of the post titles, you may get the following error message

Not Found

The requested URL /archives/… was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Update the permalinks

The WordPress database still contains the absolute locations of your HTML files and images. To refresh the permalinks of your site

  1. Log into your WordPress site,
  2. On the left side select Settings, Permalinks, and click the Save Changes button.
  3. After a few seconds the site should start to work.

Point your domain name to the new site

When you have successfully tested your new site, you can point your domain name to the DreamHost webserver. The DreamHost knowledge base will help you at https://help.dreamhost.com/hc/en-us/articles/215412347-Updating-your-DNS-after-your-WordPress-site-has-been-migrated-to-DreamHost

IMPORTANT: If you use your domain name to connect to Office 365 or other services, do not switch to the DreamHost name servers. Use “Option #2 — Pointing your A records” on the DreamHost knowledge base page above, to set the IP address of your website in the DNS record.

Configure WordPress to use the final domain name

To be able to test our site with the temporary subdomain we have updated the database. Now it is time to change the value back.

  1. Open the MySQL management utility
  2. Select the Browse tab, on the left side select your WordPress database, and in the database click the wp_options table.
  3. Click the Edit link in the siteurl row. This will automatically open the Insert tab,
  4. Update the siteurl value in the wp_options table and click the Go button,
  5. Do the same with the home row.

With an SQL query

update MY_DATABASE_NAME.wp_options set option_value = 'http://MY_SITE_URL' where option_name = 'siteurl'
update MY_DATABASE_NAME.wp_options set option_value = 'http://MY_SITE_URL' where option_name = 'home'

Test your site with your domain name

The home page of your WordPress site should load without error. If you get the error again:

Not Found

The requested URL /archives/… was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Update the permalinks again. See Update permalinks above

Waiting for SSH service on …:22, retrying in 3 seconds

When you try to launch a new EC2 instance in AWS using Chef Test Kitchen and the process times out with the message:

  Waiting for SSH service on …:22, retrying in 3 seconds

$$$$$$ [SSH] connection failed, terminating (#<Net::SSH::AuthenticationFailed: Authentication failed for user …@…>)
>>>>>> ——Exception——-
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>> Failed to complete #create action: [SSH session could not be established] on default-rhel7
>>>>>> ———————-
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose –all` for configuration

Check the access to the “ssh_key” which is specified in the platforms: driver: transport: section of the .kitchen.yml file.

The .pem file should be accessible from the cookbook directory with the absolute or relative path.

Failed to complete #create action: [undefined method `version’ for nil:NilClass] on …

When you execute kitchen converge to launch an EC2 instance in AWS with Chef Test Kitchen, you get the error message:

>>>>> ——Exception——-
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>> Failed to complete #create action: [undefined method `version’ for nil:NilClass] on …
>>>>>> ———————-
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose –all` for configuration

Test Kitchen cannot detect the operating system

The kitchen-ec2 driver tries to read the operating system version from the name of the image, but it cannot find it.

When you create your own AMI (Amazon Machine Image), make sure the version of the operating system is in the name.

The Test Kitchen Git repository has the following at https://github.com/test-kitchen/kitchen-ec2

Note that the image_search method requires that the AMI image names be in a specific format. Some examples are:

  • Windows-2012
  • Windows-2012r2
  • Windows-2012r2sp1
  • RHEL-7.2

It is safest to use the same naming convention as used by the public images published by the OS vendors on the AWS marketplace.

An acceptable name is my_windows-2012r2_base-1

Could not load the ‘ec2’ driver from the load path

When you execute kitchen list and the driver in your .kitchen file is “ec2“, the following error message appears:

>>>> ——Exception——-
>>>>>> Class: Kitchen::ClientError
>>>>>> Message: Could not load the ‘ec2’ driver from the load path. Please ensure that your driver is installed as a gem or included in your Gemfile if using Bundler.
>>>>>> ———————-
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose –all` for configuration

If you have recently installed the Chef Development Kit, you need to install the Kitchen EC2 driver to be able to launch servers in AWS.

To install the Kitchen EC2 driver, execute

chef gem install kitchen-ec2

 

Could not load the ‘vagrant’ driver from the load path

When you execute the kitchen converge command to launch a virtual machine on your workstation with the Vagrant driver, you may get the error message:

>>>>> ——Exception——-
>>>>>> Class: Kitchen::ClientError
>>>>>> Message: Could not load the ‘vagrant’ driver from the load path. Please ensure that your driver is installed as a gem or included in your Gemfile if using Bundler.
>>>>>> ———————-
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose –all` for configuration

An additional Ruby installation on your workstation besides the version came with the Chef Development kit can cause this.

To force Test Kitchen to use the Ruby instance that was installed with the Chef Development kit start your commands with chef exec:

 chef exec kitchen list

To check the Ruby installations on your workstation, execute

which ruby

The path should be

/usr/local/bin/…
or
/opt/opscode/…

If the result is something else, uninstall the extra Ruby version.

If you use the Ruby Version Manager (RVM), uninstall the current ruby version, then uninstall RVM. See https://richonrails.com/articles/uninstalling-rvm

Reinstall the Chef Development Kit, which will install the recommended Ruby version on your workstation.

If you get the Vagrant error message:

Vagrant failed to initialize at a very early stage …

 

follow the recommended steps on the screen to reinstall the Vagrant plugins.

Vagrant installation

 Vagrant Installation

Warning!

The new versions of Vagrant delete the contents of the /opt/vagrant directory. If you want to keep old versions of Vagrant, first move them out of the /opt directory.

  • Download Vagrant from https://www.vagrantup.com/ and follow the instructions to install it.
  • Select DOWNLOAD…
  • Select the operating system of your workstation. For
    • Ubuntu: Debian
    • RedHat: Centos

 

Keep multiple versions on your workstation

Vagrant has an installer, that places the bin and embedded folders to “/opt/vagrant”. To be able to keep multiple versions of Vagrant execute the following:

cd /opt/vagrant
sudo chown -R MY_USER_NAME:wheel /opt/vagrant # Change the owner of the 'vagrant' directory structure from root to you so you can move the folders mkdir vagrant_MY_VERSION # Create a subfolder for the new version mv bin vagrant_MY_VERSION # Move the folder to the version specific location mv embedded vagrant_MY_VERSION # Move the folder to the version specific location rm vagrant # Delete the old version of the symbolic link ln -s /opt/vagrant/vagrant_MY_VERSION/bin/vagrant vagrant # Create the symbolic link for the new version

Important

The default credentials of a Vagrant machine are:

  • UserName: vagrant
  • Password: vagrant

Windows in Vagrant

To test your cookbook on a Windows virtual machine locally, create one for Vagrant. See Launch Windows instances locally with Chef Test Kitchen for the details.

Ubuntu gets stuck in a login loop

When I rebooted my Ubuntu machine it started to repeatedly ask for the password.

When I entered the correct password, the screen went black and asked for the password again.

The problem was an error in the ~/.profile file.

To log into the Ubuntu terminal

  1. Press the Ctrl-Alt-F3 key combination
  2. Enter the username
  3. Enter the password
  4. Open the ~/.profile file with
    /bin/nano ~/.profile

Make sure the

  • The syntax is correct, all open braces are closed,
  • All PATH= statements have :$PATH at the end.

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

DevOps Software installation on Ubuntu

There are multiple ways to install software on Ubuntu

  • Install a .deb package from the local drive with dpkg
  • Install the software from the internet with apt

Show hidden files

To be able to see hidden files in Files

  1. Start Files,
  2. In the Edit menu select Preferences,
  3. On the Views tab check the Show hidden and backup files,
  4. There is no Save or Ok button, just close the window to save the changes.

Text Editor

Atom

  1. Download the .deb installer from https://atom.io/
  2. Start the terminal by pressing CTRL-ALT-T
  3. Navigate to the Downloads directory
    cd ~/Downloads
  4. Install Atom
    sudo dpkg -i atom-amd64.deb
  5. Add an icon to the desktop
    1. Install the Gnome Panel, but do not install the unnecessary packages
      sudo apt-get install --no-install-recommends gnome-panel
    2. If the message is

      You might want to run ‘apt-get -f install’ to correct these:The following packages have unmet dependencies:…

      1. Execute
        apt-get -f install
    3. Create a new launcher on the desktop
      gnome-desktop-item-edit --create-new ~/Desktop
    4. Enter a name and command for the shortcut,
    5. To select an icon, click the image in the upper left corner and select an icon, and click Open,
    6. Unfortunately, Ubuntu does NOT update the icon in the window, click OK to save the shortcut.

To configure Atom see Atom text editor configuration

The preferences menu item in Linux is in the Edit menu of Atom.

 

Git

  1. Open the Terminal window
  2. Execute
    sudo apt-get install git

Configure Git

To configure Git see Git configuration.


Chef Development Kit

  1. Download the Chef Development Kit from https://downloads.chef.io/chef-dk/
  2. Click the Download button next to your Ubuntu version, and select Save File,
  3. Start the terminal by pressing CTRL-ALT-T
  4. Navigate to the Downloads directory
    cd ~/Downloads
  5. Install the Chef DK. Set the name of the file below for the actual version.
    sudo dpkg -i chefdk_CHEF_DK_VERSION-1_amd64.deb

Vagrant

Important

The default credentials of a Vagrant server are:

  • UserName: vagrant
  • Password: vagrant

Terraform by Hashicorp

 Terraform Installation

  1. Download Terraform from https://www.terraform.io/downloads.html
  2. Click the Linux 64-bit link, and select Save File,
  3. Open the Downloads folder in Files,
  4. Right-click the downloaded ZIP file and select Extract Here to extract the application
  5. Create a version specific directory, terraform_x.x.x for the Terraform application in the /opt/terraform folder
  6. Move the Terraform application into the version specific directory

Add Terraform to the path

  1. In the terminal window execute
    gedit ~/.profile
  2. Add this line to the end of the file
    PATH="/opt/terraform:$PATH"

AWS CLI

The Amazon Web Services command line interface installation will set up your workstation to launch instances in AWS from Test Kitchen. If you know you will work with AWS, see DevOps Engineering part 3. – Working with AWS for the AWS CLI installation.


Packer

We use Packer to create custom AWS AMIs that contain the fundamental configuration and applications that are common in every instance we launch.

Install Packer

  • Add the Packer installation directory to the system path