How to rename a TeamCity agent

It is important to keep the TeamCity agent names unique. If you launch a TeamCity agent with a name that is already used by another agent that is connected to the TeamCity server, the new agent will not show up in the Unauthorized agent list.

To change the name of an agent, change the “name” value in the conf/ file.

To access the file you need to log into the box.

On a Linux agent

  • SSH into the agent,
  • Change the “name” value in the /opt/teamcity/conf/ file.

On a Windows agent

  • Remote into the agent,
  • Change the “name” value in the C:\TeamCity\conf\ file.

The location of TeamCity can be different depending on the configuration of the box.

Beginner’s Guide to DevOps Engineering Part 7.

Launching production instances in the cloud

In the previous parts of this tutorial we have launched instances (servers) in the cloud, but those were created by Test Kitchen, running on our workstation. Those instances are as good as they can be, but the cookbook did not reside on the Chef server.

To launch pre-production and production instances in the cloud, first we need to upload the cookbook to the Chef server. In Beginner’s Guide to DevOps Engineering part 4. Connect to the Chef server we have already connected our workstation to the Chef server.

Upload the cookbook to the Chef server

To make your cookbook available for all the servers of the organization we will upload the cookbook to the Chef server.

  • In the folder of the cookbook open a Bash window
  • Execute the command to upload the cookbook to the Chef server
    knife cookbook upload COOKBOOK_NAME --freeze

    Don’t forget to add the –freeze option to the end to protect the version of the cookbook from accidental changes.

Launch the server in the Cloud

There are many ways to launch servers in a scripted way, we are going to review a few options. One is to use RightScale, a Cloud Management Platform, that can manage servers in multiple cloud environments.


Create a new Deployment

  • Using your web browser log into the RightScale Cloud Management user interface,
  • In the Manage menu select Deployment and click the New button,
  • Enter the name of the new deployment,
  • To add the new deployment to your bookmarks,
    • On the left side in the Bookmarks section click the Add link,
    • If necessary shorten the name of the bookmark and click OK,
    • To reorder the bookmarks
      • Click the Edit link and drag the bookmark to the desired position,
      • Click the Done link to save your changes.

Create the CAT file

CAT files are Ruby like scripts that describe the configuration of the instance. It contain the name of the deployment the server should be placed it, the cloud attributes to assign security groups, regions, availability zones, set the drive size, specify security keys. The easiest way to configure a server is to copy an existing RightScale Self Service CAT file and update it with the new values.

If this is the first CAT file in your organization, get help from RightScale support and get a sample file from them.

If your organization already has a library of CAT files

  • Make a copy of an existing CAT file
  • Update the values to customize it for your server
    • Application name
    • Chef runlist
    • Security group
    • Deployment name
    • Load balancer name
    • Instance type


Upload the CAT file to RightScale

  • Open the RightScale Self Service user interface,
  • Select Designer on the left,
  • Click the Upload CAT button and select the CAT file,
  • Click the Upload button in the lower right corner,
  • In the green popup in the upper right corner click the Publish to catalog link,
  • In the lower right corner click the Yes, Publish button.

Launch the server in RightScale Self Service

  • In the RightScale Self Service interface select Catalog on the left side,
  • Select the catalog item you want to launch,
  • Enter a name for the instance to be able to identify it later and select the instance in the dropdown list,
  • Click the Launch CloudApp button.

To monitor the server launch

  • In your web browser open the RightScale user interface,
  • In the design menu select Deployments,
  • Select the deployment of the instance,
  • Click the instance to see in formation on it.


to the Tutorials page


Beginner’s Guide to DevOps Engineering Part 6.

Infrastructure as code


If you use Terraform in the corporate environment your company most likely has multiple AWS accounts. One for pre-production, one for production.

To be able to work in multiple AWS accounts, add those keys to the credentials file at C:\Users\YOUR_USERNAME\.aws

aws_access_key_id = MY_ACCESS_KEY_FOR_AWS01
aws_secret_access_key = MY_SECRET_KEY_FOR_AWS01

aws_access_key_id = MY_ACCESS_KEY_FOR_AWS02
aws_secret_access_key = MY_SECRET_KEY_FOR_AWS02

aws_access_key_id = MY_ACCESS_KEY_FOR_AWS01
aws_secret_access_key = MY_SECRET_KEY_FOR_AWS01

