Multi node Orchestration with Chef


#1

Hi Folks,

    we have a scenario that, have to run multiple recipes on multiple nodes like N1, N2 and N3. Here the process is a) stop services on N1
        b) Do Up gradation of iis websites on N2 and N3
         c) Start services on N1

So Can we do these 3 steps in a single chef-client run? We are using push-jobs to run chef-client remotely on respective nodes.

Thanks in advance for assisting on this…


#2

This could easily be done in one recipe. There are also some Chef resources available for Windows Services and their config and stop/start. Have a look at this man page as this would be your best bet. I would do that as follows (You wil once again need to test this, as there may be some delays that need to be put it so that the service has time to actually start):

windows_service 'W3SVC' do
  action :stop
end

execute 'upgrade_process' do
  command 'msiexec c:\myinstaller.msi /q /n'
end

windows_service 'W3SVC' do
  action :start
end

Also, you could just script it and use the chef resource for ‘powershell_script’ - Man page found here - Here is a dirty powershell script (That I have not tested) that may give you an idea of what could be done in one recipe to complete this task if you don’t want to use the bilt in Chef resource for ‘Windows Services’

powershell_script 'all_in_one_dirty_script' do
code <<-EOH

# Collect data for the W3SVC Service
$ServiceW3SVC = 'W3SVC'
$Service1 = Get-Service $ServiceW3SVC

# Stop the iis service
if ($Service1.Status -eq 'running')
    {
        Stop-Service $ServiceW3SVC
            while ((Get-Service $ServiceW3SVC).status -ne 'stopped'){
                Write-host 'Waiting for the service to stop'
                Start-Sleep -Seconds 5
                }
    }

# Start your upgrade process here, for example, if it was an MSI running the upgrade, you could use the 'Start-Process' command as it has a '-wait' switch that will wait for the msi process to complete

$MSI = 'c:\path\to\my.msi'
Start-Process -FilePath $MSI -ArgumentList '/q /n' -Wait

# Then a simple start service should do it.
Start-Service $ServiceW3SVC

# Then we can query the process to see if it is good
Get-Service $ServiceW3SVC

#3

Hi svucich for your reply, but here the question is executing on multi-nodes if all the steps needs to be executed on single machine it is easy but our question is different. we are stopping services on one machine and doing website up gradation on some other machine once it is done we are starting service.


#4

Yes, you create a cookbook for one node, then deploy to many. This is how it works.


#6

Hi svucich,

      I Think you didn't get the actual requirement what we are referring to.We have three machines node1, node2 and node3 .At one go when we run chef-client my cookbook should go the node1 and stop some services come back go to the node2 install some packages and finally come back and start some services in node3. This all should do in one run with single cookbook.We have a very big doubt that, Will chef provide this type of feature? If yes please guide us how can we do.

Thanks.