Keep multiple versions of applications on Macintosh

Most of the DevOps tools are still in beta versions, many times the new version is not compatible with your existing scripts or have an error that stops your scripts working. To be able to keep multiple versions of the applications and easily switch between them, create symbolic links and point to the version you want to execute.

Create version-specific locations

Create a folder for your optional applications.

mkdir /opt

Set you as the owner of the “opt” directory and its children.

YOUR_GROUP should be on:

  • MacOS: wheel
  • Ubuntu: your username 
sudo chown -R YOUR_USER_NAME:YOUR_GROUP /opt

Set the security of the folder.

sudo chmod 755 /opt

We will create a directory structure to place each version of the application into its own folder. This example uses Packer.

Create a symbolic link to point to the application in the appropriate version folder. These are the examples for Packer, Terraform, and Vagrant. Notice, that the Vagrant application is in the “bin” directory, so the symbolic link has to point there.

If there is an existing symbolic link that points to the latest version of the application, rename it to be able to quickly return to the prior version of the application. This can come handy when we need to destroy instances created with the prior version of Terraform.

cd /opt/terraform
mv terraform terraform_v_0.9.11
cd /opt/packer
mv packer packer_v_1.0.4

Create a new symbolic link that points to the latest version of the application.

# For Packer
cd /opt/packer
ln -s /opt/packer/packer_1.2.0/packer packer

# For Terraform
cd /opt/terraform
ln -s /opt/terraform/terraform_0.10.0/terraform terraform

# For Vagrant
cd /opt/vagrant
ln -s /opt/vagrant/vagrant_1.9.5/bin/vagrant vagrant #The vagrant application is in the bin folder

Add the main application folder to the path in the config file of your terminal

  • for iTerm2 with zterminal: ~/.zshrc
  • for other terminals: ~/.bash_profile
PATH=/opt/packer:$PATH
PATH=/opt/terraform:$PATH
PATH=/opt/vagrant:$PATH

Vagrant

For Vagrant installation see Vagrant


To change the version you want to execute

  • Delete the symbolic link,
    cd /opt/packer
    rm packer
  • Create a new symbolic link pointing to the other version of the application as above.

Variable ‘…’: duplicate found. Variable names must be unique.

Starting with Terraform version 0.7.3 you can only define a variable once within a directory or a module. Before that release you could copy variable definition files from other modules and did not throw an error if you had the same variable defined in multiple files within the module.

In the new version of Terraform if you define the same variable name multiple times within the module you will get the following error message,

Variable '...': duplicate found. Variable names must be unique.

Make sure a variable is only defined once in the module or directory.

Disable the Caps Lock key on the Macintosh

I am not sure who uses the Caps Lock button anymore. It was important in the age of typewriters to be able to type all uppercase titles without holding the shift key, but these days I don’t remember the last time I needed it. In fact I frequently press it accidentally and prevents me to log into my computer.

 

To disable the Caps Lock key on Sierra

  • In Settings open Keyboard,
  • Click the Modifier Keys… button,
  • Set the Caps Lock key to No Action.

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 locally fast and free.


Install the Vagrant WinRm plugin

vagrant plugin install vagrant-winrm

Get BoxCutter

Create the Windows image with BoxCutter. This process will take 30 minutes or more to fully configure the Windows image. The download step may time out on slower VPN connections. In that case disconnect the VPN connection and try it again without it. In case of any error, just execute the last command again and if it can, the process will continue from the point of error.

cd ~/
mkdir boxcutter
cd boxcutter
git clone https://github.com/boxcutter/windows.git
cd windows

Modify the BoxCutter JSON file

Change the ~/boxcutter/windows/eval-win2012r2-standard.json file to avoid the error message:

virtualbox-iso: Removing floppy drive…
==> virtualbox-iso: Error removing floppy controller: VBoxManage error: VBoxManage: error: The machine ‘eval-win2012r2-standard’ is already locked for a session (or being unlocked)
==> virtualbox-iso: VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports
==> virtualbox-iso: VBoxManage: error: Context: “LockMachine(a->session, LockType_Write)” at line 1038 of file VBoxManageStorageController.cpp

  • Change “headless”: “false”, to “headless”: “true”,
  • Add under “headless”: “true”,
