Windows Reboots

All,

I have a recipe run as the following:

  1.   Change the machine name using a powershell script (which only applies the name after a reboot :()
    
  2.   Recipe to join the machine to the domain using the window_ad cookbook.
    

Because both these recipes reboot, how do I get chef to wait for the box to have restarted before it runs the join domain recipe? Currently at the moment it tries to run it during the reboot and fails.

Cheers,
Simon.


Disclaimer

This message is intended only for the use of the person(s) (“Intended Recipient”) to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any dissemination, distribution, copying or other use of this message or any of its content by any person other than the Intended Recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the Intended Recipient, please contact the sender as soon as possible.

Totaljobs Group Limited Registered Office: Bluefin Building, 110 Southwark Street, London, SE1 0TA, UK Registered in England and Wales under company no. 4269861


Hi Simon.
What I see at the moment is to run recipe which creates scheduled 1 time task which will run after reboot. And in this task you will feed some batch file for changing PC name and adding it into domain.
Regards, Taras.
— Оригінальне повідомлення —
Від кого: “Simon Hawkins” simon.hawkins@totaljobsgroup.com
Дата: 30 березня 2015, 17:19:12

All, I have a recipe run as the following: 1. Change the machine name using a powershell script (which only applies the name after a reboot L ) 2. Recipe to join the machine to the domain using the window_ad cookbook. Because both these recipes reboot, how do I get chef to wait for the box to have restarted before it runs the join domain recipe? Currently at the moment it tries to run it during the reboot and fails. Cheers, Simon. Disclaimer This message is intended only for the use of the person(s) (“Intended Recipient”) to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any dissemination, distribution, copying or other use of this message or any of its content by any person other than the Intended Recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the Intended Recipient, please contact the sender as soon as possible. Totaljobs Group Limited Registered Office: Bluefin Building, 110 Southwark Street, London, SE1 0TA, UK Registered in England and Wales under company no. 4269861

Recent versions of Chef Client have a built-in reboot resource. reboot Resource

--
Daniel DeLeo

On Monday, March 30, 2015 at 7:40 AM, klum_tz@ukr.net wrote:

Hi Simon.

What I see at the moment is to run recipe which creates scheduled 1 time task which will run after reboot.
And in this task you will feed some batch file for changing PC name and adding it into domain.

Regards,
Taras.

--- Оригінальне повідомлення ---
Від кого: "Simon Hawkins" <simon.hawkins@totaljobsgroup.com (mailto:simon.hawkins@totaljobsgroup.com)>
Дата: 30 березня 2015, 17:19:12

All,

I have a recipe run as the following:

  1. Change the machine name using a powershell script (which only applies the name after a reboot L)

  2. Recipe to join the machine to the domain using the window_ad cookbook.

Because both these recipes reboot, how do I get chef to wait for the box to have restarted before it runs the join domain recipe? Currently at the moment it tries to run it during the reboot and fails.

Cheers,

Simon.

Disclaimer
This message is intended only for the use of the person(s) ("Intended Recipient") to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any dissemination, distribution, copying or other use of this message or any of its content by any person other than the Intended Recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the Intended Recipient, please contact the sender as soon as possible.

Totaljobs Group Limited Registered Office: Bluefin Building, 110 Southwark Street, London, SE1 0TA, UK Registered in England and Wales under company no. 4269861

On Mon, Mar 30, 2015 at 7:42 AM, Daniel DeLeo dan@kallistec.com wrote:

Recent versions of Chef Client have a built-in reboot resource.
reboot Resource

--
Daniel DeLeo

On Monday, March 30, 2015 at 7:40 AM, klum_tz@ukr.net wrote:

Hi Simon.

What I see at the moment is to run recipe which creates scheduled 1 time
task which will run after reboot.
And in this task you will feed some batch file for changing PC name and
adding it into domain.

Regards,
Taras.

--- Оригінальне повідомлення ---
Від кого: "Simon Hawkins" <simon.hawkins@totaljobsgroup.com (mailto:
simon.hawkins@totaljobsgroup.com)>
Дата: 30 березня 2015, 17:19:12

All,

I have a recipe run as the following:

  1. Change the machine name using a powershell script (which only
    applies the name after a reboot L)

  2. Recipe to join the machine to the domain using the window_ad
    cookbook.

Because both these recipes reboot, how do I get chef to wait for the
box to have restarted before it runs the join domain recipe? Currently at
the moment it tries to run it during the reboot and fails.

Cheers,

Simon.

Disclaimer
This message is intended only for the use of the person(s) ("Intended
Recipient") to whom it is addressed. It may contain information which is
privileged and confidential. Accordingly any dissemination, distribution,
copying or other use of this message or any of its content by any person
other than the Intended Recipient may constitute a breach of civil or
criminal law and is strictly prohibited. If you are not the Intended
Recipient, please contact the sender as soon as possible.

Totaljobs Group Limited Registered Office: Bluefin Building, 110
Southwark Street, London, SE1 0TA, UK Registered in England and Wales under
company no. 4269861

In addition,

There's the reboot_pending? helper:

That allows you to guard against the reboot pre-emptively.

Hi Daniel,

Many thanks, I now get this:

10.x.x.x [2015-03-31T09:35:41+01:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>3, :reason=>"Cannot continue Chef run without a reboot.", :timestamp=>2015-03-31 09:35:40 +0100, :requested_by=>"now"}

And the box restarts. The only thing is the chef run terminates and doesn’t go onto the next recipe. I was expecting the run to pause for 3 mins and then carry on after the reboot, is that how it should work? Do I need to put recipe depends on statements in the domainjoin recipe?

I have this in the rename machine recipe:

reboot "now" do
action :nothing
reason "Cannot continue Chef run without a reboot."
delay_mins 3
end

powershell_script "rename_hostname" do
code <<-EOH

….
EOH

notifies :reboot_now, 'reboot[now]', :immediately

END

Cheers,
Simon.
From: Galen Emery [mailto:galen@getchef.com]
Sent: 30 March 2015 16:22
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Windows Reboots

On Mon, Mar 30, 2015 at 7:42 AM, Daniel DeLeo <dan@kallistec.commailto:dan@kallistec.com> wrote:
Recent versions of Chef Client have a built-in reboot resource. reboot Resource

--
Daniel DeLeo

On Monday, March 30, 2015 at 7:40 AM, klum_tz@ukr.netmailto:klum_tz@ukr.net wrote:

Hi Simon.

What I see at the moment is to run recipe which creates scheduled 1 time task which will run after reboot.
And in this task you will feed some batch file for changing PC name and adding it into domain.

Regards,
Taras.

--- Оригінальне повідомлення ---
Від кого: "Simon Hawkins" <simon.hawkins@totaljobsgroup.commailto:simon.hawkins@totaljobsgroup.com (mailto:simon.hawkins@totaljobsgroup.commailto:simon.hawkins@totaljobsgroup.com)>
Дата: 30 березня 2015, 17:19:12

All,

I have a recipe run as the following:

  1. Change the machine name using a powershell script (which only applies the name after a reboot L)

  2. Recipe to join the machine to the domain using the window_ad cookbook.

Because both these recipes reboot, how do I get chef to wait for the box to have restarted before it runs the join domain recipe? Currently at the moment it tries to run it during the reboot and fails.

Cheers,

Simon.

Disclaimer
This message is intended only for the use of the person(s) ("Intended Recipient") to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any dissemination, distribution, copying or other use of this message or any of its content by any person other than the Intended Recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the Intended Recipient, please contact the sender as soon as possible.

Totaljobs Group Limited Registered Office: Bluefin Building, 110 Southwark Street, London, SE1 0TA, UK Registered in England and Wales under company no. 4269861

In addition,

There's the reboot_pending? helper: About the Chef Infra Language

That allows you to guard against the reboot pre-emptively.

I’ve tried doing the following also:

  1.   Changed my run list to run just call the join domain script.
    
  2.   Add an include in the join domain recipe to call the rename_hostname recipe.
    
  3.   When the client is run, the rename_hostname recipe is called and the reboot is run.
    
  4.   The chef run gets terminated, so the domainjoin is never completed, but the machine reboots.
    

Is there any way of pausing the chef-run to wait for the machine to come back up, then run the domain join and reboot after that?

Cheers,
Simon.
From: Simon Hawkins [mailto:Simon.Hawkins@totaljobsgroup.com]
Sent: 31 March 2015 09:56
To: galen@getchef.com; chef@lists.opscode.com
Subject: [chef] RE: Re: Re: Re: Windows Reboots

Hi Daniel,

Many thanks, I now get this:

10.x.x.x [2015-03-31T09:35:41+01:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>3, :reason=>"Cannot continue Chef run without a reboot.", :timestamp=>2015-03-31 09:35:40 +0100, :requested_by=>"now"}

And the box restarts. The only thing is the chef run terminates and doesn’t go onto the next recipe. I was expecting the run to pause for 3 mins and then carry on after the reboot, is that how it should work? Do I need to put recipe depends on statements in the domainjoin recipe?

I have this in the rename machine recipe:

reboot "now" do
action :nothing
reason "Cannot continue Chef run without a reboot."
delay_mins 3
end

powershell_script "rename_hostname" do
code <<-EOH

….
EOH

notifies :reboot_now, 'reboot[now]', :immediately

END

Cheers,
Simon.
From: Galen Emery [mailto:galen@getchef.com]
Sent: 30 March 2015 16:22
To: chef@lists.opscode.commailto:chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Windows Reboots

On Mon, Mar 30, 2015 at 7:42 AM, Daniel DeLeo <dan@kallistec.commailto:dan@kallistec.com> wrote:
Recent versions of Chef Client have a built-in reboot resource. reboot Resource

--
Daniel DeLeo

On Monday, March 30, 2015 at 7:40 AM, klum_tz@ukr.netmailto:klum_tz@ukr.net wrote:

Hi Simon.

What I see at the moment is to run recipe which creates scheduled 1 time task which will run after reboot.
And in this task you will feed some batch file for changing PC name and adding it into domain.

Regards,
Taras.

--- Оригінальне повідомлення ---
Від кого: "Simon Hawkins" <simon.hawkins@totaljobsgroup.commailto:simon.hawkins@totaljobsgroup.com (mailto:simon.hawkins@totaljobsgroup.commailto:simon.hawkins@totaljobsgroup.com)>
Дата: 30 березня 2015, 17:19:12

All,

I have a recipe run as the following:

  1. Change the machine name using a powershell script (which only applies the name after a reboot L)

  2. Recipe to join the machine to the domain using the window_ad cookbook.

Because both these recipes reboot, how do I get chef to wait for the box to have restarted before it runs the join domain recipe? Currently at the moment it tries to run it during the reboot and fails.

Cheers,

Simon.

Disclaimer
This message is intended only for the use of the person(s) ("Intended Recipient") to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any dissemination, distribution, copying or other use of this message or any of its content by any person other than the Intended Recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the Intended Recipient, please contact the sender as soon as possible.

Totaljobs Group Limited Registered Office: Bluefin Building, 110 Southwark Street, London, SE1 0TA, UK Registered in England and Wales under company no. 4269861

In addition,

There's the reboot_pending? helper: About the Chef Infra Language

That allows you to guard against the reboot pre-emptively.

Hi Simon,

Wouldn't something like this work for your use case?

reboot "my_name" do
action :nothing
reason "reason"

other params as appropriate

end

powershell_script 'rename_hostname'
code <<-EOH
# code
EOH

insert guard here to ensure this doesn't run if correct hostname's already set

notifies :request_reboot, "reboot[my_name]"
end

powershell_script "join_domain"
code <<-EOH

code

EOH
not_if {reboot_pending? || some_other_test}
notifies :request_reboot, "reboot[my_name]"
end

On the first run, rename_hostname will run, then set a reboot event that'll trigger at the end of the Chef run (thanks to the :request_reboot action); join_domain will be skipped owing to the reboot_pending? call.

Second run, rename_hostname should be skipped, join_domain will run and notify for a reboot again.

Third and subsequent times, nothing should happen.

To make sure chef-client runs on reboot, you could create a task, using e.g. windows_task from the Windows cookbook (GitHub - chef-boneyard/windows: Development repository for Chef Cookbook windows), then you could notify the windows_task resource appropriately (adding it during the first run, then deleting it in the third one- make that conditional on e.g. reboot_pending? returning false).

HTH,

am

On 31 Mar 2015, at 17:35, Simon Hawkins Simon.Hawkins@totaljobsgroup.com wrote:

I’ve tried doing the following also:

  1.   Changed my run list to run just call the join domain script.
    
  2.   Add an include in the join domain recipe to call the rename_hostname recipe.
    
  3.   When the client is run, the rename_hostname recipe is called and the reboot is run.
    
  4.   The chef run gets terminated, so the domainjoin is never completed, but the machine reboots.
    

Is there any way of pausing the chef-run to wait for the machine to come back up, then run the domain join and reboot after that?

Cheers,
Simon.
From: Simon Hawkins [mailto:Simon.Hawkins@totaljobsgroup.com]
Sent: 31 March 2015 09:56
To: galen@getchef.com; chef@lists.opscode.com
Subject: [chef] RE: Re: Re: Re: Windows Reboots

Hi Daniel,

Many thanks, I now get this:

10.x.x.x [2015-03-31T09:35:41+01:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>3, :reason=>"Cannot continue Chef run without a reboot.", :timestamp=>2015-03-31 09:35:40 +0100, :requested_by=>"now"}

And the box restarts. The only thing is the chef run terminates and doesn’t go onto the next recipe. I was expecting the run to pause for 3 mins and then carry on after the reboot, is that how it should work? Do I need to put recipe depends on statements in the domainjoin recipe?

I have this in the rename machine recipe:

reboot "now" do
action :nothing
reason "Cannot continue Chef run without a reboot."
delay_mins 3
end

powershell_script "rename_hostname" do
code <<-EOH

….
EOH

notifies :reboot_now, 'reboot[now]', :immediately

END

Cheers,
Simon.
From: Galen Emery [mailto:galen@getchef.com]
Sent: 30 March 2015 16:22
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Windows Reboots

On Mon, Mar 30, 2015 at 7:42 AM, Daniel DeLeo dan@kallistec.com wrote:
Recent versions of Chef Client have a built-in reboot resource. reboot Resource

--
Daniel DeLeo

On Monday, March 30, 2015 at 7:40 AM, klum_tz@ukr.net wrote:

Hi Simon.

What I see at the moment is to run recipe which creates scheduled 1 time task which will run after reboot.
And in this task you will feed some batch file for changing PC name and adding it into domain.

Regards,
Taras.

--- Оригінальне повідомлення ---
Від кого: "Simon Hawkins" <simon.hawkins@totaljobsgroup.com (mailto:simon.hawkins@totaljobsgroup.com)>
Дата: 30 березня 2015, 17:19:12

All,

I have a recipe run as the following:

  1. Change the machine name using a powershell script (which only applies the name after a reboot L)

  2. Recipe to join the machine to the domain using the window_ad cookbook.

Because both these recipes reboot, how do I get chef to wait for the box to have restarted before it runs the join domain recipe? Currently at the moment it tries to run it during the reboot and fails.

Cheers,

Simon.

Disclaimer
This message is intended only for the use of the person(s) ("Intended Recipient") to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any dissemination, distribution, copying or other use of this message or any of its content by any person other than the Intended Recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the Intended Recipient, please contact the sender as soon as possible.

Totaljobs Group Limited Registered Office: Bluefin Building, 110 Southwark Street, London, SE1 0TA, UK Registered in England and Wales under company no. 4269861

In addition,

There's the reboot_pending? helper: About the Chef Infra Language

That allows you to guard against the reboot pre-emptively.

Even though this has been added to Chef, I still create the following
library file

reboot_pending.rb
class Chef
class Resource
# include Chef::Mixin::ShellOut

def reboot_pending?
  # Any files listed here means reboot needed
  (Registry.key_exists?('HKLM\SYSTEM\CurrentControlSet\Control\Session

Manager\PendingFileRenameOperations') &&
Registry.get_value('HKLM\SYSTEM\CurrentControlSet\Control\Session
Manager','PendingFileRenameOperations').any?) ||
# 1 for any value means reboot pending
# "9306cdfc-c4a1-4a22-9996-848cb67eddc3"=1

(Registry.key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto
Update\RebootRequired') &&

Registry.get_values('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto
Update\RebootRequired').select{|v| v[2] == 1 }.any?) ||
# 1 or 2 for 'Flags' value means reboot pending

(Registry.key_exists?('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile')
&&

[1,2].include?(Registry::get_value('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile','Flags')))
||
# added by Alex

Registry.key_exists?('HKLM\Software\Microsoft\Windows\CurrentVersion\Component
Based Servicing\RebootPending')
end

end
end

This will install the portions that are needed then continue the run to
finish the others. If doing an RDSH install, make sure you create a
scheduled task, for 15 minutes for the continuation. As sometimes the
Service will not start after RDSH is installed

task_chefclient.rb

windows_task 'Chef client' do
user 'Administrator'
password ''
cwd 'C:\chef\bin'
command 'chef-client -L C:\tmp'
run_level :highest
frequency :minute
frequency_modifier 15
end

Then for a windows RDSH install I use the following:

rdsh_server.rb

if node[:os_version] >= '6.2'
%w{ Xps-Foundation-Xps-Viewer Remote-Desktop-Services
ServerMediaFoundation AppServer InkAndHandwritingServices DesktopExperience
}.each do |feature|
windows_feature feature do
action :install
not_if {reboot_pending?}
end
end
else

Install RDSH

powershell node['w2k8']['rds'] do
code <<-EOH
Import-Module ServerManager
Add-WindowsFeature RDS-RD-Server
EOH
not_if {reboot_pending?}
end

Install desktop experience

powershell node['w2k8']['deskexp'] do
code <<-EOH
Import-Module ServerManager
Add-WindowsFeature Desktop-Experience
EOH
not_if {reboot_pending?}
end

Install XPS Viewer

powershell node['w2k8']['xps'] do
code <<-EOH
Import-Module ServerManager
Add-WindowsFeature XPS-Viewer
EOH
not_if {reboot_pending?}
end
end

windows_reboot 30 do
reason 'A System Restart has been requested. Rebooting now..'
only_if {reboot_pending?}
end

On Tue, Mar 31, 2015 at 12:13 PM, Aimelyne Mochiron aimelynem@gmail.com
wrote:

Hi Simon,

Wouldn't something like this work for your use case?

reboot "my_name" do
action :nothing
reason "reason"

other params as appropriate

end

powershell_script 'rename_hostname'
code <<-EOH
# code
EOH

insert guard here to ensure this doesn't run if correct hostname's

already set
notifies :request_reboot, "reboot[my_name]"
end

powershell_script "join_domain"
code <<-EOH

code

EOH
not_if {reboot_pending? || some_other_test}
notifies :request_reboot, "reboot[my_name]"
end

On the first run, rename_hostname will run, then set a reboot event
that'll trigger at the end of the Chef run (thanks to the :request_reboot
action); join_domain will be skipped owing to the reboot_pending? call.

Second run, rename_hostname should be skipped, join_domain will run and
notify for a reboot again.

Third and subsequent times, nothing should happen.

To make sure chef-client runs on reboot, you could create a task, using
e.g. windows_task from the Windows cookbook (
GitHub - chef-boneyard/windows: Development repository for Chef Cookbook windows), then you could notify the
windows_task resource appropriately (adding it during the first run, then
deleting it in the third one- make that conditional on e.g. reboot_pending?
returning false).

HTH,

am

On 31 Mar 2015, at 17:35, Simon Hawkins Simon.Hawkins@totaljobsgroup.com
wrote:

I’ve tried doing the following also:

  1.   Changed my run list to run just call the join domain script.
    
  2.   Add an include in the join domain recipe to call the
    

rename_hostname recipe.
3. When the client is run, the rename_hostname recipe is called and
the reboot is run.
4. The chef run gets terminated, so the domainjoin is never
completed, but the machine reboots.

Is there any way of pausing the chef-run to wait for the machine to come
back up, then run the domain join and reboot after that?

Cheers,
Simon.
From: Simon Hawkins [mailto:Simon.Hawkins@totaljobsgroup.com
Simon.Hawkins@totaljobsgroup.com]
Sent: 31 March 2015 09:56
To: galen@getchef.com; chef@lists.opscode.com
Subject: [chef] RE: Re: Re: Re: Windows Reboots

Hi Daniel,

Many thanks, I now get this:

10.x.x.x [2015-03-31T09:35:41+01:00] WARN: Rebooting server at a recipe's
request. Details: {:delay_mins=>3, :reason=>"Cannot continue Chef run
without a reboot.", :timestamp=>2015-03-31 09:35:40 +0100,
:requested_by=>"now"}

And the box restarts. The only thing is the chef run terminates and
doesn’t go onto the next recipe. I was expecting the run to pause for 3
mins and then carry on after the reboot, is that how it should work? Do I
need to put recipe depends on statements in the domainjoin recipe?

I have this in the rename machine recipe:

reboot "now" do
action :nothing
reason "Cannot continue Chef run without a reboot."
delay_mins 3
end

powershell_script "rename_hostname" do
code <<-EOH

….
EOH

notifies :reboot_now, 'reboot[now]', :immediately

END

Cheers,
Simon.
From: Galen Emery [mailto:galen@getchef.com galen@getchef.com]
Sent: 30 March 2015 16:22
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Windows Reboots

On Mon, Mar 30, 2015 at 7:42 AM, Daniel DeLeo dan@kallistec.com wrote:
Recent versions of Chef Client have a built-in reboot resource.
reboot Resource

--
Daniel DeLeo

On Monday, March 30, 2015 at 7:40 AM, klum_tz@ukr.net wrote:

Hi Simon.

What I see at the moment is to run recipe which creates scheduled 1 time
task which will run after reboot.
And in this task you will feed some batch file for changing PC name and
adding it into domain.

Regards,
Taras.

--- Оригінальне повідомлення ---
Від кого: "Simon Hawkins" <simon.hawkins@totaljobsgroup.com (mailto:
simon.hawkins@totaljobsgroup.com)>
Дата: 30 березня 2015, 17:19:12

All,

I have a recipe run as the following:

  1. Change the machine name using a powershell script (which only
    applies the name after a reboot L)

  2. Recipe to join the machine to the domain using the window_ad
    cookbook.

Because both these recipes reboot, how do I get chef to wait for the
box to have restarted before it runs the join domain recipe? Currently at
the moment it tries to run it during the reboot and fails.

Cheers,

Simon.

Disclaimer
This message is intended only for the use of the person(s) ("Intended
Recipient") to whom it is addressed. It may contain information which is
privileged and confidential. Accordingly any dissemination, distribution,
copying or other use of this message or any of its content by any person
other than the Intended Recipient may constitute a breach of civil or
criminal law and is strictly prohibited. If you are not the Intended
Recipient, please contact the sender as soon as possible.

Totaljobs Group Limited Registered Office: Bluefin Building, 110
Southwark Street, London, SE1 0TA, UK Registered in England and Wales under
company no. 4269861

In addition,

There's the reboot_pending? helper:
About the Chef Infra Language

That allows you to guard against the reboot pre-emptively.

--

Todd Pigram

www.linkedin.com/in/toddpigram/
@pigram86 on twitter

Mobile - 216-224-5769

Hi Simon,
One of possible solutions (I saw it somewhere in the internet) is using tags.
E.G. if box has this tag do some step/recipe. Inside that step/recipe delete that tag, Next time after reboot that box will not have this tag hence other step will go further which is based on other tag...
So essentially create few tags. And each step/recipe will require some list of tags. Hence after reboot chef-client will start again. But basing on tags present for this node we can run and manipulate with what we would like to run... And just clean tags after recipe is done.
Regards, Taras.

--- Оригінальне повідомлення ---
Від кого: "Simon Hawkins" simon.hawkins@totaljobsgroup.com
Дата: 31 березня 2015, 17:36:25

I’ve tried doing the following also: 1. Changed my run list to run just call the join domain script. 2. Add an include in the join domain recipe to call the rename_hostname recipe. 3. When the client is run, the rename_hostname recipe is called and the reboot is run. 4. The chef run gets terminated, so the domainjoin is never completed, but the machine reboots. Is there any way of pausing the chef-run to wait for the machine to come back up, then run the domain join and reboot after that? Cheers, Simon. From: Simon Hawkins [mailto:Simon.Hawkins@totaljobsgroup.com]
Sent: 31 March 2015 09:56
To: galen@getchef.com ; chef@lists.opscode.com
Subject: [chef] RE: Re: Re: Re: Windows Reboots Hi Daniel, Many thanks, I now get this: 10.x.x.x [2015-03-31T09:35:41+01:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>3, :reason=>"Cannot continue Chef run without a reboot.", :timestamp=>2015-03-31 09:35:40 +0100, :requested_by=>"now"} And the box restarts. The only thing is the chef run terminates and doesn’t go onto the next recipe. I was expecting the run to pause for 3 mins and then carry on after the reboot, is that how it should work? Do I need to put recipe depends on statements in the domainjoin recipe? I have this in the rename machine recipe: reboot "now" do action :nothing reason "Cannot continue Chef run without a reboot." delay_mins 3 end powershell_script "rename_hostname" do code <<-EOH …. EOH notifies :reboot_now, 'reboot[now]', :immediately END Cheers, Simon. From: Galen Emery [ mailto:galen@getchef.com ]
Sent: 30 March 2015 16:22
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Windows Reboots On Mon, Mar 30, 2015 at 7:42 AM, Daniel DeLeo < dan@kallistec.com > wrote: Recent versions of Chef Client have a built-in reboot resource. reboot Resource

--
Daniel DeLeo

On Monday, March 30, 2015 at 7:40 AM, klum_tz@ukr.net wrote:

Hi Simon.

What I see at the moment is to run recipe which creates scheduled 1 time task which will run after reboot.
And in this task you will feed some batch file for changing PC name and adding it into domain.

Regards,
Taras.

--- Оригінальне повідомлення ---
Від кого: "Simon Hawkins" < simon.hawkins@totaljobsgroup.com (mailto: simon.hawkins@totaljobsgroup.com )>
Дата: 30 березня 2015, 17:19:12

All,

I have a recipe run as the following:

  1. Change the machine name using a powershell script (which only applies the name after a reboot L)

  2. Recipe to join the machine to the domain using the window_ad cookbook.

Because both these recipes reboot, how do I get chef to wait for the box to have restarted before it runs the join domain recipe? Currently at the moment it tries to run it during the reboot and fails.

Cheers,

Simon.

Disclaimer
This message is intended only for the use of the person(s) ("Intended Recipient") to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any dissemination, distribution, copying or other use of this message or any of its content by any person other than the Intended Recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the Intended Recipient, please contact the sender as soon as possible.

Totaljobs Group Limited Registered Office: Bluefin Building, 110 Southwark Street, London, SE1 0TA, UK Registered in England and Wales under company no. 4269861

In addition,

There's the reboot_pending? helper: About the Chef Infra Language

That allows you to guard against the reboot pre-emptively.

Hi Taras,

Yes, I have been looking at the following:

The question is, can you add tags on a boot strap, so for example it gets set to 1 and runs the rename_hostname part?

I assume my recipe would look like this

Rename_host:

if tagged?("doAction1")

reboot "now" do
action :nothing
reason "Cannot continue Chef run without a reboot."
delay_mins 0
end

powershell_script "rename_hostname" do
code <<-EOH

EOH

notifies :reboot_now, 'reboot[now]', :immediately

end

end


And the domainjoin would be:

if tagged?("doAction2")

reboot "now" do
action :nothing
reason "Cannot continue Chef run without a reboot."
delay_mins 0
end

powershell_script "join_domain" do
code <<-EOH

EOH

notifies :reboot_now, 'reboot[now]', :immediately

end

end

Cheers,
Simon

From: klum_tz@ukr.net [mailto:klum_tz@ukr.net]
Sent: 01 April 2015 11:55
To: chef@lists.opscode.com
Cc: chef@lists.opscode.com
Subject: [chef] Re: RE: RE: Re: Re: Re: Windows Reboots

Hi Simon,

One of possible solutions (I saw it somewhere in the internet) is using tags.

E.G. if box has this tag do some step/recipe. Inside that step/recipe delete that tag,
Next time after reboot that box will not have this tag hence other step will go further which is based on other tag...

So essentially create few tags. And each step/recipe will require some list of tags.
Hence after reboot chef-client will start again. But basing on tags present for this node we can run and manipulate with what we would like to run...
And just clean tags after recipe is done.

Regards,
Taras.
--- Оригінальне повідомлення ---
Від кого: "Simon Hawkins" <simon.hawkins@totaljobsgroup.commailto:simon.hawkins@totaljobsgroup.com>
Дата : 31 березня 2015, 17:36:25

I’ve tried doing the following also:

  1.   Changed my run list to run just call the join domain script.
    
  2.   Add an include in the join domain recipe to call the rename_hostname recipe.
    
  3.   When the client is run, the rename_hostname recipe is called and the reboot is run.
    
  4.   The chef run gets terminated, so the domainjoin is never completed, but the machine reboots.
    

Is there any way of pausing the chef-run to wait for the machine to come back up, then run the domain join and reboot after that?

Cheers,

Simon.

From: Simon Hawkins [mailto:Simon.Hawkins@totaljobsgroup.com]
Sent: 31 March 2015 09:56
To: galen@getchef.commailto:galen@getchef.com; chef@lists.opscode.commailto:chef@lists.opscode.com
Subject: [chef] RE: Re: Re: Re: Windows Reboots

Hi Daniel,

Many thanks, I now get this:

10.x.x.x [2015-03-31T09:35:41+01:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>3, :reason=>"Cannot continue Chef run without a reboot.", :timestamp=>2015-03-31 09:35:40 +0100, :requested_by=>"now"}

And the box restarts. The only thing is the chef run terminates and doesn’t go onto the next recipe. I was expecting the run to pause for 3 mins and then carry on after the reboot, is that how it should work? Do I need to put recipe depends on statements in the domainjoin recipe?

I have this in the rename machine recipe:

reboot "now" do

action :nothing

reason "Cannot continue Chef run without a reboot."

delay_mins 3

end

powershell_script "rename_hostname" do

code <<-EOH

….

EOH

notifies :reboot_now, 'reboot[now]', :immediately

END

Cheers,

Simon.

From: Galen Emery [mailto:galen@getchef.com]
Sent: 30 March 2015 16:22
To: chef@lists.opscode.commailto:chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Windows Reboots

On Mon, Mar 30, 2015 at 7:42 AM, Daniel DeLeo <dan@kallistec.commailto:dan@kallistec.com> wrote:

Recent versions of Chef Client have a built-in reboot resource. reboot Resource

--
Daniel DeLeo

On Monday, March 30, 2015 at 7:40 AM, klum_tz@ukr.netmailto:klum_tz@ukr.net wrote:

Hi Simon.

What I see at the moment is to run recipe which creates scheduled 1 time task which will run after reboot.
And in this task you will feed some batch file for changing PC name and adding it into domain.

Regards,
Taras.

--- Оригінальне повідомлення ---
Від кого: "Simon Hawkins" <simon.hawkins@totaljobsgroup.commailto:simon.hawkins@totaljobsgroup.com (mailto:simon.hawkins@totaljobsgroup.commailto:simon.hawkins@totaljobsgroup.com)>
Дата: 30 березня 2015, 17:19:12

All,

I have a recipe run as the following:

  1. Change the machine name using a powershell script (which only applies the name after a reboot L)

  2. Recipe to join the machine to the domain using the window_ad cookbook.

Because both these recipes reboot, how do I get chef to wait for the box to have restarted before it runs the join domain recipe? Currently at the moment it tries to run it during the reboot and fails.

Cheers,

Simon.

Disclaimer
This message is intended only for the use of the person(s) ("Intended Recipient") to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any dissemination, distribution, copying or other use of this message or any of its content by any person other than the Intended Recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the Intended Recipient, please contact the sender as soon as possible.

Totaljobs Group Limited Registered Office: Bluefin Building, 110 Southwark Street, London, SE1 0TA, UK Registered in England and Wales under company no. 4269861

In addition,

There's the reboot_pending? helper: About the Chef Infra Language

That allows you to guard against the reboot pre-emptively.

All,

So this seems to work using tags:

10.x.x.x [2015-04-01T14:01:11+01:00] INFO: Processing powershell_script[rename_hostname] action run (windows::rename_hostname line 9)
10.x.x.x [2015-04-01T14:02:07+01:00] INFO: powershell_script[rename_hostname] ran successfully
10.x.x.x [2015-04-01T14:02:07+01:00] INFO: powershell_script[rename_hostname] sending reboot_now action to reboot[now] (immediate)
10.x.x.x [2015-04-01T14:02:07+01:00] INFO: Processing reboot[now] action reboot_now (windows::rename_hostname line 3)
10.x.x.x [2015-04-01T14:02:07+01:00] WARN: Rebooting system immediately, requested by 'now'
10.x.x.x [2015-04-01T14:02:07+01:00] INFO: Changing reboot status from {} to {:delay_mins=>0, :reason=>"Cannot continue Chef run without a reboot.", :timestamp=>2015-04-01 14:02:07 +0100, :requested_by=>"now"}
10.x.x.x [2015-04-01T14:02:07+01:00] INFO: Chef Run complete in 69.357722 seconds
10.x.x.x [2015-04-01T14:02:07+01:00] INFO: Running report handlers
10.x.x.x [2015-04-01T14:02:07+01:00] INFO: Report handlers complete
10.x.x.x [2015-04-01T14:02:07+01:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>0, :reason=>"Cannot continue Chef run without a reboot.", :timestamp=>2015-04-01 14:02:07 +0100, :requested_by=>"now"}
$ knife tag list node5
doAction2

So the tagging works, but the problem is the chef-run terminates, so the “one click” deploy process breaks.

It would be useful if the run could do something like:

10.x.x.x [2015-04-01T14:02:07+01:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>0, :reason=>"Cannot continue Chef run without a reboot.", :timestamp=>2015-04-01 14:02:07 +0100, :requested_by=>"now"}
10.x.x.x [ waiting for reboot to complete before continuing]
10.x.x.x [ waiting for reboot to complete before continuing]
10.x.x.x [ waiting for reboot to complete before continuing]
10.x.x.x [machine back up, running domain join]
etc

Cheers,
Simon.

From: Simon Hawkins [mailto:Simon.Hawkins@totaljobsgroup.com]
Sent: 01 April 2015 12:39
To: chef@lists.opscode.com
Subject: [chef] RE: Re: RE: RE: Re: Re: Re: Windows Reboots

Hi Taras,

Yes, I have been looking at the following:

The question is, can you add tags on a boot strap, so for example it gets set to 1 and runs the rename_hostname part?

I assume my recipe would look like this

Rename_host:

if tagged?("doAction1")

reboot "now" do
action :nothing
reason "Cannot continue Chef run without a reboot."
delay_mins 0
end

powershell_script "rename_hostname" do
code <<-EOH

EOH

notifies :reboot_now, 'reboot[now]', :immediately

end

end


And the domainjoin would be:

if tagged?("doAction2")

reboot "now" do
action :nothing
reason "Cannot continue Chef run without a reboot."
delay_mins 0
end

powershell_script "join_domain" do
code <<-EOH

EOH

notifies :reboot_now, 'reboot[now]', :immediately

end

end

Cheers,
Simon

From: klum_tz@ukr.netmailto:klum_tz@ukr.net [mailto:klum_tz@ukr.net]
Sent: 01 April 2015 11:55
To: chef@lists.opscode.commailto:chef@lists.opscode.com
Cc: chef@lists.opscode.commailto:chef@lists.opscode.com
Subject: [chef] Re: RE: RE: Re: Re: Re: Windows Reboots

Hi Simon,

One of possible solutions (I saw it somewhere in the internet) is using tags.

E.G. if box has this tag do some step/recipe. Inside that step/recipe delete that tag,
Next time after reboot that box will not have this tag hence other step will go further which is based on other tag...

So essentially create few tags. And each step/recipe will require some list of tags.
Hence after reboot chef-client will start again. But basing on tags present for this node we can run and manipulate with what we would like to run...
And just clean tags after recipe is done.

Regards,
Taras.
--- Оригінальне повідомлення ---
Від кого: "Simon Hawkins" <simon.hawkins@totaljobsgroup.commailto:simon.hawkins@totaljobsgroup.com>
Дата : 31 березня 2015, 17:36:25

I’ve tried doing the following also:

  1.   Changed my run list to run just call the join domain script.
    
  2.   Add an include in the join domain recipe to call the rename_hostname recipe.
    
  3.   When the client is run, the rename_hostname recipe is called and the reboot is run.
    
  4.   The chef run gets terminated, so the domainjoin is never completed, but the machine reboots.
    

Is there any way of pausing the chef-run to wait for the machine to come back up, then run the domain join and reboot after that?

Cheers,

Simon.

From: Simon Hawkins [mailto:Simon.Hawkins@totaljobsgroup.com]
Sent: 31 March 2015 09:56
To: galen@getchef.commailto:galen@getchef.com; chef@lists.opscode.commailto:chef@lists.opscode.com
Subject: [chef] RE: Re: Re: Re: Windows Reboots

Hi Daniel,

Many thanks, I now get this:

10.x.x.x [2015-03-31T09:35:41+01:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>3, :reason=>"Cannot continue Chef run without a reboot.", :timestamp=>2015-03-31 09:35:40 +0100, :requested_by=>"now"}

And the box restarts. The only thing is the chef run terminates and doesn’t go onto the next recipe. I was expecting the run to pause for 3 mins and then carry on after the reboot, is that how it should work? Do I need to put recipe depends on statements in the domainjoin recipe?

I have this in the rename machine recipe:

reboot "now" do

action :nothing

reason "Cannot continue Chef run without a reboot."

delay_mins 3

end

powershell_script "rename_hostname" do

code <<-EOH

….

EOH

notifies :reboot_now, 'reboot[now]', :immediately

END

Cheers,

Simon.

From: Galen Emery [mailto:galen@getchef.com]
Sent: 30 March 2015 16:22
To: chef@lists.opscode.commailto:chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Windows Reboots

On Mon, Mar 30, 2015 at 7:42 AM, Daniel DeLeo <dan@kallistec.commailto:dan@kallistec.com> wrote:

Recent versions of Chef Client have a built-in reboot resource. reboot Resource

--
Daniel DeLeo

On Monday, March 30, 2015 at 7:40 AM, klum_tz@ukr.netmailto:klum_tz@ukr.net wrote:

Hi Simon.

What I see at the moment is to run recipe which creates scheduled 1 time task which will run after reboot.
And in this task you will feed some batch file for changing PC name and adding it into domain.

Regards,
Taras.

--- Оригінальне повідомлення ---
Від кого: "Simon Hawkins" <simon.hawkins@totaljobsgroup.commailto:simon.hawkins@totaljobsgroup.com (mailto:simon.hawkins@totaljobsgroup.commailto:simon.hawkins@totaljobsgroup.com)>
Дата: 30 березня 2015, 17:19:12

All,

I have a recipe run as the following:

  1. Change the machine name using a powershell script (which only applies the name after a reboot L)

  2. Recipe to join the machine to the domain using the window_ad cookbook.

Because both these recipes reboot, how do I get chef to wait for the box to have restarted before it runs the join domain recipe? Currently at the moment it tries to run it during the reboot and fails.

Cheers,

Simon.

Disclaimer
This message is intended only for the use of the person(s) ("Intended Recipient") to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any dissemination, distribution, copying or other use of this message or any of its content by any person other than the Intended Recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the Intended Recipient, please contact the sender as soon as possible.

Totaljobs Group Limited Registered Office: Bluefin Building, 110 Southwark Street, London, SE1 0TA, UK Registered in England and Wales under company no. 4269861

In addition,

There's the reboot_pending? helper: About the Chef Infra Language

That allows you to guard against the reboot pre-emptively.