Tag: Chef

The Macintosh workstation saves application states in .DS_Store files. When you edit your Chef cookbooks the MacOS leaves these files in many folders.

When the Chef cookbook is executed, the Chef Client reads all files in the attributes folder and tries to extract values from them. If the .DS_Store file is uploaded with the rest of the cookbook to the Chef server, the Chef cookbook execution stops with the error message:

Read the value of the environment variable into a local variable in the InSpec test file. If the environment variable does not exist, or the value is not “true”, the value of the local_execution variable will be “false”.

The last format, the dot notation is a legal form, but not accepted by the compiler that checks the cookbooks during bootstrapping. The same cookbook works perfectly in Test Kitchen, and in chef-client.

The solution is to change the dot notation to one of the other formats, preferably to the first in the list above.

Every user

Upload all cookbooks to the new Chef server

Copy all cookbooks to the new chef directory

Open a terminal in the cookbooks directory and start to upload all cookbooks

knife cookbook upload --all --freeze --force

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’

Change to that XXX cookbook directory and execute

berks upload

Repeat step 3 until all cookbooks have successfully uploaded to the server.

Upload the environment files

Open a terminal in the environments directory.

knife environment from file qa.json uat.json prod.json

Upload the data bags

Open a terminal window in the data-bags directory and upload the data bags.

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:

Vagrant Installation

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

When a process on a server instance needs access to an AWS account, the user who will execute the AWS CLI commands needs to be able to automatically authenticate in AWS.

For automatic AWS authentication, the AWS CLI creates two files in the .aws directory:

config and

credentials.

The location of this directory depends on the operating system and the type of user.

On Linux, the location is ~/.aws ( the user’s home directory )

On Windows, it is located at C:\Users\USER_NAME\.aws

On Windows, if the file was created by SYSTEM, the location is C:\Windows\System32\config\systemprofile\.aws

Store the AWS key values

To create these files, you need to store the AWS Access Key and Secret Key. The safest place for these values is an encrypted data bag. To automatically generate the AWS files, create a data bag file and name it the same as the “id” in the following structure:

When you need to set a Chef resource attribute based on the current state of the environment, there is a way to dynamically provide the value.

Set the value of a boolean variable with a test,

Declare the Chef resource and assign a reference to it to a variable,

Set the resource attribute based on the value of the boolean variable.

# Set a boolean variable with a test
def MY_BOOLEAN_VARIABLE?
"#{node['domain']}" != ""
end
# Execute a resource and get a reference to it into a variable
t = MY_RESOURCE 'MY_RESOURCE_NAME' do
...
end
# Set the attribute value based on the boolean variable
t.MY_RESOURCE_ATTRIBUTE MY_ATTRIBUTE_VALUE if MY_BOOLEAN_VARIABLE?