"shutdown_timeout": "60m",
"post_shutdown_delay": "120s",

 

  • Add under every occurrence of “headless”: “{{ user `headless` }}”,
"shutdown_timeout": "{{ user `shutdown_timeout` }}",
"post_shutdown_delay": "{{ user `post_shutdown_delay` }}",

Create the virtual machine

make virtualbox/eval-win2012r2-standard

Add the image to Vagrant

vagrant box add windows-2012r2 ./box/virtualbox/eval-win2012r2-standard-nocm-1.0.4.box

Test the virtual machine

Your .kitchen.yml file should look like this

---
driver:
  name: vagrant

provisioner:
  name: chef_zero

platforms:
  - name: windows-2012r2

suites:
  - name: MY_SUITE_NAME
  run_list:
  - recipe[MY_COOKBOOK::MY_RECIPE]

 

You may need to execute the kitchen converge commands as sudo to be able to launch the Windows instance.

How to migrate the DevOps development environment to another workstation

Git

Move the Git repositories to a new workstation

If you want to move Git repositories to your new workstation

  • Commit and push all repositories to GitHub on the old workstation,
  • Copy the folders from your old workstation to the new,
  • Execute the following command in all Git repositories on the new workstation.
    git reset --hard

Terraform

Copying Terraform scripts from a Windows workstation

If the Terraform scripts reference modules, terraform creates symbolic links to those modules in the .terraform/modules directories. When you try to copy those symbolic links on a Windows machine the copy process stops. To copy the Terraform scripts

  • Start Windows explorer in the folder above the Terraform script folders,
  • Search for .terraform,
  • In the search result list delete the .terraform folders.

Test Kitchen

If you migrate between Windows and Macintosh you need to update a few paths, because the two operating systems store user specific files at different places.

The ssh_key location in the .kitchen.yml file should start with

  • On Macintosh: ~/aws_keys/
  • On Windows: C:\Users\YOUR_USER_NAME\aws_keys\

DevOps Engineering part 1. (Mac) – Make your Macintosh easier to use

Enable the right-click

To be able the right-click on the mouse

  1. Open settings.
  2. Enable Secondary click for the mouse and the trackpad.


Sounds

Disable the startup sound

To disable the sond during the computer start

  1. In System Settings, Sound tab turn off the Play sound on startup

Enable notifications when external monitors are connected

By default notifications are turned off during screen sharing and screen mirroring. This makes screen sharing quieter for the audience, but notifications of arriving emails and Zoom calls are also muted when we use external monitors (screen mirroring). To enable notifications when external monitors are connected:

  • In System Settings, Notifications enable Allow notifications when mirroring or sharing the display.

Keyboard

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.

  1. Open settings.
  2. Open the Keyboard settings click Keyboard Shortcuts

  3. On the Modifier Keys tab set Caps Lock to No Action for the inernal keyboard.
     
  4. Set the same for your external keyboard if you have one.

Disable the Globe key

When you press the fn key on the MacBook the emoji selection pops up. It is very annoying during programming. To disable the Globe key

  • In Systems Settings, Keyboard set Press globe key to Do Nothing

Remove Siri from the control strip

If you don’t use Siri on your Mac, there is no reason for Siri to occupy space on the control strip above the keyboard.

  1. Open the Keyboard settings
  2. On the Keyboard tab click the Customize Control Strip button
  3. Move the mouse below the bottom of the screen to highlight the Siri icon on the control strip, and drag it from the control strip up to the screen.

How to lock the screen

On High Sierra ( macOS 10.13 ) and later

  1. Press the Cmd-Ctrl-q key combination to lock the screen.

On earlier macOS versions

To be able to lock the screen from the menu bar:

  1. In Finder search for Keychain Access and start it,
  2. In the Keychain Access menu select Preferences,
  3. Check the Show keychain status in menu bar checkbox,
    This will place a lock icon in the menu bar.

