chef-cookbooks / chef_client_updater

Chef Cookbook to update the chef client on nodes
https://supermarket.chef.io/cookbooks/chef_client_updater
Apache License 2.0
54 stars 79 forks source link

I think chef_client_updater won't work for windows upgrade (please read the description) for more details #129

Closed huamichaelchen closed 6 years ago

huamichaelchen commented 6 years ago

Cookbook version

chef_client_updater: 3.3.4

Chef-client version

12.12.15

Platform Details

[Operating system distribution and release version. Cloud provider if running in the cloud] windows 2012 r2

Scenario:

[What you are trying to achieve and you can't?] I'm trying to upgrade chef client from 12.12.15 to the latest by running the cookbook

Steps to Reproduce:

[If you are filing an issue what are the things we need to do in order to repro your problem? How are you using this cookbook or any resources it includes?]

I wrote a wrapper cookbook so that we can overwrite certain attributes.

#
# Cookbook:: our_chef_client_updater
# Recipe:: default
#
# Copyright 2018, 
#
# All rights reserved - Do Not Redistribute

# Are we in local mode?
local_test_enabled = (node['local_test'] == true || Chef::Config['solo'] || Chef::Config['local_mode'])

# Construct a Ruby Hash for the checksum 
checksums = {
  '13.9.4_rhel_7.3' => 'abd958b3c053d8051108a4f85252a582aedb4ba74b0d35423779864fe8b02479',
  '13.9.4_windows' => 'b9b8a0a87a33faa133a033b0c02400d10fd296dc0637e13997bd9b2e42a9cbdf',
  '14.2.0_rhel_7.3' => 'abdb676a8d55fc9807b4eabe5313c54d3946977d7ae3eecd7303cd388b04042a',
  '14.2.0_windows' => '8744c716386b82f792f41ba286431e88afeb3efd68ee46cd46516b1d6930722c',
  '14.3.37_windows' => 'f5ef8c31898592824751ec2252fe317c0f667db25ac40452710c8ccf35a1b28d',
  '14.3.37_rhel_6.9' => 'afbe87df432e6b7c02dfda141c38ba93c29ace11cbf5de03e505b5cb902fc6d1',
  '14.3.37_rhel_7.3' => '1807c453c5a16fd2cb0941f98847a0031c3812ccb9e3a628b2f8fba8335f485c'
}

# prevent a newer clien 'updating' to an older client
node.default['chef_client_updater']['prevent_downgrade'] = true

# resmed overwrites
node.default['chef_client_updater']['version'] = node['chef_client_version_from_bamboo']
Chef::Log.info("====> You are upgrading chef-client to version: #{node['chef_client_updater']['version']}. NOTE: This cookbook has set ['chef_client_updater']['prevent_downgrade'] = #{node['chef_client_updater']['prevent_downgrade']}")
case node['platform_family']
when 'rhel'
  rhel_version = ("#{node['platform_version']}".include? '6') ? '6' : '7'
  node.default['chef_client']['file_name'] = "chef-#{node['chef_client_updater']['version']}-1.el#{rhel_version}.x86_64.rpm"

  execute 'set RHEL system wide proxy' do
    command "export {http,https}_proxy='http://ourProxyServer'"
    action :run
  end

  node.default['chef_client_updater']['checksum'] = checksums["#{node['chef_client_updater']['version']}_#{node['platform_family']}_#{node['platform_version']}"]

when 'windows'
  reg = "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
  node.default['chef_client']['file_name'] = "chef-client-#{node['chef_client_updater']['version']}-1-x64.msi"

  powershell_script 'set windows system wide proxy' do
    code <<-EOH
      $settings = Get-ItemProperty -Path "#{reg}"
      $settings.ProxyServer
      $settings.ProxyEnable
      New-ItemProperty -Path "#{reg}" -Name ProxyServer -Value "http://ourProxyServer"
      Set-ItemProperty -Path "#{reg}" -Name ProxyEnable -Value 1
    EOH
    notifies :run, "powershell_script[unset windows system wide proxy]", :delayed
  end

  powershell_script 'unset windows system wide proxy' do
    code <<-EOH
      Set-ItemProperty -Path "#{reg}" -Name ProxyEnable -Value 0
    EOH
    # notifies :delayed
  end

  node.default['chef_client_updater']['handle_zip_download_url'] = "http://ourNexusServer/nexus/content/repositories/OTS-Repo-SVN/io/chef/chef-client/#{node['chef_client_updater']['version']}/Handle.zip"
  node.default['chef_client_updater']['checksum'] = checksums["#{node['chef_client_updater']['version']}_#{node['platform_family']}"]

else
  Chef::Log.fatal("====> In resmed, as of now, we only support redhat and windows family :)")
  raise
end

node.default['chef_client_updater']['download_url_override'] = "http://ourNexusServer/nexus/content/repositories/OTS-Repo-SVN/io/chef/chef-client/#{node['chef_client_updater']['version']}/#{node['chef_client']['file_name']}"

node.default['chef_client_updater']['post_install_action'] = 'exec'
Chef::Log.info("====> post_installation_action: #{node['chef_client_updater']['post_install_action']}")

chef_client_updater 'update chef-client' do
  channel node['chef_client_updater']['channel']
  version node['chef_client_updater']['version']
  prevent_downgrade node['chef_client_updater']['prevent_downgrade']
  post_install_action node['chef_client_updater']['post_install_action']
  download_url_override node['chef_client_updater']['download_url_override'] if node['chef_client_updater']['download_url_override']
  checksum node['chef_client_updater']['checksum'] if node['chef_client_updater']['checksum']
  upgrade_delay node['chef_client_updater']['upgrade_delay'] unless node['chef_client_updater']['upgrade_delay'].nil?
  product_name node['chef_client_updater']['product_name'] if node['chef_client_updater']['product_name']
  handle_zip_download_url node['chef_client_updater']['handle_zip_download_url'] if node['chef_client_updater']['handle_zip_download_url']
end

Expected Result:

[What are you expecting to happen as the consequence of above reproduction steps?] Hoped it would successfully updated our chef-client from 12.12.15 to 14.3.37

Actual Result:

[What actually happens after the reproduction steps? Include the error output or a link to a gist if possible.]

chef-client run failed with the following:

I, [2018-07-30T14:42:30.345410 #19140]  INFO -- default-windows-2012r2:       - execute "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -File "C:/Users/vagrant/AppData/Local/Temp/chef-script20180730-2104-1thy3d8.ps1"
I, [2018-07-30T14:42:30.388418 #19140]  INFO -- default-windows-2012r2:     - upgrade chef-client 12.12.15 to 14.3.37[2018-07-30T18:41:13+00:00] WARN: forcing "exec" to "kill" on windows.
I, [2018-07-30T14:42:30.445519 #19140]  INFO -- default-windows-2012r2: [2018-07-30T18:41:13+00:00] WARN: New chef-client installed and exit is allowed. Forcing chef exit!
I, [2018-07-30T14:42:30.505941 #19140]  INFO -- default-windows-2012r2: 
I, [2018-07-30T14:42:30.548681 #19140]  INFO -- default-windows-2012r2:     ================================================================================
I, [2018-07-30T14:42:30.589100 #19140]  INFO -- default-windows-2012r2:     Error executing action `update` on resource 'chef_client_updater[update chef-client]'
I, [2018-07-30T14:42:30.649515 #19140]  INFO -- default-windows-2012r2:     ================================================================================
I, [2018-07-30T14:42:30.700865 #19140]  INFO -- default-windows-2012r2: 
I, [2018-07-30T14:42:30.745645 #19140]  INFO -- default-windows-2012r2:     SystemExit
I, [2018-07-30T14:42:30.775687 #19140]  INFO -- default-windows-2012r2:     ----------
I, [2018-07-30T14:42:30.823329 #19140]  INFO -- default-windows-2012r2:     exit
I, [2018-07-30T14:42:30.869699 #19140]  INFO -- default-windows-2012r2: 
I, [2018-07-30T14:42:30.909796 #19140]  INFO -- default-windows-2012r2:     Resource Declaration:
I, [2018-07-30T14:42:30.942397 #19140]  INFO -- default-windows-2012r2:     ---------------------
I, [2018-07-30T14:42:30.979051 #19140]  INFO -- default-windows-2012r2:     # In C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/cookbooks/resmed_chef_client_updater/recipes/default.rb
I, [2018-07-30T14:42:31.022708 #19140]  INFO -- default-windows-2012r2: 
I, [2018-07-30T14:42:31.056816 #19140]  INFO -- default-windows-2012r2:      83: chef_client_updater 'update chef-client' do
I, [2018-07-30T14:42:31.105442 #19140]  INFO -- default-windows-2012r2:      84:   channel node['chef_client_updater']['channel']
I, [2018-07-30T14:42:31.145461 #19140]  INFO -- default-windows-2012r2:      85:   version node['chef_client_updater']['version']
I, [2018-07-30T14:42:31.190413 #19140]  INFO -- default-windows-2012r2:      86:   prevent_downgrade node['chef_client_updater']['prevent_downgrade']
I, [2018-07-30T14:42:31.234468 #19140]  INFO -- default-windows-2012r2:      87:   post_install_action node['chef_client_updater']['post_install_action']
I, [2018-07-30T14:42:31.285728 #19140]  INFO -- default-windows-2012r2:      88:   download_url_override node['chef_client_updater']['download_url_override'] if node['chef_client_updater']['download_url_override']
I, [2018-07-30T14:42:31.331990 #19140]  INFO -- default-windows-2012r2:      89:   checksum node['chef_client_updater']['checksum'] if node['chef_client_updater']['checksum']
I, [2018-07-30T14:42:31.378332 #19140]  INFO -- default-windows-2012r2:      90:   upgrade_delay node['chef_client_updater']['upgrade_delay'] unless node['chef_client_updater']['upgrade_delay'].nil?
I, [2018-07-30T14:42:31.417179 #19140]  INFO -- default-windows-2012r2:      91:   product_name node['chef_client_updater']['product_name'] if node['chef_client_updater']['product_name']
I, [2018-07-30T14:42:31.469624 #19140]  INFO -- default-windows-2012r2:      92:   handle_zip_download_url node['chef_client_updater']['handle_zip_download_url'] if node['chef_client_updater']['handle_zip_download_url']
I, [2018-07-30T14:42:31.513035 #19140]  INFO -- default-windows-2012r2:      93: end
I, [2018-07-30T14:42:31.552533 #19140]  INFO -- default-windows-2012r2:      94: 
I, [2018-07-30T14:42:31.601752 #19140]  INFO -- default-windows-2012r2:      95: 
I, [2018-07-30T14:42:31.654298 #19140]  INFO -- default-windows-2012r2: 

Potential reason for this behavior

I think the reason it was success with the windows 2012r2 update is because

  1. In the code here https://github.com/chef-cookbooks/chef_client_updater/blob/a4b30066168f862759cf3e6c55a8cce15bed343e/providers/default.rb#L175-L178

The code sets to post_installation_action to 'kill' no matter what we pass in.

  1. Then it won't go into this block, because of !windows? https://github.com/chef-cookbooks/chef_client_updater/blob/a4b30066168f862759cf3e6c55a8cce15bed343e/providers/default.rb#L197-L198

  2. Finally, all it can do is raise the error and exit https://github.com/chef-cookbooks/chef_client_updater/blob/a4b30066168f862759cf3e6c55a8cce15bed343e/providers/default.rb#L201-L203

In other words, for windows, chef_client_updater cookbook, the post_installation_action is always set to 'kill' no matter what you pass in, then it won't go into the kill case/when logic because of the !windows?. Eventually, all it can do is raise error and exit...

welcomebot commented 6 years ago

Hey There It looks like this is the first issue you've filed against the chef-cookbooks project. I'm here to offer you a bit of extra help to make sure we can quickly get back to you. Make sure you've filled out all the fields in our issue template. Make sure you've provided us with the version of chef-client you're running, your operating system and the version of the cookbook. If you're not using the most up to date version of the cookbook then please make sure to update first. Lots of things change between versions even if you're issue isn't listed in the changelog. Finally please give us a detailed description of the issue you're having. The more we know about what you're trying to do, what actually happens, and how you can reproduce the problem, the better.

If you're looking for more immediate troubleshooting help make sure to check out #general on the Chef Community Slack. There's plenty of folks there willing to lend a helping hand. Thanks for the first issue. We hope we can get back to you soon with a solution.

stuartpreston commented 6 years ago

Hi @huamichaelchen - the behaviour you experienced is by design, we want the current Chef Client to exit as fast as possible after setting up a scheduled task containing the PowerShell script required to run the real upgrade. If this didn't work for you, have a look in your c:\opscode folder for a log file and join us in the #windows channel in Chef Community Slack. I'm going to close this issue for now but will open a new issue if we find a defect to solve. Thanks!

huamichaelchen commented 6 years ago

@stuartpreston Thank you for the response :)

I just want to confirm a few things.

  1. By running this cookbook on a windows infrastructure, chef-client will exit regardless of what I pass in?
  2. If the above point is correct, then I need to manually kick of the c:\opscode\chef_upgrade.ps1?