We will use Terraform to create security groups and load balancers in AWS.

  • Create a folder on your workstation for the Git repositories C:\Git
  • In the Git folder create a folder for the Terraform Configurations Terraform Configs
  • In the Terraform Configs folder create a sub-folder for the

When you are reusing existing Terraform configurations

  • Make a copy of the existing Terraform Config folder
  • Rename the folder
  • Rename the .tf files to match the name of the folder name
  • Delete the .tfstate and .tfstate.backup files
  • Update the .tf files with the new values
  • Open a Bash window in the new folder
  • Get the Terraform modules with
    terraform get -update
  • Test the script with
    terraform plan
  • Execute the script with
    terraform apply

More info on Terraform at


Launching production instances in the cloud in Beginner’s Guide to DevOps Engineering part 7.


to the Tutorials page

Enable user to import projects in TeamCity

It is not enough to belong to the “System Administrator” group to be able to import projects from backup  in TeamCity. The user has to be in the “System administrator” role for the “Root project”.

To enable the user to import projects into TeamCity

  • Click the Administration link in the upper right corner
  • In the User Management section click Users
  • Click the user name in the list
  • On the Roles tab click the + Assign role button
  • Set the Role to System administrator
  • Set the Scope to Root project
  • Select the Replace existing roles with newly selected check box and click the Assign button

Beginner’s Guide to DevOps Engineering part 5.

Create an enterprise cookbook

In this exercise we will create a Chef cookbook for a corporation. It will be robust and include all the necessary elements to be used in a large enterprise. If your company already has established standards, as you progress with this tutorial, copy the appropriate file from an existing cookbook. If this is the first cookbook in your organization, or you don’t want to follow the current standards, copy the sample files from this page.

Create the cookbook

  • Navigate to the C:\Chef\…\cookbooks folder and open a Bash window
  • Create an empty cookbook
    chef generate cookbook COOKBOOK_NAME

    Chef creates a new sub-folder with the name of the cookbook.

  • Rename the new folder to cookbook-COOKBOOK_NAME to distinguish it in version control from other repository types.

Update the .gitignore file

The last line is the most important! We want to exclude sensitive information from source control.


# Bundler


# Ignore the unencrypted Data Bags

Update the metadata.rb file

Add your name, email address, and the version of the cookbook to the top of the metadata.rb file

maintainer 'YOUR_NAME'
maintainer_email 'YOUR_EMAIL_ADDRESS'
license 'All rights reserved'
description 'Installs/Configures THE_NAME_OF_THE_COOKBOOK'
long_description, ''))
version '1.0.0'

The expression in the long_description line refers to the file that GitHub can create when you set up a new repository. Place the cookbook related information into that file, so others who want to use your cookbook can easily find it.

Update the .kitchen.yml file to be able to test your cookbook.

If you want to test your cookbook in the Cloud, copy the following sections from an existing .kitchen.yml file of your organization. To learn Chef and launch instances with Vagrant on your workstation, the automatically created .kitchen.yml file is perfect.

  • driver
  • provisioner
  • platforms
  • a suite as an example

If your organization use tags to track instances in the Cloud,  update the tags section to reflect the values of the cookbook.

The following is a sample .kitchen.yml file with Windows and Linux platforms

name: ec2
aws_ssh_key_id: YOUR_AWS_SSH_KEY_NAME
region: THE_AWS_REGION # us-east-1
availability_zone: THE_AWS_AVAILIBILITY_ZONE # e
subnet_id: THE_SUBNET_ID
require_chef_omnibus: true
Name: TK_test
Environment: DEV
created-by: test-kitchen
associate_public_ip: false #This can be false if test instance is accessible by VPN or LAN
retryable_tries: 120
retryable_sleep: 5
# interface: dns #uncomment if test instance should be registered with DNS

name: chef_zero

- name: windows-2012r2
image_id: "A_WINDOWS_AMI_ID"
instance_type: INSTANCE_TYPE # t2.large #Can be changed to any AWS instance size
security_group_ids: [ "SECURITY_GROUP_ID_1", "SECURITY_GROUP_ID_2" ]
name: winrm
elevated: true # Required for the installation of some Windows features
connection_timeout: 10
connection_retries: 5

