Skip to content
This repository has been archived by the owner on Mar 7, 2019. It is now read-only.
/ Learn-Chef Public archive

Learn how to setup Hosted Chef Server to manage AWS EC2 Instances

Notifications You must be signed in to change notification settings

miztiik/Learn-Chef

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How-To setup Chef to manage your servers.

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.

Hosted Chef Server Preparation

  • Create account in chef from manage.chef.io website.
  • Create a organization

Create EC2 Instances to act as nodes

  • 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

Configure Chef Workstation

  • 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.

Chef Node[s] bootstrapping

We call the process that installs chef-client on a node and the initial checkin to the Chef server bootstrapping the node.

Bootstrap using key-based authentication

  • 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 line log_level :info

Create cookbook learn-httpd

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>

Clean up your environment

Delete the node from the Chef server

knife node delete chef-node01 --yes

About

Learn how to setup Hosted Chef Server to manage AWS EC2 Instances

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published