setting up a basic chef environment; chef server, chef workstation, nodes

Info:

setup 3 vm with below info, put these names under the hosts file on each vm.
Server Name
Function
Local user
chef-server
Chef server
anthony
chef-ws
Chef workstation
anthony
chef-client
Chef node
anthony

Setting up chef-server - standalone

Download the required installer file from chef website
$ dpkg -i chef-server-core_12.8.0-1_amd64.deb            
$ chef-server-ctl reconfigure
$ cd /etc/chef
$ chef-server-ctl user-create anthony anthony chin anthony.chin@bluecoat.com 'P@ssw0rd' --filename anthony.pem
$ chef-server-ctl org-create abctest 'ABC Test Co.' --association_user anthony --filename abctest-validator.pem

Setting up chef-workstation

In Ubuntu 16.04 workstation, download the chef-dk from chef website
$ dpkg -i chefdk_0.17.17-1_amd64.deb
$ mkdir -p ~/learn-chef/.chef
$ vi knife.rb

# See http://docs.chef.io/config_rb_knife.html for more information on knife configuration options

current_dir = File.dirname(__FILE__)
log_level                :info
log_location             STDOUT
node_name                "anthony"
client_key               "#{current_dir}/anthony.pem"
chef_server_url          "https://chef-server/organizations/abctest"
cookbook_path            ["#{current_dir}/../cookbooks"]

$ scp anthony@chef-server:/etc/chef/anthony.pem ./
$ knife ssl fetch  ß this will get the server certificate from chef-server when the server cert is self-sign.
$ knife ssl check
$ knife node list   ß if you are able to run this without any error, thus you have successfully authenticated with the chef-server

Setting up a cookbook

Extract and save the files under ~/learn-chef/cookbooks/
$ cd ~/learn-chef/cookbooks
$ knife cookbook list
$ knife cookbook upload learn_chef_apache2
$ knife cookbook list

Setting up chef-client (bootstrap from chef-workstation)

From chef-workstation
$ knife node list
$ knife bootstrap chef-client --ssh-user anthony --ssh-password 'P@ssw0rd' --sudo --use-sudo-password --node-name chef-client --run-list 'recipe[learn_chef_apache2]'
$ knife node list     ß you will have a “chef-client” node being added with a recipe associated
$ knife node show chef-client

By now, you have installed a chef server, chef workstation, and bootstrapped a node with a recipe associated with it.

Try load the http://chef-client from web browser and you shall get a “hello word” page.

No comments: