在 Server 2012R2 中使用重启时测试厨房不会重试

Test kitchen doesn't retry when using reboot in Server 2012R2

我的食谱要求来宾在 Windows Server 2012R2 上安装 WMF5 后重新启动。

reboot 'Reboot Windows' do
  action :nothing
end

chocolatey 'DotNet4.5.1' do
  version '4.5.1.20140606'
  action :install
end

chocolatey 'Powershell' do
  version '5.0.10586.20161027'
  action :install
  options ({ '-ignore-package-exit-codes' => '' })
end

powershell_script 'Reboot if PowerShell v4' do
  notifies :reboot_now, 'reboot[Reboot Windows]', :immediately
  only_if { reboot_pending? }
end

当重启发生时,测试厨房将退出而不尝试再次收敛。我也看不到退出代码。

D      [WinRM] Waiting for output...
D      [WinRM] Processing output
         - execute the ruby block track-path-Powershell

     * powershell_script[Reboot if PowerShell v4] action run
       - execute "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -File "C:/Users/vagrant/AppData/Local/Temp/chef-script20161212-936-452h54.ps1"
     * reboot[Reboot Windows] action reboot_now[2016-12-12T15:44:04-05:00] WARN: Rebooting system immediately, requested by 'Reboot Windows'


       Running handlers:
       Running handlers complete
       Chef Client finished, 54/140 resources updated in 02 minutes 46 seconds
   [2016-12-12T15:44:04-05:00] WARN: Rebooting server at a recipe's request. Details: {:delay_mins=>0, :reason=>"Reboot by Chef", :timestamp=>2016-12-12 15:44:04 -0500, :requested_by=>"Reboot Windows"}
D      [WinRM] Waiting for output...
D      [WinRM] Processing output
D      [WinRM] cleaning up command_id: 737D4041-AE48-4403-ADEC-840D31B1FE0E on shell_id B4370D6D-AE03-46E3-9823-EFB3EF2EA14C
$$$$$$ DL is deprecated, please use Fiddle
D      Cleaning up local sandbox in     C:/Users/lsmit648/AppData/Local/Temp/default-windows2012r2min-sandbox-20161212-12432-rf5u0f
       Finished converging <default-windows2012r2min> (3m19.06s).
-----> Kitchen is finished. (3m58.02s)

这是我的 .kitchen.yaml 文件

---
driver:
  name: vagrant
  provider: virtualbox
  gui: false
  box_check_update: true
  vm_hostname: false
  communicator: winrm
  guest: windows
  customize:
    natdnshostresolver1: 'on'
    natdnsproxy1: 'on'
    usb: 'off'
  reset_command: "exit 0"
  username: 'vagrant'
  password: 'vagrant'
  winrm:
    boot_timeout: 600
    max_tries: 500

# https://github.com/chef/chef-dk/issues/1009#issuecomment-246875683
transport:
  name: winrm
  username: 'vagrant'
  password: 'vagrant'
  elevated: true

provisioner:
  name: chef_zero
  retry_on_exit_code:
    - [35, 1]
  max_retries: 5
  wait_for_retry: 60
  client_rb:
    exit_status: :enabled

verifier:
  name: inspec

platforms:
  - name: windows2012.r2.min
    transport:
      port: 5985
    os_type: windows
    shell_type: powershell
    driver:
      box: windows2012.r2.min
      box_url: <%= ENV['VAGRANT_BOX_REPOSITORY'] %>/windows2012.r2min.json
      port: 5985
      winrm:
        guest_port: 5985
      network:
        - ['forwarded_port', {guest: 3389, host: 9561, id: 'rdp', auto_correct: true}]
        - ['forwarded_port', {guest: 5985, host: 9571, id: 'winrm', auto_correct: true}]
suites:
  - name: default
    run_list:
      - recipe[chocolatey::default]
      - recipe[wmf_5]
      - recipe[roles_features]

如何捕获重新启动正在使用的退出代码,以便厨房再次尝试收敛?

解决了问题。

默认安装的 Chef 客户端是 12.8.1

我需要最低版本 12.11 才能正确返回退出代码