By Arslan Ud Din Shafiq, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud's incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.
Chef is a powerful platform for automation that helps you to automate how infrastructure is configured, deployed and managed across your network. It transforms infrastructure into code and allows you to manage and deploy resources across multiple nodes or servers. Before deploying code to any other environment, you create it and test it on your workstation. On your workstation, you can administer your infrastructure and write your cookbooks.
In this tutorial, I will show you how to install and set up a Chef Server Workstation on Alibaba Cloud Elastic Compute Service (ECS) with Ubuntu 16.04.
Before proceeding with installation of any kind of package, use the following command to update your Ubuntu system. To execute this command, remember to login from non-root user with sudo privileges.
# sudo apt update && sudo apt upgrade
Chef server behaves as a hub of interaction between all nodes and workstations using Chef. When changes are made, these are uploaded to Chef server. After it, chef client accesses Chef server and helps in configuring each individual node. To install Chef server, follow the steps below.
You will need to download Chef server core. To download it, execute the following command.
# wget https://packages.chef.io/files/stable/chef-server/12.17.33/ubuntu/16.04/chef-server-core_12.17.33-1_amd64.deb
You will need to de-package and install the .deb using the following command.
# sudo dpkg -i chef-server-core_12.17.33-1_amd64.deb
Remove the downloaded .deb file by executing the command below.
# sudo rm chef-server-core_12.17.33-1_amd64.deb
Execute the following command to start Chef server command line utility. It will start Chef server services.
# sudo chef-server-ctl reconfigure
You will see the following screen if your installation is successful.
For linking nodes and workstations to your Chef server, you will need to create an admin user and organization with associated RSA private keys. To do so, follow the steps below.
Create a directory for storing the keys by executing the command below.
# mkdir .chef
To create user, you will use Chef command line utility. Execute the following command to create a user and remember to replace aareez with your desired username, 123@example.com with your desired email address and file name aareez.pem to your_username.pem, 654321Ab with your desired password, Arslan with your first name and Malik with your last name.
# sudo chef-server-ctl user-create aareez Arslan Shafiq 123@example.com '654321Ab' --filename ~/.chef/aareez.pem
Create an organization and add the user created in the step above in admins and billing admins security groups. To do so, execute the following command.
# sudo chef-server-ctl org-create org_name "org_full_name" --association_user aareez --filename ~/.chef/org_name.pem
Remember to replace org_name and org_full_name with your organization's name and aareez with your username.
Create a new Alibaba Cloud instance for Chef Workstation and update it.
# sudo apt update && sudo apt upgrade
Install Git with the command below.
# sudo apt-get install git
(Optional) Execute the commands below to configure Git by providing your name and valid email address so that commit messages may contain your correct information.
# git config --global user.name "Aareez"
# git config --global user.email "xyz@example.com"
A Chef workstation allows you to create and configure your recipes, cookbooks, attributes and other changes made to your Chef configurations. To install and configure Chef Development Kit, follow the steps below.
You will need to download the Chef Development Kit by executing the command below.
# wget https://packages.chef.io/files/stable/chefdk/3.3.23/ubuntu/16.04/chefdk_3.3.23-1_amd64.deb
To install Chef Development Kit, execute the following command.
# sudo dpkg -i chefdk_3.3.23-1_amd64.deb
Remove the download .deb file by executing command below.
# sudo rm chefdk_3.3.23-1_amd64.deb
Generate chef-repo by executing command below.
# chef generate app chef-repo
Navigate to chef-repo
# cd chef-repo
Create .chef directory for storing aareez.pem, organization-validator.pem and knife.rb. Execute the following command.
# mkdir .chef
The RSA keys generated while setting up and installing Chef server will be placed on the workstation. To do so, execute the following command.
# scp aareez@softpedia.xyz:~/.chef/*.pem ~/chef-repo/.chef/
Remember to replace aareez with your username and softpedia.xyz with your domain name or ECS IP address.
To confirm if the files have been copied successfully, you may execute the following command.
# ls ~/chef-repo/.chef
You will need to add .chef directory to .gitignore file. To do so, execute the command below.
# echo ".chef" > .gitignore
You will need to add and commit all existing files. For this, execute the command below.
For adding: # git add .
For committing: # git commit -m "initial commit"
You may check the status by executing command below.
# git status
To generate knife.rb file, follow the steps below.
Navigate to /chef-repo/.chef by executing the following command.
# cd ~/chef-repo/.chef
Create a file named knife.rb, a file will be opened in nano text editor by executing the command below.
# sudo nano knife.rb
Copy and paste the following text in opened file. Remember to replace aareez with your Chef server user name, org_name with your organization's name and chef_server_url value with your own domain or IP address.
current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name 'aareez'
client_key "aareez.pem"
validation_client_name 'org_name-validator'
validation_key "org_name-validator.pem"
chef_server_url 'https://softpedia.xyz/organizations/org_name'
cache_type 'BasicFile'
cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
cookbook_path ["#{current_dir}/../cookbooks"]
Navigate back to /chef-repo and fetch by using commands below.
# cd ..
# knife ssl fetch
You can confirm if knife.rb has been set up correctly by executing the command below.
# knife client list
With a configured workstation and server, you may now bootstrap your first node.
In bootstrapping a node, Chef client is installed. It validates the node and allows to read from Chef server and allows to make configurations. To bootstrap a node, follow the steps below.
Navigate to /chef-repo/.chef by executing the following command.
# cd ~/chef-repo/.chef
As a user with sudo privileges, execute the following command. Remember to change aareez with your node username, 654321Ab with password of user, softpedia.xyz with IP address or domain of Chef server and imaareez with name that you want to give to your node.
# knife bootstrap softpedia.xyz -x aareez -P 654321Ab --sudo --node-name imaareez
You can confirm if the node has been bootstrapped by executing the command below.
# knife client list
If you have activated firewalls, you will have to define a rule in Alibaba Cloud security group for your cloud server to add exception for port 80/tcp and 443/tcp. You can enable these ports while creating ECS instance, but in case if you have forgotten to unblock these ports, you can follow the procedure in this guide: https://www.alibabacloud.com/help/doc-detail/25471.htm
Congratulations! You have successfully installed and configured Chef Server and Chef Server Workstation on your ECS instance.
2,599 posts | 764 followers
FollowAlibaba Clouder - October 12, 2019
Alibaba Clouder - June 14, 2019
Alibaba Clouder - July 24, 2020
Alibaba Clouder - June 14, 2019
Alibaba Clouder - July 12, 2018
Alibaba Clouder - November 18, 2019
2,599 posts | 764 followers
FollowRobotic Process Automation (RPA) allows you to automate repetitive tasks and integrate business rules and decisions into processes.
Learn MoreAccelerate software development and delivery by integrating DevOps with the cloud
Learn MoreAn enterprise-level continuous delivery tool.
Learn MoreExplore Web Hosting solutions that can power your personal website or empower your online business.
Learn MoreMore Posts by Alibaba Clouder