How can I tell if a Chef cookbook is frozen

If a Chef cookbook is “frozen”, the cookbook is protected against accidental overwrite.

When someone tries to overwrite it the
Version ... of cookbook COOKBOOK_NAME is frozen. Use --force to override"
message appears.

To check if a Chef cookbook is frozen on the Chef server execute the following command
knife cookbook show COOKBOOK_NAME latest | grep frozen

To upload a Chef cookbook and freeze it to prevent accidental overwrite
knife cookbook upload COOKBOOK_NAME --freeze

To overwrite a frozen cookbook upload it with
knife cookbook upload COOKBOOK_NAME --force

To freeze the referenced cookbooks when you upload them with BerkShelf upload them with
berks upload
(do not use the –no-freeze option)

REMOTE HOST IDENTIFICATION HAS CHANGED warning when you try to connect to a server with ssh

If you work in the AWS environment and  launch and terminate servers frequently the same IP is reused many times. When you try to connect to a new server with SSH and the IP address is already in the known_hosts file you will get the following error message.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:...
Please contact your system administrator.
Add correct host key in /c/Users/.../.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /c/Users/.../.ssh/known_hosts:13
ECDSA host key for ... has changed and you have requested strict checking.
Host key verification failed.

The solution is to delete the line from the “c:/Users/YOUR_USER_NAME/.ssh/known_hosts” file that has the same IP address as the new server.

SSL certificate is missing after installing ChefDK

When you install a new version of ChefDK and try to run Test Kitchen converge you may get the following error message
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: Failed to complete #create action: [SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

To solve the problem add the following to the Windows environment variables and open a new Command or Bash window for the change to take effect:
SSL_CERT_FILE=C:\opscode\chefdk\embedded\ssl\certs\cacert.pem

Winrm is missing after installing ChefDK

When you install the new version of ChefDK you may get the following error message when you try to run Test Kitchen
!!!!!! The `winrm` gem is missing and must be installed or cannot be properly activated. Run `gem install winrm --version '["~> 1.6"]'` or add the following to your Gemfile if you are using Bundler: `gem 'winrm ', '["~> 1.6"]'`.

To install Winrm for the correct Ruby version execute
gem install winrm
gem install winrm-fs

Berkshelf is missing after installing ChefDK

When you install a new version of ChefDK and try to run Test Kitchen the following error message may appear
!!!!!! The `berkshelf' gem is missing and must be installed or cannot be properly activated. Run `gem install berkshelf` or add the following to your Gemfile if you are using Bundler: `gem 'berkshelf'`.

To reinstall Brekshelf in the correct version of Ruby execute
gem install berkshelf

EC2 driver is missing after installing ChefDK

After installing a new version of ChefDK you may get the following error message when you try to run Test Kitchen:

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.

To install the EC2 driver in the correct Ruby version execute

gem install kitchen-ec2

Error in Test Kitchen after installing ChefDK

You may get the following error when you try to run Test Kitchen after installing the latest version of ChefDK:

$ kitchen
C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- dl/import (LoadError)
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/pageant.rb:1:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/agent/socket.rb:5:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/agent.rb:22:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/key_manager.rb:4:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:4:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh.rb:11:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/test-kitchen-1.7.3/lib/kitchen/ssh.rb:20:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/test-kitchen-1.7.3/lib/kitchen.rb:46:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/test-kitchen-1.7.3/lib/kitchen/cli.rb:21:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/test-kitchen-1.7.3/bin/kitchen:10:in `<top (required)>'
from C:/Ruby22/bin/kitchen:23:in `load'
from C:/Ruby22/bin/kitchen:23:in `<main>'

To make Test Kitchen work again execute the following:

gem install net-ssh -v 2.9.3.beta1

Extract data from JSON with Ruby

Chef uses Ruby as the scripting language. If you need to extract data out from a JSON string you can use the following script


# Save the JSON values
instance_data_drive_config = '{"size":"500","type":"io1","iops":"15000"}'

# Parse the JSON to a hash
data = JSON.parse(instance_data_drive_config)

# Declare the variables
size = ''
type = ''
iops = ''

# Iterate through the hash
data.each do |child|
case child[0]
when 'size'
size = child[1]
when 'type'
type = child[1]
when 'iops'
iops = child[1]
end
end

# Display the result
puts "size=#{size}"
puts "type=#{type}"
puts "iops=#{iops}"

The output is
size=500
type=io1
iops=15000