{"id":100,"date":"2015-09-26T21:32:45","date_gmt":"2015-09-26T21:32:45","guid":{"rendered":"http:\/\/cephswift.com\/?page_id=100"},"modified":"2015-09-28T02:00:30","modified_gmt":"2015-09-28T02:00:30","slug":"chef-setup","status":"publish","type":"page","link":"https:\/\/cephswift.com\/index.php\/chef-setup\/","title":{"rendered":"Chef automation setup"},"content":{"rendered":"<p>Chef server, client, and workstation setup:<\/p>\n<p>root@chef_server:~# <\/p>\n<p># sudo apt-get upgrade  # use this command to update software first on ubuntu linux<\/p>\n<p>Install  ruby and verify before Chef Env setup:<\/p>\n<p># sudo apt-get install ruby-full<br \/>\n# which ruby    ## verify if ruby get install<br \/>\n# ruby -v<br \/>\n# wget https:\/\/opscode-omnibus-packages.s3.amazonaws.com\/ubuntu\/12.04\/x86_64\/chef-server_11.0.8-1.ubuntu.12.04_amd64.deb<\/p>\n<p># which ruby<br \/>\n   \/bin\/ruby<\/p>\n<p> reset ruby path: ( after the Chef development kit is installed to\/opt\/chefdk\/ on UNIX and Linux systems )<\/p>\n<p>  https:\/\/docs.chef.io\/install_dk.html<\/p>\n<p># echo &#8216;eval &#8220;$(chef shell-init bash)&#8221;&#8216; >> ~\/.bash_profile<\/p>\n<p># which ruby<\/p>\n<p>  \/opt\/chefdk\/embedded\/bin\/ruby<\/p>\n<p>Chef server download and install<\/p>\n<p># wget https:\/\/opscode-omnibus-packages.s3.amazonaws.com\/ubuntu\/12.04\/x86_64\/chef-server_11.0.8-1.ubuntu.12.04_amd64.deb<br \/>\n # sudo dpkg -i chef-server_11.0.8-1.ubuntu.12.04_amd64.deb<br \/>\n # sudo chef-server-ctl reconfigure<\/p>\n<p># root@chef_server:~# dpkg &#8211;list | grep chef         ### list chef pkg installed<br \/>\n# root@chef_server:~# dpkg -P chef-server chef-zero   ### remove chef after install on ubountu linux if you don&#8217;t need it any more<\/p>\n<p>Recipe: chef-server::erchef<br \/>\n  * service[erchef] action restart<br \/>\n    &#8211; restart service service[erchef]<\/p>\n<p>Chef Client finished, 270 resources updated<br \/>\nchef-server Reconfigured!<br \/>\nChef_server running status check:<\/p>\n<p># chef-server-ctl status<br \/>\nrun: bookshelf: (pid 995) 2262767s; run: log: (pid 993) 2262767s<br \/>\nrun: chef-expander: (pid 990) 2262767s; run: log: (pid 989) 2262767s<br \/>\nrun: chef-server-webui: (pid 996) 2262767s; run: log: (pid 994) 2262767s<br \/>\nrun: chef-solr: (pid 1644) 2262430s; run: log: (pid 987) 2262767s<br \/>\nrun: erchef: (pid 998) 2262767s; run: log: (pid 997) 2262767s<br \/>\nrun: nginx: (pid 1000) 2262767s; run: log: (pid 999) 2262767s<br \/>\nrun: postgresql: (pid 1007) 2262767s; run: log: (pid 1004) 2262767s<br \/>\nrun: rabbitmq: (pid 992) 2262767s; run: log: (pid 991) 2262767s<\/p>\n<p>Chef_Server running Status UI login:<\/p>\n<p>https:\/\/192.168.1.2\/users\/login    ### you may login to web ui, to play with&#8230;as you do in command line.<\/p>\n<p>192.168.1.2 \u2013-> chef_server<\/p>\n<p>username: admin<\/p>\n<p>password: p@ssw0rd1   #### change to WHAT YOUR WANT then SAVE to somewhere !!!!!<\/p>\n<p>Please change the default password immediately after logging in!<br \/>\nPublic and Private Key created from chef server admin:<br \/>\nClient: chef-validator<br \/>\nchef-validator.pub.pem<\/p>\n<p>&#8212;&#8211;BEGIN PUBLIC KEY&#8212;&#8211;<br \/>\n&#8212;&#8211;END PUBLIC KEY&#8212;&#8211;<\/p>\n<p>root@chef_server:\/etc\/chef-server# cat chef-validator.pem<\/p>\n<p>&#8212;&#8211;BEGIN RSA PRIVATE KEY&#8212;&#8211;<br \/>\n&#8212;&#8211;END RSA PRIVATE KEY&#8212;&#8211;<\/p>\n<p>default admin user and passed:<\/p>\n<p>login: admin<br \/>\npasswd: <\/p>\n<p>added admin user:<br \/>\nlogin:<br \/>\npasswd:<\/p>\n<p>admin key for ADDED USER     ### save the key to some where for later use&#8230;. <\/p>\n<p>&#8212;&#8211;BEGIN PUBLIC KEY&#8212;&#8211;<br \/>\n&#8212;&#8211;END PUBLIC KEY&#8212;&#8211;<\/p>\n<p>&#8212;&#8211;BEGIN RSA PRIVATE KEY&#8212;&#8211;<br \/>\n&#8212;&#8211;END RSA PRIVATE KEY&#8212;&#8211;<\/p>\n<p>For Chef server:<\/p>\n<p>admin key:<\/p>\n<p>&#8212;&#8211;BEGIN PUBLIC KEY&#8212;&#8211;<br \/>\n&#8212;&#8211;END PUBLIC KEY\u2014\u2014<\/p>\n<p>&#8212;&#8211;BEGIN RSA PRIVATE KEY&#8212;&#8211;<br \/>\n&#8212;&#8211;END RSA PRIVATE KEY&#8212;&#8211;<\/p>\n<p>Remove &#038; uninstall not worked Chef installed:<\/p>\n<p>[root@chef_server ~]# rpm -qa *chef*<br \/>\nchef-server-11.1.5-1.el6.x86_64<br \/>\nchef-12.2.0-1.el6.x86_64<\/p>\n<p>root@chef_server ~]# yum remove *chef*  ### this is for Chef clean up on Centos Linux, if chef was instlled with yum&#8230;.<br \/>\n===========================================================================================================================<\/p>\n<p>root@chef_ws:~#  #### you may assign IP as 192.168.1.3 for this host<\/p>\n<p>Workstation Setup:<\/p>\n<p>[root@chef_ws]# <\/p>\n<p>Install ruby as what have been done in chef server, then download and install \u201cchefdk\u201d:<\/p>\n<p># sudo dpkg -i chefdk_0.4.0-1_amd64.deb<\/p>\n<p>root@chef_ws:\/tmp\/chef_pkgs# ls -ltr<br \/>\ntotal 328324<br \/>\n-rw-r&#8211;r&#8211; 1 root root 197934506 Apr 23  2013 chef-server_11.0.8-1.ubuntu.12.04_amd64.deb<br \/>\n-rw-r&#8212;&#8211; 1 root root 138265262 Mar 30 17:52 chefdk_0.4.0-1_amd64.deb<\/p>\n<p>root@chef_ws:\/tmp\/chef_pkgs# sudo dpkg -i chefdk_0.4.0-1_amd64.deb<br \/>\nSelecting previously unselected package chefdk.<br \/>\n(Reading database &#8230; 82743 files and directories currently installed.)<br \/>\nPreparing to unpack chefdk_0.4.0-1_amd64.deb &#8230;<br \/>\nUnpacking chefdk (0.4.0-1) &#8230;<br \/>\nSetting up chefdk (0.4.0-1) &#8230;<br \/>\nThank you for installing Chef Development Kit!<\/p>\n<p>=========================================================================================<br \/>\nroot@chef_ws:\/tmp\/chef_pkgs# curl -O -L http:\/\/www.opscode.com\/chef\/install.sh<\/p>\n<p>root@chef_ws:\/tmp\/chef_pkgs# ls -l<br \/>\ntotal 328344<br \/>\n-rw-r&#8212;&#8211; 1 root root 138265262 Mar 30 17:52 chefdk_0.4.0-1_amd64.deb<br \/>\n-rw-r&#8211;r&#8211; 1 root root 197934506 Apr 23  2013 chef-server_11.0.8-1.ubuntu.12.04_amd64.deb<br \/>\n-rw-r&#8211;r&#8211; 1 root root     18373 Mar 31 10:42 install.sh<\/p>\n<p>root@chef_ws:\/tmp\/chef_pkgs# sudo sh install.sh<\/p>\n<p>Downloading Chef  for ubuntu&#8230;<br \/>\ndownloading http:\/\/www.opscode.com\/chef\/metadata?v=&#038;prerelease=false&#038;nightlies=false&#038;p=ubuntu&#038;pv=14.04&#038;m=x86_64<br \/>\n  to file \/tmp\/install.sh.15425\/metadata.txt<br \/>\ntrying wget&#8230;<br \/>\nurl\thttp:\/\/opscode-omnibus-packages.s3.amazonaws.com\/ubuntu\/13.04\/x86_64\/chef_12.2.1-1_amd64.deb<br \/>\nmd5\t84119f54115d754373c9891b8759497c<br \/>\nsha256\t8e0a8a2477c11615f86ffe686a68fa6636112ba82ebe6bb22daa5dd416f3c13e<br \/>\ndownloaded metadata file looks valid&#8230;<br \/>\ndownloading http:\/\/opscode-omnibus-packages.s3.amazonaws.com\/ubuntu\/13.04\/x86_64\/chef_12.2.1-1_amd64.deb<br \/>\n  to file \/tmp\/install.sh.15425\/chef_12.2.1-1_amd64.deb<br \/>\ntrying wget&#8230;<br \/>\nComparing checksum with sha256sum&#8230;<br \/>\nInstalling Chef<br \/>\ninstalling with dpkg&#8230;<br \/>\nSelecting previously unselected package chef.<br \/>\n(Reading database &#8230; 125291 files and directories currently installed.)<br \/>\nPreparing to unpack &#8230;\/chef_12.2.1-1_amd64.deb &#8230;<br \/>\nUnpacking chef (12.2.1-1) &#8230;<br \/>\nSetting up chef (12.2.1-1) \u2026<br \/>\nThank you for installing Chef!<\/p>\n<p>root@chef_ws:\/tmp\/chef_pkgs# <\/p>\n<p>==============================================<br \/>\nhttp:\/\/thornelabs.net\/2013\/09\/16\/install-the-open-source-chef-server-setup-knife-on-your-workstation-and-bootstrap-your-first-client-server.html<\/p>\n<p>root@chef_ws:\/tmp\/chef_pkgs# mkdir ~\/Development<br \/>\nroot@chef_ws:\/tmp\/chef_pkgs# cd ~\/Development<br \/>\nroot@chef_ws:~\/Development# git clone https:\/\/github.com\/opscode\/chef-repo.git<br \/>\nCloning into &#8216;chef-repo&#8217;&#8230;<br \/>\nremote: Counting objects: 250, done.<br \/>\nremote: Total 250 (delta 0), reused 0 (delta 0), pack-reused 250<br \/>\nReceiving objects: 100% (250\/250), 49.55 KiB | 0 bytes\/s, done.<br \/>\nResolving deltas: 100% (70\/70), done.<br \/>\nChecking connectivity&#8230; done.<br \/>\nroot@chef_ws:~\/Development# <\/p>\n<p># cd ~\/Development\/chef-repo<br \/>\n# mkdir .chef<br \/>\n# cd .chef<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo\/.chef# <\/p>\n<p># vi chef-validator.pem<br \/>\n# vi chef-client-validator.pub.pem<br \/>\n# vi admin.pem<br \/>\n# vi admin.pub.pem<\/p>\n<p># cd ~\/Development\/chef-repo\/.chef\/<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo\/.chef\/<\/p>\n<p># knife configure<\/p>\n<p>Overwrite \/root\/Development\/chef-repo\/.chef\/knife.rb? (Y\/N) Y<br \/>\nPlease enter the chef server URL: [https:\/\/192.168.1.2:443] https:\/\/192.168.1.2:443<br \/>\nPlease enter an existing username or clientname for the API: [root] admin<br \/>\nPlease enter the validation clientname: [chef-validator] chef-validator<br \/>\nPlease enter the location of the validation key: [\/etc\/chef-server\/chef-validator.pem] ~\/Development\/chef-repo\/.chef\/chef-validator.pem<br \/>\nPlease enter the path to a chef repository (or leave blank):<br \/>\n*****<\/p>\n<p>You must place your client key in:<br \/>\n  \/root\/Development\/chef-repo\/.chef\/admin.pem<br \/>\nBefore running commands with Knife!<\/p>\n<p>*****<\/p>\n<p>You must place your validation key in:<br \/>\n  \/root\/Development\/chef-repo\/.chef\/chef-validator.pem<br \/>\nBefore generating instance data with Knife!<\/p>\n<p>*****<br \/>\nConfiguration file written to \/root\/Development\/chef-repo\/.chef\/knife.rb<\/p>\n<p>=========================================================================<\/p>\n<p># knife configure<br \/>\n# cat chef-validator.pem >> \/root\/Development\/chef-repo\/.chef\/admin.pem<br \/>\n# cat \/root\/Development\/chef-repo\/.chef\/chef-validator.pem<br \/>\n# cat \/root\/Development\/chef-repo\/.chef\/knife.rb<br \/>\n# knife client list<br \/>\n# knife ssl check<\/p>\n<p># mkdir \/root\/Development\/chef-repo\/.chef\/trusted_certs<br \/>\n# cd trusted_certs<\/p>\n<p>Copy &#8220;192.168.1.2.crt\u201d from server to client for SSL communication:<\/p>\n<p># scp 192.168.1.2:\/var\/opt\/chef-server\/nginx\/ca\/192.168.1.2.crt \/root\/Development\/chef-repo\/.chef\/trusted_certs\/<\/p>\n<p>========================================================================<\/p>\n<p>Test knife from client to server via SSL check:<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo\/.chef<\/p>\n<p># knife ssl check<br \/>\nConnecting to host 192.168.1.2:443<br \/>\nSuccessfully verified certificates from `192.168.1.2\u2019<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo\/.chef# <\/p>\n<p>root@chef_ws:~# cd ~\/Development\/chef-repo\/.chef<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo\/.chef# ls -l<br \/>\ntotal 36<br \/>\n-rw-r&#8211;r&#8211; 1 root root 1675 Mar 31 12:24 admin.pem<br \/>\n-rw-r&#8211;r&#8211; 1 root root  451 Mar 31 12:19 admin.pub.pem<br \/>\n-rw-r&#8211;r&#8211; 1 root root  451 Mar 31 12:35 chef-client-validator.pub.pem<br \/>\n-rw-r&#8211;r&#8211; 1 root root 1675 Mar 31 12:34 chef-validator.pem<br \/>\n-rw-r&#8211;r&#8211; 1 root root  423 Mar 31 15:31 knife.rb<br \/>\n-rw-r&#8211;r&#8211; 1 root root 1675 Mar 31 13:11 root.pem<br \/>\ndrwxr-xr-x 2 root root 4096 Mar 31 15:28 trusted_certs<br \/>\nroot@chef_ws:~\/Development\/chef-repo\/.chef# <\/p>\n<p>root@chef_ws:~# chef verify<\/p>\n<p>Running verification for component &#8216;berkshelf&#8217;<\/p>\n<p>Running verification for component &#8216;test-kitchen&#8217;<\/p>\n<p>Running verification for component &#8216;chef-client&#8217;<\/p>\n<p>Running verification for component &#8216;chef-dk&#8217;<\/p>\n<p>Running verification for component &#8216;chefspec&#8217;<\/p>\n<p>Running verification for component &#8216;rubocop&#8217;<\/p>\n<p>Running verification for component &#8216;fauxhai&#8217;<\/p>\n<p>Running verification for component &#8216;knife-spork&#8217;<\/p>\n<p>Running verification for component &#8216;kitchen-vagrant&#8217;<\/p>\n<p>Running verification for component &#8216;package installation&#8217;<\/p>\n<p>&#8230;..<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>Verification of component &#8216;chef-dk&#8217; succeeded.<\/p>\n<p>Verification of component &#8216;rubocop&#8217; succeeded.<\/p>\n<p>Verification of component &#8216;knife-spork&#8217; succeeded.<\/p>\n<p>Verification of component &#8216;berkshelf&#8217; succeeded.<\/p>\n<p>Verification of component &#8216;chef-client&#8217; succeeded.<\/p>\n<p>Verification of component &#8216;fauxhai&#8217; succeeded.<\/p>\n<p>Verification of component &#8216;test-kitchen&#8217; succeeded.<\/p>\n<p>Verification of component &#8216;kitchen-vagrant&#8217; succeeded.<\/p>\n<p>Verification of component &#8216;chefspec&#8217; succeeded.<\/p>\n<p>Verification of component &#8216;package installation&#8217; succeeded.<\/p>\n<p>root@chef_ws:~# <\/p>\n<p>root@chef_ws:~# which ruby<br \/>\n\/opt\/chefdk\/embedded\/bin\/ruby<br \/>\nRefer online docs:<\/p>\n<p>http:\/\/thornelabs.net\/2013\/09\/16\/install-the-open-source-chef-server-setup-knife-on-your-workstation-and-bootstrap-your-first-client-server.html<\/p>\n<p>http:\/\/gettingstartedwithchef.com\/first-steps-with-chef.html<\/p>\n<p>http:\/\/www.linuxfunda.com\/2014\/02\/04\/how-to-install-and-configure-chef-client\/<\/p>\n<p>http:\/\/tcotav.github.io\/chefdk_getting_started.html<\/p>\n<p>http:\/\/docs.chef.io\/client\/install_workstation.html<\/p>\n<p>Thank you for installing Chef!<\/p>\n<p>Setup git :<\/p>\n<p>root@chef_ws:~# which git<br \/>\n\/usr\/bin\/git<br \/>\nroot@chef_ws:~# git config &#8211;global user.name &#8220;Benjamin Lu&#8221;            ###### Please replace my name with yours to create your github account<br \/>\nroot@chef_ws:~# git config &#8211;global user.email &#8220;benlu369@yahoo&#8221;        ###### Please replace my e-mail with yours to setup your github contact<br \/>\nroot@chef_ws:~# <\/p>\n<p>root@chef_ws:~# which knife<br \/>\n\/opt\/chefdk\/bin\/knife<\/p>\n<p>root@chef_server:~# scp 192.168.1.3:\/root\/Development\/chef-repo\/.chef\/chef-validator.pem \/etc\/chef\/chef-validator<\/p>\n<p>Install chef_client from chef_work_station on \u201cchef_ws on 192.168.1.3\u201d to chef_server on &#8220;192.168.1.2\u201d:<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo\/.chef#<\/p>\n<p># knife bootstrap -u root 192.168.1.4  #### thsi will add your 3rd host as chef_client with IP: 192.168.1.4 to Chef_server on 192.168.1.2 from your chef_ws on 192.168.1.3<\/p>\n<p>Connecting to 192.168.1.4<br \/>\nroot@192.168.1.4&#8217;s password:<br \/>\n192.168.1.4 Installing Chef Client&#8230;<br \/>\n&#8230;..<br \/>\n100%[======================================>] 18,378      &#8211;.-K\/s   in 0.002s<br \/>\n&#8230;.<br \/>\n192.168.1.4o Chef Client finished, 0\/0 resources updated in 1.795916082 seconds<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo\/.chef<\/p>\n<p>root@chef_server:\/etc\/chef# chmod 644 client.pem<br \/>\nroot@chef_server:\/etc\/chef# ls -ltr<br \/>\ntotal 20<br \/>\n-rw&#8212;&#8212;- 1 root root 1676 Mar 31 16:03 validation.pem<br \/>\ndrwxr-xr-x 2 root root 4096 Mar 31 16:03 trusted_certs<br \/>\n-rw-r&#8211;r&#8211; 1 root root  192 Mar 31 16:03 client.rb<br \/>\n-rw-r&#8211;r&#8211; 1 root root   16 Mar 31 16:03 first-boot.json<br \/>\n-rw-r&#8211;r&#8211; 1 root root 1675 Mar 31 16:03 client.pem<\/p>\n<p>Test client\/workstation ====> server talk from listing chef_client created on chef_server:<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo# knife client list<br \/>\nchef-validator<br \/>\nchef-webui<br \/>\n192.168.1.4<br \/>\nroot@chef_ws:~\/Development\/chef-repo# <\/p>\n<p>example of add \u201cclient\u201d as &#8220;chef_client_01.XYZ.com\u201d from workstation chef_ws to CHEF server remotely:<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo# knife bootstrap -u root chef_client_01.XYZ.com<\/p>\n<p>example of create\/detete \u201cenvironment\u201d from workstation chef_ws on CHEF server remotely:<\/p>\n<p># knife environment create development -d &#8220;The development environment\u201d<br \/>\n# knife environment delete development -d &#8220;The development environment\u201d<br \/>\n# knife environment list   # this is to list \u201cenvironment\u201d created on server side, the same view can be see from web ui at: https:\/\/192.168.1.2\/environments<\/p>\n<p>troubleshooting:<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo# knife cookbook create my_test_cookbook<\/p>\n<p># cd \/var\/chef\/cookbooks\/my_test_cookbook<\/p>\n<p>root@chef_ws:# ls<br \/>\nattributes  CHANGELOG.md  definitions  files  libraries  metadata.rb  providers  README.md  recipes  resources  templates<\/p>\n<p>root@chef_ws:\/var\/chef\/cookbooks\/my_test_cookbook# cd recipes<\/p>\n<p>root@chef_ws:\/var\/chef\/cookbooks\/my_test_cookbook\/recipes# ls<\/p>\n<p>default.rb<br \/>\n===================================================================<\/p>\n<p>#### start chef_client to deploy cookbook on host:<\/p>\n<p>root@192.168.1.4:~\/Development\/chef-repo# sudo chef-client<br \/>\nStarting Chef Client, version 12.2.1<br \/>\nresolving cookbooks for run list: []<br \/>\nSynchronizing Cookbooks:<br \/>\nCompiling Cookbooks&#8230;<br \/>\n[2015-04-14T14:23:17+00:00] WARN: Node 192.168.1.4 has an empty run list.<br \/>\nConverging 0 resources<br \/>\nRunning handlers:<br \/>\nRunning handlers complete<br \/>\nChef Client finished, 0\/0 resources updated in 1.132211206 seconds<br \/>\nroot@chef_ws:~\/Development\/chef-repo# <\/p>\n<p>====================================<\/p>\n<p>### add &#8220;run list\u201d to &#8220;192.168.1.4\u201d for &#8220;recipe[motd]\u201d :<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo# knife node run_list add 192.168.1.4 recipe[motd]<\/p>\n<p>192.168.1.4:<\/p>\n<p>  run_list: recipe[motd]<\/p>\n<p>Removed \u201crun list\u201d added:<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo# knife node run_list remove 192.168.1.4 recipe[motd]<\/p>\n<p>https:\/\/docs.chef.io\/knife_cookbook.html<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo\/roles# knife cookbook bulk delete motd<\/p>\n<p>All versions of the following cookbooks will be deleted:<br \/>\nmotd<br \/>\nDo you really want to delete these cookbooks? (Y\/N) Y<br \/>\nDeleted cookbook  motd                      [0.1.0]<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo# knife cookbook create motd<\/p>\n<p>** Creating cookbook motd in \/var\/chef\/cookbooks<\/p>\n<p>** Creating README for cookbook: motd<\/p>\n<p>** Creating CHANGELOG for cookbook: motd<\/p>\n<p>** Creating metadata for cookbook: motd<\/p>\n<p>root@chef_ws:~\/Development\/chef-repo# knife cookbook upload -a \/var\/chef\/cookbooks\/motd -E production<\/p>\n<p>Uploading motd           [0.1.0]<\/p>\n<p>Uploaded all cookbooks.<\/p>\n<p>***************************************************************************************************<\/p>\n<p>Examples:<\/p>\n<p>Chef: step_to_deply_new_host_and_Remove_user_from_data_bag<\/p>\n<p>root@ws:~\/Development\/chef-repo# cat step_2_deply_new_host_for_chef<\/p>\n<p>## go to chef workstation, do following:<\/p>\n<p>cd ~\/Development\/chef-repo\/<\/p>\n<p># knife bootstrap -u root <HOST_NAME>            ### add host to chef node and client<\/p>\n<p># knife node list | grep <HOST_NAME>             ### verify node list on chef server to see if this host get added<\/p>\n<p># knife client list | grep <HOST_NAME>           ### verify client list on chef server to see if this host get added<\/p>\n<p>## transfer the new added host to production ENV:<\/p>\n<p># knife exec -E &#8216;nodes.transform(&#8220;chef_environment:_default&#8221;) { |n| n.chef_environment(&#8220;production&#8221;) }&#8217;<\/p>\n<p># add host to run list:<\/p>\n<p># for most host not as DNS and NTP server, they only need apply the role below:<\/p>\n<p># knife node run_list set HOST_NAME &#8216;role[dns_ntp_client_role]&#8217;<\/p>\n<p># example: knife node run_list set <HOST_NAME> &#8216;role[dns_ntp_client_role]&#8217;<\/p>\n<p># verify runlist to see if the host has been added:<\/p>\n<p># knife search node &#8216;run_list:recipe\\[roles\\]&#8217;<\/p>\n<p># example: knife search node &#8216;run_list:role\\[dns_ntp_client_role\\]&#8217;<\/p>\n<p># example: knife search node <HOST_NAME><\/p>\n<p># if all above are running successfilly, go to the client host to run &#8220;sudo chef-client&#8221; or run from anyware from cli.<\/p>\n<p>===================================================================================================================<\/p>\n<p># on some CentOS 7 linux, add node and client from WS does not work with error about NTP, need to go to that box to intall NTP then restart services:<\/p>\n<p>$ sudo yum install ntp ntpdate ntp-doc;<\/p>\n<p>$ sudo chkconfig ntpd on;<\/p>\n<p>$ sudo ntpdate pool.ntp.org;<\/p>\n<p>$ sudo \/etc\/init.d\/ntpd start;<\/p>\n<p>$ sudo yum install bind-utils #####  install nslookup from this command, optional<\/p>\n<p>$ sudo yum install ruby; ruby &#8211;version; #### install ruby as chef needed<\/p>\n<p>or<\/p>\n<p>$ sudo yum install ntp ntpdate ntp-doc; sudo chkconfig ntpd on; sudo ntpdate pool.ntp.org; sudo \/etc\/init.d\/ntpd start; sudo yum install bind-utils;  sudo yum install ruby; ruby &#8211;version;<\/p>\n<p>============================================================================<\/p>\n<p># upload cookbook to production:<\/p>\n<p>$ sudo knife cookbook upload -E production -o cookbooks -a<\/p>\n<p>$ chef-client -v<\/p>\n<p># upgrade chef-client on node<\/p>\n<p>$ curl -L https:\/\/www.opscode.com\/chef\/install.sh | sudo bash<\/p>\n<p>================================================================================================================<br \/>\nExample to remove user from data bag steps:<\/p>\n<p>step 1: <\/p>\n<p>Edit the user json file to set action to remove:<\/p>\n<p>root@ws:~\/Development\/chef-repo\/data_bags\/<YOUR_sysadmin_group># cat blu.json<br \/>\n{<br \/>\n  &#8220;id&#8221;: &#8220;blu&#8221;,                 #### the USER_ID could be <blu> as example<br \/>\n  &#8220;comment&#8221;: &#8220;Benjamin Lu&#8221;,    #### the comment for <blu> could be <Benjamin Lu><br \/>\n  &#8220;groups&#8221;: [ &#8220;sysadmin&#8221;],<br \/>\n  &#8220;shell&#8221;: &#8220;\/bin\/bash&#8221;,<br \/>\n  &#8220;uid&#8221;: 3000,                 #### this example is a fake, 3000 should the the real &#8220;uid&#8221; for <blu><br \/>\n  &#8220;action&#8221;: \u201cremove&#8221;           #### this line of &#8220;remove&#8221; should be added here for remove !<\/p>\n<p>}<\/p>\n<p>Step 2:<\/p>\n<p>Update data bag in chef server from command :<\/p>\n<p>&#8220;knife data bag from file YOUR_sysadmin_group <YOUR_sysadmin_group>\/blu.json&#8221;<\/p>\n<p>root@ws:~\/Development\/chef-repo\/data_bags# ls -ltr<br \/>\ntotal 8<br \/>\n-rw-r&#8211;r&#8211; 1 root root 1876 Mar 31 10:48 README.md<br \/>\ndrwxr-xr-x 2 root root 4096 Jun 26 19:16 YOUR_sysadmin_group<br \/>\nroot@ws:~\/Development\/chef-repo\/data_bags# knife data bag from file YOUR_sysadmin_group YOUR_sysadmin_group\/blu.json<br \/>\nUpdated data_bag_item[YOUR_sysadmin_group::blu]<\/p>\n<p>Step 3:<\/p>\n<p>Go to any host has the user installed from chef, rerun \u201csudo chef-client\u201d to remove the user.<\/p>\n<p>step 4:<\/p>\n<p>Repeat step 3 on all host has the user installed.<\/p>\n<p>step 5:<\/p>\n<p>Delete this user as \u201cblu\u201d from data bag in chef server from command as below:<\/p>\n<p># knife data bag delete YOUR_sysadmin_group blu<\/p>\n<p>root@ws:~\/Development\/chef-repo\/data_bags\/YOUR_sysadmin_group# <\/p>\n<p># knife data bag delete YOUR_sysadmin_group blu<br \/>\nDo you really want to delete blu? (Y\/N) Y<br \/>\nDeleted data_bag_item[blu]<\/p>\n<p>Done !<br \/>\n==============================================================================================<br \/>\nTroubleshooting :<\/p>\n<p>Some host has no FQDN in \/etc\/hosts, cause chef deploy NOT work, need fix as below:<\/p>\n<p>Step 1:  remove &#8220;\/etc\/chef\/client.pem\u201d, then edit &#8220;\/etc\/hosts \u201c to have FQDN, them remove &#8220;\/etc\/chef&#8221;<\/p>\n<p>  [root@<SOME_HOST> ~]# <\/p>\n<p>  $ rm \/etc\/chef\/client.pem<br \/>\n  $ hostname<br \/>\n  $ vi \/etc\/hosts   ( the host name has to be FQDN )<br \/>\n  $ rm -rf \/etc\/chef<\/p>\n<p>Step 2: go to chef working station to add it again: at <\/p>\n<p>   root@ws:~\/Development\/chef-repo# <\/p>\n<p>   example:<\/p>\n<p>   $ knife bootstrap -u root <SOME_HOST>;<\/p>\n<p>Step 3, Apply role again:<\/p>\n<p>   $ knife node run_list set <SOME_HOST> &#8216;role[dns_server_role]\u2019<\/p>\n<p>Step 4, deploy chef again on the client host:<\/p>\n<p>   [root@<SOME_HOST> ~]# chef-client;<\/p>\n<p>Done;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Chef server, client, and workstation setup: root@chef_server:~# # sudo apt-get upgrade # use this command to update software first on ubuntu linux Install ruby and verify before Chef Env setup: # sudo apt-get install ruby-full # which ruby ## verify if ruby get install # ruby -v # wget https:\/\/opscode-omnibus-packages.s3.amazonaws.com\/ubuntu\/12.04\/x86_64\/chef-server_11.0.8-1.ubuntu.12.04_amd64.deb # which ruby \/bin\/ruby reset [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/cephswift.com\/index.php\/wp-json\/wp\/v2\/pages\/100"}],"collection":[{"href":"https:\/\/cephswift.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/cephswift.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/cephswift.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cephswift.com\/index.php\/wp-json\/wp\/v2\/comments?post=100"}],"version-history":[{"count":4,"href":"https:\/\/cephswift.com\/index.php\/wp-json\/wp\/v2\/pages\/100\/revisions"}],"predecessor-version":[{"id":113,"href":"https:\/\/cephswift.com\/index.php\/wp-json\/wp\/v2\/pages\/100\/revisions\/113"}],"wp:attachment":[{"href":"https:\/\/cephswift.com\/index.php\/wp-json\/wp\/v2\/media?parent=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}