`pwd’: No such file or directory – getcwd (Errno::ENOENT)

When you rename a subdirectory under the directory where your Linux or MacOS terminal is open you may get the error message

/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.4.19/lib/chef/knife/cookbook_download.rb:45:in `pwd’: No such file or directory – getcwd (Errno::ENOENT)

You need to refresh the directory cache of the terminal.

  1. Go one level higher
    cd ..
  2. Go back to the directory
    cd MY_DIRECTORY

 

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

  1. Execute the downloaded 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

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,

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,

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 default…

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 default-windows-2012r2
>>>>>> ———————-
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose –all` for configuration

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:

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

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

  • 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
mkdir vagrant_MY_VERSION                                 # Create a folder for the new version
sudo chown -R YOUR_USER_NAME:wheel bin                   # Set the owner, so you can move it
sudo chown -R YOUR_USER_NAME:wheel embedded              # Set the owner, so you can move it
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

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.