Create the AWS credentials file from a Chef Data Bag

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 …

Dynamically set Chef resource attributes

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 …

No instances for regex `’, try running `kitchen list’ in Chef Test Kitchen

When I tried to execute the “kitchen list” command in Chef Test Kitchen the following error came up: No instances for regex `’, try running `kitchen list’ I could not find the reason for the error, so I opened the .kitchen.yml file in the Atom editor, added a space to one of the comments, and saved the …

Chef Attributes

Chef attributes are global variables that are available for every cookbook on the node. There are multiple formats to declare and use an attribute. For important notes on the syntax, please see Undefined method or attribute error in a Chef recipe. To override the value of an attribute that is defined in another cookbook, use the …

Getting started with InSpec

InSpec is an open-source testing framework to verify your infrastructure satisfies the design requirements. In this article, we will learn to install and use InSpec with Chef. Install InSpec Navigate to https://downloads.chef.io/inspec, and download the installer for the operating system of your workstation, Execute the downloaded installer. Allow InSpec to verify Red Hat Enterprise Linux instances InSpec needs …

Undefined method or attribute error in a Chef recipe

There are multiple reasons Chef can display the following error message NoMethodError ————- Undefined method or attribute `…’ on `node’   There are many ways to reference an attribute in a Chef recipe: node[‘ATTRIBUTE_NAME’] (the recommended style) node[“ATTRIBUTE_NAME”] node[:ATTRIBUTE_NAME] (use it only if the single or double quotes (‘ or “) would cause a problem …

Add SSH key to a Jenkins Git step

To access a Git repository Jenkins can use an SSH key. To add the SSH key to the Jenkins server use the following Chef script Store the SSH key in an encrypted data bag called “keys”. { “id”: “ci_private_keys”, “ci_github_key”: “—–BEGIN RSA PRIVATE KEY—–\n…\n—–END RSA PRIVATE KEY—–“, }   Add the following to the Jenkins …

Chef custom resource is using the same property name as the called resource

When you create a Chef custom resource, you can call other resources including custom resources you have created. For ease of use it can be convenient to use the same property name as the called resource use. property :delay_mins,          Fixnum, default: 3 reboot ‘Hostname was changed’ do reason reboot_reason delay_mins delay_mins …

NoMethodError: undefined method `exists?’ for Chef::Resource::File:Class

When you create a Chef custom resource and use the File class, you need to make slight a change in the syntax you use. In a Chef recipe you can use if File.exists?(“#{FileName}”) to check for the existence of a file. If we use the same line in a Chef custom resource, we get the …