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

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

Purpose – To bootstrap a Linux node and manage it using Hosted Chef server

Hosted Chef Server –    – Used for preparing cookbooks and recipes – Managed using hosted chef server

Step1: Bootstrap the node using password authentication
[root@desktop1 chefspace]# knife bootstrap –ssh-user student –ssh-password ‘xxx’ –sudo –use-sudo-password –node-name rhel7 –run-list ‘recipe[learn_chef_httpd]’
Creating new client for rhel7
Creating new node for rhel7
Connecting to —–> Existing Chef installation detected Starting the first Chef Client run… [2017-06-05T02:57:50-04:00] INFO: Forking chef instance to converge… Starting Chef Client, version 12.20.3 [2017-06-05T02:57:50-04:00] INFO: *** Chef 12.20.3 *** [2017-06-05T02:57:50-04:00] INFO: Platform: x86_64-linux [2017-06-05T02:57:50-04:00] INFO: Chef-client pid: 5225 [2017-06-05T02:57:57-04:00] INFO: Setting the run_list to [“recipe[learn_chef_httpd]”] from CLI options [2017-06-05T02:57:57-04:00] INFO: Run List is [recipe[learn_chef_httpd]] [2017-06-05T02:57:57-04:00] INFO: Run List expands to [learn_chef_httpd] [2017-06-05T02:57:57-04:00] INFO: Starting Chef Run for rhel7 [2017-06-05T02:57:57-04:00] INFO: Running start handlers [2017-06-05T02:57:57-04:00] INFO: Start handlers complete. [2017-06-05T02:57:57-04:00] INFO: HTTP Request Returned 404 Not Found: [2017-06-05T02:57:57-04:00] INFO: Error while reporting run start to Data Collector. URL: Exception: 404 — 404 “Not Found”  (This is normal if you do not have Chef Automate) resolving cookbooks for run list: [“learn_chef_httpd”] [2017-06-05T02:57:58-04:00] INFO: Loading cookbooks [learn_chef_httpd@0.2.0] Synchronizing Cookbooks:   – learn_chef_httpd (0.2.0) Installing Cookbook Gems: Compiling Cookbooks… [2017-06-05T02:57:58-04:00] INFO: HTTP Request Returned 404 Not Found: Converging 4 resources Recipe: learn_chef_httpd::default   * 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)  (up to date)   * service[httpd] action enable
[2017-06-05T02:48:35-04:00] INFO: Processing service[httpd] action enable (learn_chef_httpd::default line 11)
[2017-06-05T02:48:36-04:00] INFO: service[httpd] enabled     – enable service service[httpd]   * service[httpd] action start
[2017-06-05T02:48:36-04:00] INFO: Processing service[httpd] action start (learn_chef_httpd::default line 11) [2017-06-05T02:48:38-04:00] INFO: service[httpd] started     – start service service[httpd]   * 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)
[2017-06-05T02:48:38-04:00] INFO: template[/var/www/html/index.html] created file /var/www/html/index.html     – 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     – update content in file /var/www/html/index.html from none to ef4ffd     — /var/www/html/index.html    2017-06-05 02:48:38.615394175 -0400     +++ /var/www/html/.chef-index20170605-4784-gm00gj.html  2017-06-05 02:48:38.610394177 -0400     @@ -1 +1,6 @@     +<html>     +  <body>     +    <h1>hello world</h1>     +  </body>     +</html>     – restore selinux security context   * service[iptables] action stop[2017-06-05T02:48:39-04:00] INFO: Processing service[iptables] action stop (learn_chef_httpd::default line 19)  (up to date) [2017-06-05T02:48:40-04:00] INFO: Chef Run complete in 12.025692798 seconds Running handlers: [2017-06-05T02:58:04-04:00] INFO: Running report handlers Running handlers complete [2017-06-05T02:58:04-04:00] INFO: Report handlers complete Chef Client finished, 0/5 resources updated in 14 seconds [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

[root@desktop1 chefspace]# knife node list
[root@desktop1 chefspace]# knife node show rhel7
Node Name:   rhel7
Environment: _default
Run List:    recipe[learn_chef_httpd]
Recipes:     learn_chef_httpd, learn_chef_httpd::default
Platform:    redhat 7.0

Step3: Validate the webpage

[root@desktop1 chefspace]# curl
    <h1>hello world</h1>

Hope you enjoyed reading this article. Thank you.