Wednesday 9 November 2016

Exploring "Infrastructure as code" with Opscode Chef Part 7 (push instead of pull)

What ever we've done with chef thus far involves logging into the node & executing the chef-client command to commence the chef run. for thousands of servers, logging into each server & executing chef-client doesn't sound very practical.
To ease this, chef introduced an add on called "push jobs". This consists of components to be installed on chef server, workstation & node. Once installed we can trigger a chef run from the chef workstation using the knife utility.
I've tried to set this up but haven't succeeded yet. But another alternative is using "knife ssh" command. This allows you to login to a node via ssh, run a command & display output to STDOUT.

Here are a couple of examples:

[sahil@cwork push-jobs-master]$ sudo knife ssh 'name:mychefnode' 'whoami'
root@cclient1's password:
cclient1 root
[sahil@cwork push-jobs-master]$  knife ssh 'name:mychefnode' 'whoami'
sahil@cclient1's password:
sahil@cclient1's password:
cclient1 sahil
[sahil@cwork push-jobs-master]$  knife ssh 'name:mychefnode' 'uptime'
sahil@cclient1's password:
cclient1  12:54:00 up  1:01,  4 users,  load average: 0.00, 0.01, 0.05

So, if we can't get push jobs we can still trigger the chef-client on the node from the chef workstation using the "knife ssh" command as shown below:

[sahil@cwork cookbooks]$  knife ssh 'name:mychefnode' 'sudo chef-client'
sahil@cclient1's password:
cclient1 Starting Chef Client, version 12.15.19
cclient1 resolving cookbooks for run list: ["apache::addscreen", "apache"]
cclient1 Synchronizing Cookbooks:
cclient1   - apache (0.1.0)
cclient1 Installing Cookbook Gems:
cclient1 Compiling Cookbooks...
cclient1 Converging 4 resources
cclient1 Recipe: apache::addscreen
cclient1   * yum_package[screen] action install (up to date)
cclient1 Recipe: apache::default
cclient1   * yum_package[httpd] action install (up to date)
cclient1   * service[httpd] action start (up to date)
cclient1   * service[httpd] action enable (up to date)
cclient1   * template[/var/www/html/index.html] action create (up to date)
cclient1
cclient1 Running handlers:
cclient1 Running handlers complete
cclient1 Chef Client finished, 0/5 resources updated in 31 seconds
[sahil@cwork cookbooks]$

No comments:

Post a Comment

Using capture groups in grep in Linux

Introduction Let me start by saying that this article isn't about capture groups in grep per se. What we are going to do here with gr...