- name: rhel7
image_id: "A_LINUX_AMI_ID"
instance_type: INSTANCE_TYPE # t2.medium #Can be changed to any AWS instance size
- device_name: /dev/sda1
volume_type: standard
volume_size: 100
delete_on_termination: true
security_group_ids: [ "SECURITY_GROUP_ID_1", "SECURITY_GROUP_ID_2" ]
ssh_key: C:\Users\YOUR_USERNAME\.aws\YOUR_KEY_FILE_NAME.pem
connection_timeout: 10
connection_retries: 5
sudo: true

- name: windows_server
data_bags_path: "data_bags"
encrypted_data_bag_secret_key_path: "../../data_bags/DATABAG_SECRET_FILE_NAME"
- rhel7

Encrypted Data Bags

If you want to use encrypted data bags, ask your Chef administrator to send you the key file to encrypt and decrypt data bags. In the sample .kitchen.yml file above the DATABAG_SECRET_FILE is the placeholder for the key file name. Create a folder for the key at


on the same level where the cookbook and environment folders are.


This is a chicken and egg paradox. We don’t want to commit secrets into version control, so we need to encrypt them. But how can we place the secret encryption key on the server to decrypt the secrets? We will use Packer to create our own server images that will contain the secret key, so when Chef starts to run on the server, the key is going to be there.

Default recipe

We will place code in the default.rb file that is common to all recipes in the cookbook. All custom recipes will call the default recipe as the first step.

Update the header comments of the default.rb recipe with your name and company information

# Cookbook Name:: COOKBOOK_NAME
# Recipe:: default
# Copyright (c) 2015-2016 COMPANY_NAME, All Rights Reserved.

Custom recipe

Make a copy of the default.rb file and name it to describe the purpose of the instance (server.rb)

  • Update the name of the recipe in the header
  • Add the following line under the header to call the default recipe, even if it is currently empty
    include_recipe 'COOKBOOK_NAME::default'

Add the cookbook to GitHub

Create the local repository

  • In the Bash window execute the following commands
git init
git add .
git commit -m "Initial commit"

Add the repository to GitHub

In your web browser log into your GitHub account and create a new repository

  • Click the New Repository button
  • Name the repository the same as the name of the folder of the cookbook (cookbook-…)
  • Execute the lines in the section …or push an existing repository….  If you work on a Windows workstation make sure HTTPS is selected
    git remote add origin
    git push -u origin master
  • In the Collaborators & teams section of Settings select the group who will have access to the new repository

Test the cookbook

In the Bash window launch the instance with Test Kitchen

List the available instances

kitchen list

Launch the instance


If there are multiple suites or platforms in the .kitchen.yml file you need to type the unique part of the name of the instance to identify it.

Start a Remote Desktop connection into the instance


Terminate the instance



Infrastructure as code in Beginner’s Guide to DevOps Engineering part 6.


to the Tutorials page

Beginner’s Guide to DevOps Engineering part 4.

Connect to the Chef server

Find a Chef Server

To work in a corporate environment, your organization needs access to a Chef server.

To learn Chef and test your cookbooks for free, you can create an account on the “hosted” Chef server, maintained by the Chef company. The plan allows five nodes at a time, so you can even launch a small server farm for yourself. Another option is to launch your own Chef server (on-premises) and manage up to 25 nodes on it for free. That could be enough for a small organization to get started with automation. Please see the Chef web portal for more information at

To use the “hosted” Chef server

To launch your own Chef server

Accessing the Chef Server

To access the Chef server you need a user account to log into the web interface and a key to access the server with command line tools, like knife.

Until you set up your workstation to access the Chef server, you will  get the following error message:

WARNING: No knife configuration file found
WARN: Failed to read the private key C:\chef\client.pem: #<Errno::ENOENT: No such file or directory @ rb_sysopen - C:\chef\client.pem>
ERROR: Your private key could not be loaded from C:\chef\client.pem
Check your configuration file and ensure that your private key is readable

To create a user account on the Chef server

  • Open the Chef server page in your web browser,
  • Click the Click here to get started! link to create a new account,
  • Enter your name, email address and username you want to use and click the Get Started button,
  • Open the email Chef Notifications sent you and click the long link to verify your email address,
  • On the Email Verification page enter the password you want to use on the Chef server and click the Create User button,

Ask your Chef server administrator to invite you to an organization on the Chef server

The administrator

  • Using a web browser log into the Chef server user interface,
  • In the upper right corner select the organization to invite the user to,
  • On the Administration tab select Users on the left side,
  • Under Users click Invite,
  • Enter the username of the new registered user and click the Invite button

