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
Knowledge Base for IT Professionals, Teachers and Astronauts
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
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 action :request_reboot end
When you you execute the code, chef will display the following error message:
property delay_mins is declared in both reboot[Hostname was changed] and utils_reboot[hostname_reboot] action :request_reboot. Use new_resource.delay_mins instead.
To tell Chef that you want to use the property you have created in this custom resource, add new_resource. in front of your property:
property :delay_mins, Fixnum, default: 3 reboot 'Hostname was changed' do reason reboot_reason delay_mins new_resource.delay_mins action :request_reboot end
After software update in Sierra on my Macintosh, my Bluetooth mouse usually stops working.
The toolbar displays the Bluetooth not available icon:
When I click it, the “Bluetooth: Not Available” message is displayed.
There are two recommended actions we can take to bring Bluetooth back to life. If the first one does not help, try to execute them together during the same shutdown and restart cycle.
Since I installed Windows 10 on my Toshiba P-70A laptop, the computer does not recognize the second monitor.
To make the second monitor work, I had to uninstall the display drivers and remove them from the computer:
To keep your second monitor working do not update the display drivers, keep the drivers that Windows installs during the reboot.
When you install Jenkins, the default settings allow anyone to sign up and administer it. There are many ways to secure Jenkins, the simplest is to disable the user sign up and require login to administer the server.
If you work on a Mac or Linux workstation and need to script and administer Windows servers, you need a few Windows tools. You can create a Windows Virtual Machine hosted in the free Virtual Box from Oracle or in VMware Fusion. For installation instructions see Install the DevOps development tools on Windows
When you work on a Mac, you use the Command key for cut, copy, paste and other functions. If you press the same key in the Windows virtual machine, it acts as the Windows key. If you press it with an arrow key, it will move or resize your current window.
To disable the left Windows Key in your Windows virtual machine download SharpKeys from https://www.randyrants.com/category/sharpkeys/.
The application does not run in the background, it only updates the registry to remap the specified keys. Configure it to disable the left Windows Key:
There are DevOps tools that you can install on your Mac to work with Windows servers and applications
To connect to Microsoft SQL servers you can install Visual Studio Code and the MSSQL extension on your Mac.
brew update
brew install openssl
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
For more info on MSSQL in Visual Studio Code see https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-develop-use-vscode?view=sql-server-2017
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 error message:
NoMethodError: undefined method `exists?’ for Chef::Resource::File:Class
In a Chef custom resource, you need to add :: in front of the File class to make it work
The leading :: tells Chef not to look for the “File” class in the Chef namespace.
if ::File.exists?("#{FileName}")
Amazon Web Services do not provide tools to migrate data to, from and between AWS RDS instances.
There is a free utility that can do the job.
Install Microsoft SQL Server Management Studio (SSMS), because the utility uses libraries from it.
The Chef file and folder locations are different on Linux and Windows machines. This article explains the purpose of each file and the location.
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 custom log files | /var/log/cheflog.log | C:\Logs\Chef\cheflog.log |
Chef Client configuration | /etc/chef/client.rb | C:\chef\client.rb |
The .kitchen.yml file contains the username to execute the Chef cookbook. It is specified under platforms:, transport:, username:
Use that value in place of USER-NAME-FROM-KITCHEN-YML below.
Linux | Windows | |
---|---|---|
Cookbook location | /tmp/kitchen/cookbooks /tmp/kitchen/cache/cookbooks |
C:\Users\USER-NAME-FROM-KITCHEN-YML\AppData\Local\Temp\kitchen\cookbooks |
Error log | /tmp/kitchen/cache/chef-stacktrace.out | C:\Users\USER-NAME-FROM-KITCHEN-YML\AppData\Local\Temp\kitchen\cache\chef-stacktrace.out |
Ohai output | /tmp/kitchen/cache/failed-run-data.json | C:\Users\USER-NAME-FROM-KITCHEN-YML\AppData\Local\Temp\kitchen\cache\failed-run-data.json |
Data bags | /tmp/kitchen/data_bags | C:\Users\USER-NAME-FROM-KITCHEN-YML\AppData\Local\Temp\kitchen\data_bags |
When the Chef recipes are executed, all cookbooks are stored on the node. You can examine the code to make sure your latest changes are reflected on the machine.
The output of the Chef cookbook execution is in the chef.log or chef-client.log file
The log of the first Chef Client run and subsequent runs are stored in different log files. After the initial Chef Client run, the rest of the log entries are collected in the second file.
Chef saves information on the hard drive when scripts are executed. If there is a failure, the stack trace of the last error is saved in the chef-stacktrace.out file.
All the information that Ohai collects on the instance, is saved in the failed-run-data.json file, even if there is no error. It is a great resource to get the server specific values.
Cloud info
Computer info
Operating system info
Chef info
To get detailed information on the Chef run, start the Chef Client in debug mode. Execute the command in sudo mode, because many Chef steps require elevated rights.
chef-client -l debug -L debug.txt
The debug information is saved in the debug.txt file in the current folder.
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.
To get the list of the available Chocolatey packages on an Artifactory server
choco list -s http://ARTIFACTORY_SERVER_URL/artifactory/api/nuget/ARTIFACTORY_REPOSITORY_NAME
If the Chocolatey package does not contain copyrighted components, Chocolatey can download and repackage the entire package, including the application.
Download a Chocolatey package from the Internet and store it on your local drive
choco download PACKAGE_NAME --internalize
To store the Chocolatey packages on an Artifactory server
Upload all packages from your local drive to an Artifactory server. Some of the large packages depend on other NuGet packages that have to be available on your Artifactory server.
curl -u ARTIFACTORY_USERNAME:ARTIFACTORY_PASSWORD -X PUT "http://ARTIFACTORY_SERVER_URL/artifactory/ARTIFACTORY_REPOSITORY_NAME/FOLDER_NAME/PACKAGE_FILE_NAME.nupkg" -T ./PACKAGE_FILE_NAME.nupkg
If the Chocolatey package installs an application that is copyrighted, the author of the package cannot publish the copyrighted source, but can place the download location and installation process into the package.
To download the necessary files and create a custom Chocolatey package with copyrighted application source:
choco download PACKAGE_NAME
Example:
choco download javaruntime
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$url = "$toolsDir\32_BIT_INSTALLER_FILE" $url64 = "$toolsDir\64_BIT_INSTALLER_FILE"
-UseOriginalLocation
to the Install-ChocolateyPackage line.
curl -u ARTIFACTORY_USERNAME:ARTIFACTORY_PASSWORD -X PUT "http://ARTIFACTORY_SERVER_URL/artifactory/ARTIFACTORY_REPOSITORY_NAME/PACKAGE_NAME/PACKAGE_FILE_NAME.nupkg" -T PATH/TO/PACKAGE_FILE_NAME.nupkg