To lock your screen

  1. Click the lock icon in the menu bar
  2. Select Lock Screen

Finder

Always browse in list mode

  1. Open Finder
  2. In the View menu select Show View Options
  3. Select Always open in list view, and Browse in list view

Show the full path in Finder

  1. Open Finder
  2. In the View menu select Show Path Bar
    Finder will show the full path of the current folder at the bottom of the window. 

To jump to a folder shown in the path bar just double click it.

Show hidden files and folders

  1. Open the terminal and execute the following line
    defaults write com.apple.finder AppleShowAllFiles YES
  2. For the change to take effect relaunch Finder.
    • Press the ‘Option/Alt’ key, right click on the Finder icon in the dock and click Relaunch

Menu bar

Change the spacing betweeh the icons

The notch for the camera on the new MacBooks hides the left most icons. The apps are running, but their icons are hidden if those do not fit on the right side of the notch. To make room for more icons

Remove rarely used system icons from the Menu Bar

Set the clock to display less information. Click the Clock Options button to access the Clock panel

Set the spacing of the icons. Based on Hidden preference to alter the menubar spacing and How to fix Mac menu bar icons hidden by the MacBook notch by Jesse Squires.

  • Open a terminal and execute the commands below. Log out and in again for the changes to take effect
defaults -currentHost write -globalDomain NSStatusItemSpacing -int 12
defaults -currentHost write -globalDomain NSStatusItemSelectionPadding -int 8
  • To check the values after those are set (there are no default values)
defaults -currentHost read -globalDomain NSStatusItemSpacing
defaults -currentHost read -globalDomain NSStatusItemSelectionPadding
  • To restore the original values execute the commands below. Log out and in again for the changes to take effect.
defaults -currentHost delete -globalDomain NSStatusItemSpacing
defaults -currentHost delete -globalDomain NSStatusItemSelectionPadding

Move the important icons to the right side

Press and hold the Command key and drag the important icons to the right side of the Menu Bar to keep those always displayed.

Show the battery charge percentage

In Sequoia and later

  1. In System Settings on the Control Center tab under Battery enable Show Percentage

In Monterey or later

  1. In System Preferences select Dock & Menubar
  2. On the left side scroll down to Battery Menu Bar and select Show Percentage

Before Monterey ( macOS 12 )

  1. Click the battery icon in the toolbar
  2. Select Show Percentage

Remove Fast User Switching

If you are the only one who uses the computer, to save space in the Menu Bar, remove the Fast User Switching icon

  1. In System Settings on the Control Center tab under Fast User Switching set Show in Menu Bar to Don’t Show

Apple Id without credit card

If you don’t have an Apple Id, create one. To obtain one without a credit card, you need to create the account in an older version of iTunes. In version 12.7 of iTunes Apple removed the access to the App Store.

  1. Downgrade iTunes on your Mac to version 12.6. Follow the instructions at http://osxdaily.com/2017/09/17/downgrade-itunes-12-7-to-itunes-12-6/
  2. Start iTunes 12.6 on your Macintosh,
  3. Click the drop-down menu in the upper left corner,
    apple-id-01
  4. If Apps is visible, select it, otherwise click Edit Menu
    • Select Apps, and click Done to display it in the drop down.
      apple-id-02
  5. Search for a free app in the App Store and start to download it,
    apple-id-03
  6. Create a new Apple Id and select None for credit card type.

Show the user home directory and drive root

  1. Open Finder
  2. In the Finder menu select Settings
  3. Select the Sidebar tab
  4. In the Favorites section select the checkbox next to the home icon
  5. If you want to see all mapped drives, in the Locations section select the name of the hard drive

Prevent Microsoft Outlook to send the message with Command-Enter

To prevent Outlook to send the email when you accidentally press Command-Enter, associate the Send action with a zero length character:

  • Quit Microsoft Outlook
  • Execute in the terminal
    defaults write com.microsoft.Outlook NSUserKeyEquivalents -dict-add "Send" "\U200B"

Stop Spotlight indexing the Time Machine drive

Spotlight helps to search for files by indexing drives. To speed up the Time Machine operations prevent Spotlight indexing the Time Machine drive.

  • Connect the Time Machine drive to the computer.
  • In System Preferences select Spotlight
  • On the Privacy tab click the Plus sign
  • In the locations section select the Time Machine drive and click the Choose button
  • The list should contain the Time Machine drive

Homebrew

Homebrew is a package manager, it can install packages on your Macintosh that apple does not provide, like a few utilities below.

Installation

Installation instructions are at http://brew.sh/

To add Homebrew to the path, so you can execute it from any terminal window execute

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

List outdated software

  1. To list installed software that has new versions available, execute
    brew outdated

Update installed software

  1. To update (upgrade) all software that has new versions, execute
    brew upgrade

Uninstallation

To uninstall Homebrew if you don’t need it later, execute

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

Limit battery charging to 80%

To prolong the life of the battery of your Macintosh, you can install a utility to stop battery charging at 80%.

  • Install BCLM from https://github.com/zackelia/bclm
    • If you don’t have ownership of Homebrew, before installation execute
      sudo chown -R $(whoami) /usr/local/var/homebrew
      sudo chown -R $(whoami) /usr/local/Homebrew/
    • The installation steps are currently
      brew tap zackelia/formulae
      brew install bclm
      sudo bclm write 77
      sudo bclm persist
    • Check the set value with
      bclm read
  • Turn off Optimized battery charging in System Preferences to give full control to the tool.

  • You may need to reboot the computer for the process to start monitoring the battery.
  • The charging will stop around 80%. It may goes above 80% with a few percents, but at least the battery is not fully charged.

After software update

The system software update usually resets the upper charging limit to 100%. After system update execute in a terminal

sudo bclm write 77
sudo bclm persist
bclm read

UTC Clock in the menu bar

This feature does not work reliably on newer machines with the notch on the top of the screen for the camera. Most likely when there is not enough room in the Menu Bar, the UTC clock is not displayed, but still hides other icons in the Menu Bar.

xBar is a plugin manager that can display plugins in the menu bar. One of them is World Clock that can display multiple clocks in a drop down of the menu.

Install xbar

  1. Navigate to https://xbarapp.com/
  2. Click the Download xbar for macOS button
  3. Download and run the .dmg file to install the application
  4. Move the xbar application to the Applications folder
  5. Launch xbar form the Launcher
  6. Right-click the icon in the task bar and select Options, Open at Login
  7. Restart the computer for the app to appear in the Menu Bar.

Add World Clock to xBar

    • Click xbar in the Menu Bar
    • Select the Plugin browser
    • On the Time page click the Install button in the World Clock panel

    • Click the Install button on the pop-up

Customize World Clock

  1. To open the plugins folder click the UTC clock, select xbar, Open plugin folder…
  2. Open the 001-worldclock.1s.sh file in a text editor

To change the displayed timezones, edit the ZONES variable in the file:

ZONES="US/Pacific UTC Europe/London Europe/Berlin Asia/Kolkata Asia/Tokyo Australia/Sydney"

To change the display format, edit the data formats.

  1. To remove the seconds from the menu bar, delete the :%S from the format line
date -u +'%H:%M UTC'

To add the day of the week and date to the clocks in the World Clock drop down

add

  • %a for the day of the week
  • %Y for the four digit year
  • %b for the name of the month
  • %d for the date
  • %z for the time zone offset
echo "$(TZ=$zone date +'%H:%M - %a, %Y %b %d %z') $zone"

To refresh the dropdown formats after making changes in the config file

  1. Click the World Clock in the menu bar
  2. Select Preferences, Refresh all

Disk Inventory X

This utility displays the graphical representation of file sizes and helps to find the biggest files.

  1. Download it from http://www.derlien.com/

System information in the menu bar

Stats is a free open source software to display system information in the menu bar including

  • CPU usage and temperature
  • Memory usage
  • Network and hard drive usage

To install it, navigate to https://github.com/exelban/stats

Next:

Back:

to the Tutorials page

OLD- DevOps Engineering part 1. (Win) – Make your Windows computer easier to use

Set up your computer

Display the file extensions

