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 …
Category Archives: Chef
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 …
Continue reading “Undefined method or attribute error in a Chef recipe”
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 …
Generate a GUID in Chef with Ruby
When you need a unique string to name a resource in your Chef scrip, generate a GUID with SecureRandom.uuid To make sure the resource always gets a unique name: log “#{SecureRandom.uuid}” do message ‘My message’ level :info end
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 …
Continue reading “Chef custom resource is using the same property name as the called resource”
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 …
Continue reading “NoMethodError: undefined method `exists?’ for Chef::Resource::File:Class”
Chef file locations
The Chef file and folder locations are different on Linux and Windows machines. This article explains the purpose of each file and the location. Summary Linux Windows Cookbook location /var/chef/cache/cookbooks C:\chef\cache\cookbooks Chef Client run log /var/log/chef.log First run only C:\chef\chef-client.log Subsequent Chef client runs C:\chef\log\client.log Error log /var/chef/cache/chef-stacktrace.out C:\chef\cache\chef-stacktrace.out Ohai output /var/chef/cache/failed-run-data.json C:\chef\cache\failed-run-data.json Recommended location for …
Internalize Chocolatey packages
To access Chocolatey packages in your private network you need to download them from the Internet and store them at a location where all servers can access them. You can internalize Chocolatey packages if you have a Chocolatey Business subscription. You can use an Artifactory server to host the internalized packages. List of available packages To …
Launch Windows instances locally with Chef Test Kitchen
Most Linux distributions are free, and do not require product keys to launch them. The steps below are based on the great article at http://kitchen.ci/blog/test-kitchen-windows-test-flight-with-vagrant/ I have summarized the steps below to create a free Virtual Box Windows Server 2012R2 image on your workstation, so Test Kitchen can use Vagrant and Virtual Box to launch Windows instances and test cookbooks …
Continue reading “Launch Windows instances locally with Chef Test Kitchen”
DevOps Engineering part 1. (Mac) – Make your Macintosh easier to use
Enable the right-click To be able the right-click on the mouse Disable caps lock If you never write emails with all capital letters, and many times a day accidentally press the caps lock key, you can disable it. Remove Siri from the control strip If you don’t use Siri on your Mac, there is no …
Continue reading “DevOps Engineering part 1. (Mac) – Make your Macintosh easier to use”