How to bootstrap a Linux node to be managed by Chef Server

Here in this article we will try to bootstrap a Linux node and manage it using Hosted Chef server.
Test Environment
Hosted Chef Server – https://manage.chef.io/
desktop1.example.com – Used for preparing cookbooks and recipes
server1.example.com – Managed using hosted chef server
What is Knife
knife is a command-line tool that provides an interface between a local chef-repo and the Chef Infra Server. knife helps users to manage: Nodes. Cookbooks and recipes. Roles, Environments, and Data Bags.
Procedure
Step1: Bootstrap the node using password authentication
As a first step we will try to bootstrap the node using the “knife” utility as shown below.
[root@desktop1 chefspace] # knife bootstrap server1.example.com --ssh-user student --ssh-password 'xxx' --sudo --use-sudo-password --node-name rhel7 --run-list 'recipe[learn_chef_httpd]' |
reating new client for rhel7 Creating new node for rhel7 Connecting to server1.example.com server1.example.com -----> Existing Chef installation detected server1.example.com Starting the first Chef Client run... server1.example.com [2017-06-05T02:57:50-04:00] INFO: Forking chef instance to converge... server1.example.com Starting Chef Client, version 12.20.3 server1.example.com [2017-06-05T02:57:50-04:00] INFO: *** Chef 12.20.3 *** server1.example.com [2017-06-05T02:57:50-04:00] INFO: Platform: x86_64-linux server1.example.com [2017-06-05T02:57:50-04:00] INFO: Chef-client pid: 5225 server1.example.com [2017-06-05T02:57:57-04:00] INFO: Setting the run_list to [ "recipe[learn_chef_httpd]" ] from CLI options server1.example.com [2017-06-05T02:57:57-04:00] INFO: Run List is [recipe[learn_chef_httpd]] server1.example.com [2017-06-05T02:57:57-04:00] INFO: Run List expands to [learn_chef_httpd] server1.example.com [2017-06-05T02:57:57-04:00] INFO: Starting Chef Run for rhel7 server1.example.com [2017-06-05T02:57:57-04:00] INFO: Running start handlers server1.example.com [2017-06-05T02:57:57-04:00] INFO: Start handlers complete. server1.example.com [2017-06-05T02:57:57-04:00] INFO: HTTP Request Returned 404 Not Found: server1.example.com [2017-06-05T02:57:57-04:00] INFO: Error while reporting run start to Data Collector. URL: https: //api .chef.io /organizations/sudhir-org/data-collector Exception: 404 -- 404 "Not Found" (This is normal if you do not have Chef Automate) server1.example.com resolving cookbooks for run list: [ "learn_chef_httpd" ] server1.example.com [2017-06-05T02:57:58-04:00] INFO: Loading cookbooks [learn_chef_httpd@0.2.0] server1.example.com Synchronizing Cookbooks: server1.example.com - learn_chef_httpd (0.2.0) server1.example.com Installing Cookbook Gems: server1.example.com Compiling Cookbooks... server1.example.com [2017-06-05T02:57:58-04:00] INFO: HTTP Request Returned 404 Not Found: server1.example.com Converging 4 resources server1.example.com Recipe: learn_chef_httpd::default server1.example.com * yum_package[httpd] action install [2017-06-05T02:48:30-04:00] INFO: Processing yum_package[httpd] action install (learn_chef_httpd::default line 9) server1.example.com (up to date ) server1.example.com * service[httpd] action enable [2017-06-05T02:48:35-04:00] INFO: Processing service[httpd] action enable (learn_chef_httpd::default line 11) server1.example.com [2017-06-05T02:48:36-04:00] INFO: service[httpd] enabled server1.example.com server1.example.com - enable service service[httpd] server1.example.com * service[httpd] action start [2017-06-05T02:48:36-04:00] INFO: Processing service[httpd] action start (learn_chef_httpd::default line 11) server1.example.com [2017-06-05T02:48:38-04:00] INFO: service[httpd] started server1.example.com server1.example.com - start service service[httpd] server1.example.com * template[ /var/www/html/index .html] action create [2017-06-05T02:48:38-04:00] INFO: Processing template[ /var/www/html/index .html] action create (learn_chef_httpd::default line 15) server1.example.com [2017-06-05T02:48:38-04:00] INFO: template[ /var/www/html/index .html] created file /var/www/html/index .html server1.example.com server1.example.com - create new file /var/www/html/index .html [2017-06-05T02:48:38-04:00] INFO: template[ /var/www/html/index .html] updated file contents /var/www/html/index .html server1.example.com server1.example.com - update content in file /var/www/html/index .html from none to ef4ffd server1.example.com --- /var/www/html/index .html 2017-06-05 02:48:38.615394175 -0400 server1.example.com +++ /var/www/html/ .chef-index20170605-4784-gm00gj.html 2017-06-05 02:48:38.610394177 -0400 server1.example.com @@ -1 +1,6 @@ server1.example.com +<html> server1.example.com + <body> server1.example.com + <h1>hello world< /h1 > server1.example.com + < /body > server1.example.com +< /html > server1.example.com - restore selinux security context server1.example.com * service[iptables] action stop[2017-06-05T02:48:39-04:00] INFO: Processing service[iptables] action stop (learn_chef_httpd::default line 19) server1.example.com (up to date ) server1.example.com [2017-06-05T02:48:40-04:00] INFO: Chef Run complete in 12.025692798 seconds server1.example.comserver1.example.com Running handlers: server1.example.com [2017-06-05T02:58:04-04:00] INFO: Running report handlers server1.example.com Running handlers complete server1.example.com [2017-06-05T02:58:04-04:00] INFO: Report handlers complete server1.example.com Chef Client finished, 0 /5 resources updated in 14 seconds server1.example.com [2017-06-05T02:58:04-04:00] INFO: Sending resource update report (run- id : be565577-2628-4461-a087-f458e8337a44) |
Step2: List the nodes managed by chef server
Now let’s try to list the nodes available in our hosted environment as shown below.
[root@desktop1 chefspace] # knife node list rhel7 |
[root@desktop1 chefspace] # knife node show rhel7 Node Name: rhel7 Environment: _default FQDN: server1.example.com IP: 192.168.0.101 Run List: recipe[learn_chef_httpd] Roles: Recipes: learn_chef_httpd, learn_chef_httpd::default Platform: redhat 7.0 Tags: |
Step3: Validate the webpage
We can now validate the recipe that has been provisioned on our managed node as shown below.
[root@desktop1 chefspace] # curl 192.168.0.101 <html> <body> <h1>hello world< /h1 > < /body > < /html > |
Hope you enjoyed reading this article. Thank you..
Leave a Reply
You must be logged in to post a comment.