Ruby Gem Management

Ruby gems are Ruby programs and libraries with a name, version and the platform that can execute them.

List the installed gems on your system

gem list

Detailed list that includes the author, homepage, license, install location and a short description

gem list -d

Install the latest version of the gem

gem install GEM_NAME

Install a specific version of the Gem

gem install GEM_NAME -v GEM_VERSION

Uninstall the gem from your system

gem uninstall GEM_NAME

Uninstall a  gem from a specific location

gem uninstall GEM_NAME -i LOCATION_FROM_GEM_LIST_-D

Update the Gem list in your system after Gem uninstallation

gem update --system

 

 

 

 

Bootstrap Chef nodes to connect them to the Chef server

A Chef node is a physical or virtual machine with an operating system that is connected to the Chef server. Once the node has made the connection to the Chef server, the installed Chef Client can execute Chef cookbooks to configure the machine.

Bootstrapping is the process to connect the node the first time to the Chef server, or to attach it again if the node lost the connectivity to the Chef server. To be able to bootstrap a node, your workstation needs to have the Chef Development Kit installed. The kit includes the ‘knife’ command that communicates with the Chef server. Your workstation also has to be able to connect to the Chef server with the YOUR_USERNAME.pem file you store in the .chef directory just above your cookbooks.

Bootstrap a Linux node

To bootstrap a Linux node, open a terminal window on your workstation and execute the command:

With password authentication
-----------------------------
knife bootstrap MY_NODE_IP -x SERVER_ADMIN_USERNAME -P SERVER_ADMIN_PASSWORD --sudo --node-name THE_NODE_NAME --environment THE_ENVIRONMENT --run-list 'recipe[MY_COOKBOOK1::default],recipe[MY_COOKBOOK2::default]' --json-attributes '{"MY_ATTRIB1":"MY_VALUE1","MY_ATTRIB2":"MY_VALUE2"}'

With key authentication
-----------------------
knife bootstrap MY_NODE_IP -x SERVER_ADMIN_USERNAME -i PATH_TO_KEY_FILE --sudo --node-name THE_NODE_NAME --environment THE_ENVIRONMENT --run-list 'recipe[MY_COOKBOOK1::default],recipe[MY_COOKBOOK2::default]' --json-attributes '{"MY_ATTRIB1":"MY_VALUE1","MY_ATTRIB2":"MY_VALUE2"}'

Bootstrap a Windows node

knife bootstrap windows winrm MY_NODE_IP -x SERVER_ADMIN_USERNAME -P SERVER_ADMIN_PASSWORD --node-name THE_NODE_NAME --environment THE_ENVIRONMENT --run-list 'recipe[MY_COOKBOOK1::default],recipe[MY_COOKBOOK2::default]' --json-attributes '{"MY_ATTRIB1":"MY_VALUE1","MY_ATTRIB2":"MY_VALUE2"}' -V

where

  • MY_NODE_IP is the IP address of the node you want to attach to the Chef server,
  • SERVER_ADMIN_USERNAME and SERVER_ADMIN_PASSWORD are the credentials to connect to the node.
    If the Windows server is in the Windows domain start the username with the domain name MY_DOMAIN\\SERVER_ADMIN_USERNAME
    If the Windows server is not in the domain start the username with the IP address MY_NODE_IP\\SERVER_ADMIN_USERNAME
  • THE_NODE_NAME is the unique name you want the node to use in the Chef server database. If you are bootstrapping a server that lost connectivity to the Chef server or moving the node to another Chef server, find the node name in the node list.
  • THE_ENVIRONMENT is the name of the environment the node will run the cookbook in,
  • The run list is a list of cookbooks and roles. No spaces are allowed in the string.

Troubleshooting

If the known_hosts file already contains an entry for a different server with the same IP address, we get the error message

ERROR: Net::SSH::HostKeyMismatch: fingerprint … does not match for “…”

Open the ~/.ssh/known_hosts file and delete the line that contains the IP address of the server.

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.

  1. Set the value of a boolean variable with a test,
  2. Declare the Chef resource and assign a reference to it to a variable,
  3. 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?

 

 

How to create a bootable USB drive to install Windows

If the computer you want to install Microsoft WIndows on, does not have a DVD drive, you can install Windows from a USB drive. To start the computer from the USB drive, you need to prepare the drive to make it bootable.

Microsoft has a free tool that can download the edition of the Windows operating system you need, format the USB drive, make it bootable, and place the installer file on it.

  1. Using a web browser navigate to https://www.microsoft.com/en-us/software-download/windows10,
  2. Click the Download tool now button to install the Microsoft Media Creation Tool,
  3. Start the downloaded MediaCreationTool.exe program and follow the prompts.

Setup failed: Failed to copy slug dir: lstat /Users: no such file or directory error in Terraform Enterprise

When you try to execute a Terraform configuration in Terraform Enterprise (Atlas) you may get the error message:

Setup failed: Failed to copy slug dir: lstat /Users: no such file or directory

Cause:

The Git repository contains the .terraform/modules directory, and the Terraform Enterprise server cannot get the latest modules from GitHub.

Solution:

  1. Create a .gitignore file in the repository and add these lines:
    */.terraform/modules/
    
    # Ignore DS_Store if working on a mac
    .DS_Store
  2. Delete the .terraform directory and push the changes to GitHub

 

 

Install a Python package

To install a Python package on Macintosh

  1. Download the Python package to your workstation,
  2. Unpack the package,
  3. Open a terminal window,
  4. Start sudo,
    sudo -i
  5. Change to the directory of the package,
  6. Install the package.
    pip install PACKAGE_NAME

If you don’t install the package in sudo mode, you will get “Permission denied” errors during the package installation.

Troubleshooting

When you encounter the warning message

WARNING: The directory ‘/Users/…/Library/Caches/pip’ or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo’s -H flag.

To make yourself the owner of the /Users/…/Library/Caches/pip directory execute

sudo chown -R $(whoami) ~/Library/Caches/pip

PyCharm configuration

When you install PyCharm, the default Python interpreter is may not the version you want to use for your new projects. When you create a new project, and the project interpreter is not set, you may get the following error message:

Executed command:
/var/folders/_x/_f0zzs1s4sx6bk4s8n78l2jsbn9r3z/T/tmpBoQLx_pycharm-management/pip-9.0.1/setup.py install

Error occurred:
40:357: execution error: /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py:266: UserWarning: Unknown distribution option: ‘python_requires’

Command output:
40:357: execution error: /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py:266: UserWarning: Unknown distribution option: ‘python_requires’
warnings.warn(msg)
warning: build_py: byte-compiling is disabled, skipping.
warning: install_lib: byte-compiling is disabled, skipping.
error: byte-compiling is disabled.
(1)

Solution:

Set the default Python interpreter to the latest installed version before you create your project:

  1. Start PyCharm
  2. In the File menu select Default Settings
  3. On the left side select Project Interpreter,
  4. On the right side click the arrow of the Project Interpreter drop-down
  5. Select the Python interpreter you want to use by default, and click the OK button.

Python ImportError: No module named …

Symptom:

from MY_FOLDER.MY_FILE import MY_CLASS causes an error:
ImportError: No module named MY_FOLDER.MY_FILE

Debugging:

  1. Execute the program in debug mode,
  2. In the Variables window expand Special Variables,
  3. Read the __warningregistry__ value.

Possible cause:

The __init__.py file is missing in the directory of the referenced class.

Solution:

Create an empty __init__.py file in the directory where the class is referenced from.