This tutorial will assist you in setting up a Chef Server
- hosted at Chef.io , Chef Workstation
& Chef Nodes
running on AWS as EC2 Instances.
- Create account in chef from manage.chef.io website.
- Create a organization
- Create two instances,
- One for workstation and
- Another one to act as the remote node on AWS account
- The security groups should have the following ports open,
22, 80, 443
-
Download Chef starter kit from hosted Chef Server
-
SCP the starter kit into your workstation and unzip in /root directory. It generates
/chef-repo
.yum install unzip -y cd / unzip chef-starter.zip cd /chef-repo curl -L https://www.opscode.com/chef/install.sh | bash
-
Validate the SSL certificate & authenticate calls to Chef Server
knife ssl check
-
Validate your connection to the Chef server, One way to do that is to run the
knife client list
command. -
We have configured our Chef Server(hosted in chef site) and Chef workstation, Authentication is established by the
Starter-Kit
.
We call the process that installs
chef-client
on a node and the initial checkin to the Chef server bootstrapping the node.
- Lets tag our node as
chef-node01
. I used the same tag in EC2 as well to remember it easily. - Copy the EC2 key to your workstation to
./chef/chef-node-key.pem
knife bootstrap <EC2_IP_Addr> \
--ssh-user ec2-user --sudo \
--identity-file /chef-repo/.chef/<AWS_SSH_Key> \
--node-name chef-node01
- To confirm the list of nodes registered to the Chef-Server
knife node list
or
knife node show chef-node01
- Login to chef node and edit
/etc/chef/client.rb
file add below linelog_level :info
knife cookbook create learn-httpd
- Go inside directory cookbooks/learn-httpd/recipes
- cd cookbooks/learn-httpd/recipes
- Edit default.rb file add below code to install httpd package.
package "httpd"
service "httpd" do
action [:enable, :start]
end
file '/var/www/html/index.html' do
content '<h1> I am on top of the world</h1>'
end
- Upload this new code to your chef server by using below command
knife cookbook upload learn-httpd
-
If you want to double-check your cook books
knife cookbook list
-
Now go to your chef node and run chef-client to get latest cookbooks from servers.
chef-client
- Note: even though our code is currect. It cant install apache. Because we haven’t set this node to run recipes. To do that we should run below command.
knife node run_list add chef-node01 "recipe[learn-httpd]"
-
Run
chef-client
from your node to run the recipe. -
Load the webserver page
curl localhost
or
curl <your_public_ip>
knife node delete chef-node01 --yes