Chef infrastructure setup

From Notes_Wiki
Revision as of 13:31, 20 May 2021 by Saurabh (talk | contribs)

<yambe:breadcrumb>Chef|Chef</yambe:breadcrumb>

Chef infrastructure setup

These steps were tried on an openVZ container based setup. Unfortunately node bootstrap fails if all three machines server, workstation and node are configured as openVZ containers. Whether these steps work on a VM or not is not verified.


Install Chef server

In case of a virtual server (such as openVZ container) 2.5GB RAM, 500k inodes and 10GB disk space is recommended

  1. yum -y install postgresql
  2. Download chef server from http://downloads.chef.io/chef-server/
  3. rpm -ivh *.rpm
  4. chef-server-ctl reconfigure
    At least in the case of openVZ containers following additional things need to be done:
    1. 'chef-server-ctl reconfigure' needs to be run twice so that installation ends with
      Chef Client finished, 396/448 resources updated in 109.272186048 seconds
      opscode Reconfigured!
    2. Container needs to be rebooted after package is installed for things to work. Without this following error message would be received while trying to create a new user using chef-server-ctl
      ERROR: Errno::ECONNRESET: Connection reset by peer - SSL_connect
  5. Download ops-manage from http://downloads.getchef.com/chef-manage/ to /root
  6. chef-server-ctl install opscode-manage --path /root
  7. opscode-manage-ctl reconfigure
  8. chef-server-ctl reconfigure
  9. chef-server-ctl user-create saurabh Saurabh Barjatiya saurabh@example.com secret123 --filename saurabh.pem
  10. Open http://<server-IP>/ and login using username (saurabh) and password (secret123)
  11. Create organization and download starter kit. It will warn about regenerating keys. That is ok.
  12. Other way to create organization is:
    chef-server-ctl org-create rekall Rekall Software Pvt. Ltd. --association_user saurabh --filename rekall.pem
  13. Save starter-kit on a workstation and use it to work with server

Steps learned from https://docs.chef.io/install_server.html


Configure chef-server and knife workstation combination using command line

  1. On chef server create a new user using:
    chef-server-ctl user-create user_name first_name last_name email password --filename FILE_NAME
    chef-server-ctl user-create saurabh Saurabh Barjatiya saurabh@example.com secret123 --filename saurabh.pem
  2. Then create a new organization using:
    chef-server-ctl org-create short_name full_organization_name --association_user user_name --filename FILE_NAME
    Example
    chef-server-ctl org-create rekall Rekall Software Pvt. Ltd. --association_user saurabh --filename rekall.pem
  3. Install chef development kit on client as explained at chef-apply and receipe syntax
  4. Verify using chef-client -v that client got installed properly
  5. Create ~/.chef and copy the two user and organization pem files to this folder
  6. Now create "~/.chef/knife.rb" with following content:
    current_dir = File.dirname(__FILE__)
    log_level :info
    log_location STDOUT
    node_name "saurabh"
    client_key "#{current_dir}/saurabh.pem"
    validation_client_name "saurabh-rekall"
    validation_key "#{current_dir}/rekall.pem"
    chef_server_url "https://chefserver/organizations/rekall"
    cache_type 'BasicFile'
    cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
    cookbook_path ["#{current_dir}/../cookbooks"]
    Here node_name must match with the name of the user for which client key was generated.
  7. Run "knife user list" and "knife client list" commands to verify whether knife configuration is working
  8. Create "~/cookbooks" folder for cookbooks as specified in ~/.chef/knife.rb

More info on knife configuration is available at https://docs.chef.io/config_rb_knife.html

Steps learned from http://sachinsharm.wordpress.com/2013/10/11/installsetup-and-configure-chef-serverworkstationnode-on-centosrhel-6-4/


Configure a new node to interact with chef-server

  1. To configure a new node to work with chef server use:
    knife bootstrap {{address}} --ssh-user {{user}} --ssh-password '{{password}}' --node-name node1 --run-list 'recipe[learn_chef_httpd]'
    For example
    knife bootstrap 192.168.122.105 --ssh-user root --ssh-password secret123 --node-name dns



<yambe:breadcrumb>Chef|Chef</yambe:breadcrumb>