Accept the invite

  • Using a web browser log into the Chef server user interface,
  • On the Welcome to Chef page click the Accept Invite button. If you are already logged into the Chef server user interface, the upper right corner will show you the number of invitations you have received. Click on the number to accept the invitation.
  • Select the check box next to the organization you want to be part of and click the Accept button.

Download your key to access the Chef server

  • Using a web browser log into the Chef server user interface,
  • In the upper right corner click your name and select My Profile,
  • In the lower right click the Reset Key link,
  • Click the Download button to download your private .pem key file.

Configure knife

The knife command is used to interact with the Chef server. Before you can connect to the Chef server we need to configure knife

  • Open a Bash window in the c:\Chef folder
  • Execute
    knife configure
  • Answer the questions. To get the company specific values ask someone who already has a knife.rb file set up at C:\Chef\.chef
    Where should I put the config file? C:/Chef/.chef/knife.rb
    Please enter the chef server URL: YOUR_CHEF_SERVER_URL (the URL should end with the name of the organization)
    Please enter an existing username or clientname for the API: YOUR_CHEF_USERNAME
    Please enter the validation clientname: VALIDATOR_KEY_NAME (Ask your Chef server administrator)
    Please enter the location of the validation key: VALIDATOR_FILE_NAME.pem (Get the file from your Chef server administrator)
    Please enter the path to a chef repository (or leave blank): #{current_dir}/..
  • Open the C:/Chef/.chef/knife.rb file and make the following changes
    • Insert to the top of the file
       # See for more information on knife configuration options
      current_dir = File.dirname(__FILE__)
    • In the validation_key line replace C:/Chef with
    • Append to the end of the file to be able to edit cookbook files and data bags from the command line
    • The file should look like this
      # See for more information on knife configuration options
      current_dir = File.dirname(__FILE__)
      log_level               :info
      log_location            STDOUT
      node_name               'YOUR_CHEF_USERNAME'
      client_key              'C:/Chef/.chef/YOUR_CHEF_USERNAME.pem'
      validation_client_name  'VALIDATOR_KEY_NAME'
      validation_key          'C:/Chef/.chef/VALIDATOR_FILE_NAME.pem'
      chef_server_url         'https://YOUR_CHEF_SERVER_URL/organizations/YOUR_ORGANIZATION'
      syntax_check_cache_path 'C:/Chef/.chef/syntax_check_cache'
      cookbook_path           [ '#{current_dir}/../cookbooks' ]

Save the key files on your workstation

  • Move the .pem Chef server private key file, you have downloaded during the Chef user registration, to the C:/Chef/.chef directory.
  • Get the VALIDATOR_FILE_NAME.pem file from your Chef server administrator and save it in the C:/Chef/.chef directory.

Test the Chef server connectivity

  • Open a Bash window in the folder of the cookbook at C:\Chef\cookbooks\test
  • Execute
knife cookbook list

to see the list of the available cookbooks on the Chef server.

Upload the cookbook to the Chef server

knife cookbook upload COOKBOOK_NAME --freeze

The –freeze option is the most important. It locks the cookbook on the Chef server so we are forced to increment the version before we upload a new version of the cookbook.


Create an enterprise cookbook in Beginner’s Guide to DevOps Engineering part 5.


to the Tutorials page

Permission denied message when you try to upload your new repository to GitHub from a Windows computer

If you work on a Windows computer and create a new GitHub repository, you can copy the code from the GitHub page to set the remote address and push the existing code to the GitHub server. You may get the following error message:

$ git push -u origin master
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Make sure you have selected the HTTPS button to see the correct lines for Windows.

To change to address of the remote server execute the following
git remote set-url origin

Beginner’s Guide to DevOps Engineering part 3.

Working with AWS

Install the AWS EC2 drivers

Open a Bash or CMD window in the Chef cookbook folder

  • Install the kitchen-ec2 driver
    More info on the ec2 driver at
    chef gem install kitchen-ec2
  • Install the  chef-zero-scheduled-task plugin
    chef gem install chef-zero-scheduled-task
  • Install the latest vagrant plugin
    chef gem install kitchen-vagrant

Personalize your workstation

Set up your account in the AWS console

If you are not an AWS account administrator, ask your AWS account administrator to do the following for you

  • Create an account in AWS
  • Add the account to the appropriate user group
  • Generate a password with a request to change it at the first login
  • Generate an AWS Access Key ID and Secret Key
    • Using your browser log into the AWS console
    • In the upper right corner click your user id
    • In the drop down list select Security Credentials
    • On the left select Users
    • In the user list select you account
    • Select the Security Credentials tab
    • Click the Create Access Key button

AWS Command Line Interface



If you do not configure the AWS CLI you will get the following error message: ‘NoneType’ object has no attribute ‘get_frozen_credentials’

  • Open a Bash window and execute the following command to save your AWS credentials and default region in the C:\Users\YOUR_USER_NAME\.aws folder
    aws configure
    • Answer the questions
      AWS Access Key ID [None]: YOUR AWS KEY
      AWS Secret Access Key [None]: YOUR AWS SECRET KEY
      Default region name [None]: us-east-1
      Default output format [None]: HIT ENTER FOR NONE

Close and reopen all open Bash and Command windows to reload the changed Path environment variable.

Your  credentials file will look like this

 aws_access_key_id = MY_ACCESS_KEY
 aws_secret_access_key = MY_SECRET_KEY

When you work with multiple AWS accounts you can add all of your keys to the credentials file. To use a specific key, add the profile option to your command line instructions. If you don’t specify the profile in your AWS commands, the AWS Command Line Interface will use the key from the default section.

 aws_access_key_id = MY_ACCESS_KEY_FOR_AWS01
 aws_secret_access_key = MY_SECRET_KEY_FOR_AWS01

 aws_access_key_id = MY_ACCESS_KEY_FOR_AWS02
 aws_secret_access_key = MY_SECRET_KEY_FOR_AWS02

 aws_access_key_id = MY_ACCESS_KEY_FOR_AWS01
 aws_secret_access_key = MY_SECRET_KEY_FOR_AWS01

The config file will look like this. If you don’t specify the region in the AWS command, the AWS Command Line utility will use the region from this file.

region = us-east-1

Collect the following information to be able to launch an instance in AWS


  • Your IAM user name
  • AWS Access Key and Secret Key
  • Region (us-east-1)
  • Availability zone (b)
  • VPC subnet ID
  • Security group ID
  • AWS key pair file
  • AMI ID


Generate an AWS key pair

  • Log into the AWS console
  • Select EC2
  • Under Network & Security select Key Pairs
  • In the upper right corner select the region
  • Click the Create Key Pair button
    Create your key pair with the following naming scheme:
    For example: USERID_aws01_us_east_1
  • Download the .pem private key file and save it in the C:\Users\YOUR_USER_NAME\.aws directory you created above during the AWS CLI configuration.

For more info visit Amazon EC2 Key Pairs

Set up your .kitchen.yml file

When you have created your cookbook, Chef already added a .kitchen.yml file that tells Test Kitchen how to launch a server instance on your workstation.

The default .kitchen.yml file only contains driver and provisioner information for Vargrant. To launch a server instance in AWS we need to add AWS specific instructions to the file. First modify the .kitchen.yml file to be ready for other drivers:

  name: chef_zero

  name: inspec

  - name: ubuntu-16.04
      name: vagrant

  - name: centos-7.2
      name: vagrant

  - name: default
      - recipe[test::default]
        - test/recipes

Make sure the empty lines are really empty. The .kitchen.yml file cannot have white space in a seemingly empty line.



Connect to the Chef server in Beginner’s Guide to DevOps Engineering part 4.


to the Tutorials page

List the installed Windows Features on the Windows server with PowerShell

When you set up a new Windows server and want to make sure all necessary Windows features are installed on it, you can list them in text format. If you want to replicate the configuration of an existing server, just list the features of both servers and compare them in a comparison tool, like Araxis Merge.

To list the installed Windows features, execute the following in the PowerShell prompt


The result follows the layout of the check boxes of the graphical user interface in text form.

[X] Web Server (IIS)         Web-Server                 Installed
   [X] Web Server            Web-WebServer              Installed
   [X] Common HTTP           Features Web-Common-Http   Installed
   [X] Default Document      Web-Default-Doc            Installed
   [X] Directory Browsing    Web-Dir-Browsing           Installed
   [X] HTTP Errors           Web-Http-Errors            Installed
   [X] Static Content        Web-Static-Content         Installed
   [X] HTTP Redirection      Web-Http-Redirect          Installed
   [ ] WebDAV Publishing     Web-DAV-Publishing         Available