On Windows 11

  • Open the File Explorer
  • Click the arrow next to View and select Show
  • Mark File name extensions and Hidden items

On Windows 10

  • Open File Explorer
  • On the View tab select
    • File name extensions
    • Hidden items
      windows-03-show-file-extensions

On Windows 7

(if you accidentally run into an ancient machine)

  • Open Windows Explorer and select Organize
  • Select Folder and search options
    windows-02-show-file-extensions
  • On the View tab
    • Select Show hidden files, folders, and drives
    • Uncheck Hide extensions for known file types

To disable the Windows key

If you use a Macintosh computer you use the Command key all the time. Unfortunately, on the Windows keyboard you will always hit the Windows key. This can be very frustrating, as pressing the Windows key with any of the cursor keys will resize the window.

To disable the Windows key

  • Download the 64 bit version of PowerToys by Microsoft (currently PowerToysSetup-0.68.1-x64.exe) from https://github.com/microsoft/PowerToys/releases/tag/v0.68.1
  • Execute the installer file to install the application
  • Start Powertoys
  • On the left side select the Keyboard manager
  • Click the Open Settings button
  • Select Remap a key
  • Click the plus sign
  • On the left side select Win (Left), on the right side select Disable and click the OK button.
  • Click Continue Anyway

  1. 
    

Virtual Box

Download Virtual Box from https://www.virtualbox.org/wiki/Downloads and follow the instructions to install it.

At the time of writing, this was the section where the installer files were referenced

virtual-box-01-download

Run the downloaded installer file and accept all default values.

The installer starts the Virtual Box application.You can close it, we will use other tools to start it in the future.

To be able to launch 64 bit guest operating systems turn off Hyper-V in Windows Features

  1. In the Windows search box enter Windows Features and select Turn Windows Features on or off,
  2. Uncheck Hyper-V and click OK,
  3. Reboot the computer for the setting to take effect.

Configure VirtualBox

Networking

To share the connectivity of the host computer with the virtual machine, mainly if you use VPN

  1. In Virtual box click Settings
  2. Select Network
  3. Attach the network adapter to NAT

Copy and paste

To enable copy and paste between the virtual machine and the host ( your workstation )

  1. On the General tab of the Settings page select the Bidirectional shared clipboard

Shared Folders

Specify the shared folder on your workstation

  1. In the VirtualBox menu select Preferences
  2. On the Shared Folders tab click the + icon
  3. To share the entire system drive, select the C: drive of your workstation

Enable shared folders on the virtual machines

To enable the shared folders on the virtual machine and other configurations see Virtual machine configuration at VirtualBox


Vagrant

For Vagrant installation see Vagrant.


Ruby

  • Download Ruby from http://rubyinstaller.org/downloads
  • Install the 32 bit version, as the 64 bit version is fairly new and has compatibility issues. Download the latest Ruby installer. Pick the file that does not have the (x64) at the end.
  • Accept the default values but check Add Ruby executables to your PATH
    ruby-01-add-to-path

 Ruby Development Kit

The Ruby Development Kit is need for certain Ruby gems, so install it.

  • Download the Ruby Development Kit from the DEVELOPMENT KIT section of  http://rubyinstaller.org/downloads
  • If you have installed the 32 bit version of Ruby make sure you install the 32 bit version of the DevKit. Select the Development kit that matches the Ruby version you installed. At the time of writing the latest development kit is under “For use with Ruby 2.0 and above (32bits version only)
    • Run the installer to extract it to a permanent location (C:\RubyDevKit)
    • Open a command window in the C:\RubyDevKit folder
    • Run these commands in the command prompt to install it.
      • ruby dk.rb init
      • ruby dk.rb install
  • For more information see  http://github.com/oneclick/rubyinstaller/wiki/Development-Kit

Chef Development Kit

Terraform by Hashicorp

Install it with Chocolatey

  • Open a Git Bash window as administrator
  • Execute
    choco install terraform

or

