`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.

 

Serialize SSH and RSA private keys to store them in 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 inline.

Use base64 encoding

Base64 encoding converts binary data to ASCII format to represent special characters, like line breaks as ASCII text. The result will be larger, 8 / 6th of the original size, as every 8 bit ASCII character only represents 6 bits of data.

To convert a file to base 64 and save it as another file

cat test.pem | base64 > test.pem.base64

If we need the result on the computer’s clipboard to paste it into a field on the screen

cat test.pem | base64 | pbcopy

To use the encoded string we need to decode it in the Chef cookbook.

Replace the newline characters with \n

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

In Atom

on Mac and Windows

  1. Open the RSA key file in Atom,
  2. Press Command-F on Mac, Ctrl-F on Windows to open the Find and Replace window,
  3. On the right side click the Use Regex button,
  4. In the search field enter
    \r\n
  5. In the replace with field enter
    \\n
  6. Press the Replace All button

In Visual Studio Code

on Mac and Windows

  • Press Command-F on Mac, Ctrl-F on Windows to open the Find dialog
  • Select the Use Regular Expression button
  • Enter \n into the find, \\n into the replace field

In Notepad++

on Windows

  • 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 ( if the key was generated on a Windows computer using GitBash, search for \n )
  • Enter \\n  to the Replace with text box
  • Press the Replace All button

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

HTTP Request Returned 409 Conflict: Client already exists

The Chef server maintains the list of registered nodes and clients in its database.  When you launch a new instance with Chef you may encounter the following error message:

*** Input CHEF_CLIENT_NODE_NAME is undefined, using: IP-0AFE6965
...
*** Starting chef-client
*** Finished chef-client
Printing Log
...
[...] INFO: Client key C:\chef\client.pem is not present - registering
[...] INFO: HTTP Request Returned 409 Conflict: Client already exists
[...] INFO: HTTP Request Returned 403 Forbidden: error
[...] ERROR: Running exception handlers
[...] ERROR: Exception handlers complete
[...] FATAL: Stacktrace dumped to C:/chef/cache/chef-stacktrace.out
[...] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[...] FATAL: Net::HTTPServerException: 403 "Forbidden"

Cause:

In this case the CHEF_CLIENT_NODE_NAME already exists in the client database.You can search for it from a Bash window.

Solution:

Add a line to the Chef configuration to remove the existing node with the same node name

If you use Terraform to launch server instances and configure Chef, add this line to the Chef provisioner:

recreate_client = true

To delete nodes from the Chef server:

Use the knife command to search for the existing node from a Bash window.

To find the node in the Chef server database

knife search node '*:IP-0AFE6965'

To find the client in the Chef server database

knife search client '*:IP-0AFE6965'

If any of them found, those are leftovers from a previous launch. AWS reuse the IDs, so you have to remove the nodes from the Chef server database when you terminate the instances. To delete the unnecessary entries use the following commands:

knife node delete 'IP-0AFE6965'
knife client delete 'IP-0AFE6965'

To remove the terminated instances from the Chef server database you can also use the Chef web interface.

  • On the Nodes tab enter the IP address of the instance into the search box and hit Enter
  • In the Actions column click the down arrow next to the instance and select Delete

How to edit the GitHub README.md file

The GitHub repositories usually contain a README.md file to describe how to use the project. The GitHub web site has a simple editor, but it has a few limitations

  • If you accidentally refresh the page, you lose your changes,
  • The preview pane is wider than the page that will display your file, so the formatting can be different,
  • You have to switch between the editor and the the preview every time you want to see the result.

One of the simplest ways to edit the README.md is to use the Atom editor.

  • Open the README.md file with Atom,
  • In the Packages menu select Markdown Preview, or press Ctrl-Shitft-M to open the preview pane.

As you type in the editor window the preview pane will show the live review of the file.

For the Markdown syntax visit https://guides.github.com/pdfs/markdown-cheatsheet-online.pdf

An error occurred while signing

When you deploy and application in Microsoft Visual Studio with ClickOnce, you need to sign the installer with a key.

To sign the project Visual Studio needs to use the signtool. If the ClickOnce feature is not enabled in Visual studio, it displays the following error message:

An error occurred while signing: SignTool.exe was not found at path C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\signtool.exe

To install the ClickOnce feature and the signtool

On Windows 7

  • In Windows Control panel select Programs and Features,
  • Right click Visual Studio 2015 and select Modify,
  • In the feature list select ClickOnce tools.

On Windows 10

  • In Windows Control Panel select System,
  • On the left side select Apps & features,
  • In the app list click Microsoft Visual Studio 2015,
  • Click the Modify button,
  • In the Visual Studio setup click the Modify button again,
  • In the feature list select ClickOnce Publishing Tools.

 

Troubleshooting

When you have been able to successfully sign your Click Once applications in the past and suddenly you get the error message

An error occurred while signing: Failed to sign bin\Debug\app.publish\….exe. SignTool Error: No certificates were found that met all the given criteria.

it is possible that the certificate you used to sign your app has expired. To check the validity of the certificate

  1. In Visual Studio open the project’s properties page,
  2. On the Signing tab check the expiration date of the certificate.

Create a new certificate

To create a new certificate

  1. On the Signing tab of the project properties page click the Create Test Certificate button,
  2. Enter a password for the new certificate.
  3. Click the down arrow next to the key file name and select the new key file in the dropdown list.
  4. Save the project file and build your application.

 

 

 

No mapping specified for instances of the EntitySet and AssociationSet in the EntityContainer

When you move your Visual Studio solution to another workstation you may encounter the following error message:

System.Data.Entity.Core.MappingException was unhandled by user code
HResult=-2146232032
Message=Schema specified is not valid. Errors:
: error 2062: No mapping specified for instances of the EntitySet and AssociationSet in the EntityContainer …
Source=EntityFramework

 

In this case it may help if you re-import the database objects into the .edmx file.

To import all objects again:

  • Open the .edmx file,
  • Press the Ctrl-A keys to select all tables in the diagram,
  • Press the delete key on the keyboard to delete all tables,
  • Right click the white area and select Model Browser,
  • In the Model Browser expand the {model name}.Store, and the Stored Procedures / Functions element
  • Delete all functions and stored procedures
  • In the {model name} element (the element above the {model name}.Store) expand the Function Imports element
  • Delete all function imports
  • Save the .edmx file
  • Right click the white area of the .edmx file and select Update Model from Database
  • Select all necessary tables, stored procedures, and functions and import them.

If you re-import the tables, but do not delete the stored procedures, functions, and function imports you may get the following error message:

HResult=-2146233079
Message=The function import ‘Tobacco_WebEntities.spGetAgeGroupId’ cannot be executed because it is not mapped to a store function.
Source=EntityFramework