Manual installation

  • Download Terraform from https://www.terraform.io/downloads.html
  • Unzip the downloaded package to C:\HashiCorp\Terraform
  • Add the Terraform directory to the path of the computer. It is not added automatically on 64 bit Windows.
    • In Windows Explorer right-click Computer and select Properties,
    • On the left side select Advanced System Settings,
    • At the bottom click the Environment Variables… button,
    • In the System Variables box select Path and click the Edit… button,
    • Add the following to the end of the Variable value. (Don’t forget to start with the semicolon as the separator).
      ;C:\HashiCorp\Terraform
  • To create RDS (Relational Database Service) instances in AWS, install the Amazon Web Services Command Line Interface (See instructions below)
  • Configure the GitBash window to run as administrator to be able to execute the “terraform get” command to get local modules during development
    • Right click the shortcut of the Bash window you use and select Properties
    • On the Compatibility tab check Run this program as an administrator

For more details see https://www.terraform.io/intro/getting-started/install.html

Graphviz

Graphviz is a Dependency Graph Visualization Software. We will use this utility to display the Terraform graphs.

  • Download from http://www.graphviz.org/Download..php
    There are really two dots in the address :-)
  • Execute the installer
  • You may need to add the location to the Path environment variable. Make sure you use the actual folder name, as it contains the version of the application.
    ;C:\Program Files (x86)\GraphvizX.XX\bin

AWS CLI

The Amazon Web Services command line interface installation will set up your workstation to launch instances in AWS from Test Kitchen. If you know you will work with AWS, see DevOps Engineering part 3. – Working with AWS for the AWS CLI installation.

Packer

We use Packer to create custom AWS AMIs that contain the fundamental configuration and applications that are common in every instance we launch.

Install with Chocolatey

  • Open a Git Bash window as administrator
  • Execute
    choco install packer

or

Manual Installation

  • Add the Packer executable or installation directory to the system path

Nice to have utilities

WinDirStat

Screenshot

WinDirStat is a disk utility to display the relative size of your files in a graphical interface and provide a tree view to help to find them.

Download it from https://windirstat.net/

Next:

Set up the DevOps development environment in Beginner’s Guide to DevOps Engineering part 2.

Back:

to the Tutorials page

Your session has timed out. Please try again. Code 5107 in the

To download apps from the Apple Store you need an Apple Id. If the app is free, you may not want to enter credit card information during the registration. If you try to create the Apple Id without the credit card in the App Store application, you may get the following error message:

Your session has timed out. Please try again. Code 5107

To create the Apple Id without a credit card

  • Start iTunes on your Macintosh,
  • Click the drop down menu in the upper left corner,
  • If Apps is visible, select it, otherwise click Edit Menu… in the same drop down,

    • To display Apps in the drop down, select the check box next to it.
  • On the top of the screen click the App Store button,
  • In the upper right corner search for a free app in the App Store and start to download it,
  • Create a new Apple Id and select None for credit card type.

`block in filter_instances’: undefined method `empty?’ for nil:NilClass (NoMethodError)

When you try to execute any of the “kitchen” commands in Chef Test Kitchen you may get the following error message.

lib/kitchen/config.rb:182:in `block in filter_instances': undefined method `empty?' for nil:NilClass (NoMethodError)

This happened in my cookbook, when I have removed the value from the “excludes:” option in the .kitchen.yml file, but left the “excludes:” option there alone.

To make your cookbook work in Chef Test Kitchen again, remove the empty “excludes:” option form the .kitchen.yml file

Failed to open file ‘…’ , error 2 and error 22

How to restore a MySQL database in Windows

To restore a MySQL database on a Windows machine:

  • Place the database backup file in the root directory of your C: drive (trust me, this will make your life easier)
  • Open the Command Prompt
  • Start the MySQL command prompt
  • mysql -u root -p

    This command will prompt you for the MySQL root password

  • Switch to the new database
    use db;
  • Import the database
    source C:/BACKUP_FILE_NAME.sql

    To avoid the Failed to open file ‘…’ , error 2 and error 22 error message
    You can have spaces in the name of the backup file, but not in the directory names in the path
    Do not use quotes around the file path
    Use forward slashes
    Do not end the command with semicolon (;)