chocolatey-community / chocolatey-cookbook

Chef cookbook to install chocolatey and packages on Windows
Apache License 2.0
108 stars 77 forks source link

Fail to install chocolatey due Powershell_script ArgumentError #118

Closed tiagolo closed 7 years ago

tiagolo commented 7 years ago

Cookbook version

1.1.0

Chef-client version

13.0.18

Platform Details

Windows 10 Pro Windows 7

Scenario:

Running the default recipe for chocolatey-cookbook results in an error on the powershell_script resource

Steps to Reproduce:

Chef Recipe

ms_dotnet_framework '4.5.2' do
  action            :install
  include_patches   true
  perform_reboot    true
end

include_recipe "chocolatey"

chocolatey "sysinternals"
chocolatey "notepadplusplus"
chocolatey "kdiff3"
chocolatey "GoogleChrome"
chocolatey "Console2"
chocolatey "virtualbox"
chocolatey "visualstudiocode"

Execution

Running with chef-client

chef-client --local-mode --override-runlist recipe[mycookbook::myrecipe]

Actual Result:

Powershell_script ArgumentError

ArgumentError
-------------
wrong number of arguments (given 0, expected 1)

Complete error stack

         * powershell_script[Install Chocolatey] action run

           ================================================================================
           Error executing action `run` on resource 'powershell_script[Install Chocolatey]'
           ================================================================================

           ArgumentError
           -------------
           wrong number of arguments (given 0, expected 1)

           Resource Declaration:
           ---------------------
           # In C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/cookbooks/chocolatey/recipes/default.rb

            35: powershell_script 'Install Chocolatey' do
            36:   environment node['chocolatey']['install_vars']
            37:   cwd Chef::Config['file_cache_path']
            38:   code install_ps1
            39:   not_if { chocolatey_installed? && (node['chocolatey']['upgrade'] == false) }
            40: end

           Compiled Resource:
           ------------------
           # Declared in C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/cookbooks/chocolatey/recipes/default.rb:35:in `from_file'

           powershell_script("Install Chocolatey") do
             action [:run]
             default_guard_interpreter :powershell_script
             command nil
             backup 5
             cwd "C:\\Users\\vagrant\\AppData\\Local\\Temp\\kitchen\\cache"
             environment {"chocolateyProxyLocation"=>nil, "chocolateyProxyUser"=>nil, "chocolateyProxyPassword"=>nil, "chocolateyVersion"=>nil, "chocolateyDownloadUrl"=>"https://chocolatey.org/api/v2/package/chocolatey", "chocolateyUseWindowsCompression"=>nil}
             returns 0
             user nil
             interpreter "powershell.exe"
             declared_type :powershell_script
             cookbook_name "chocolatey"
             recipe_name "default"
             code "C:\\Users\\vagrant\\AppData\\Local\\Temp\\kitchen\\cache/chocolatey-install.ps1"
             domain nil
             not_if { #code block }
           end

           System Info:
           ------------
           chef_version=13.0.118
           platform=windows
           platform_version=6.1.7600
           ruby=ruby 2.4.1p111 (2017-03-22 revision 58053) [x64-mingw32]
           program_name=C:/opscode/chef/bin/chef-client
           executable=C:/opscode/chef/bin/chef-client

       Running handlers:
       [2017-04-20T09:56:47-07:00] ERROR: Running exception handlers
       Running handlers complete
       [2017-04-20T09:56:47-07:00] ERROR: Exception handlers complete
       Chef Client failed. 48 resources updated in 29 minutes 02 seconds
       [2017-04-20T09:56:47-07:00] FATAL: Stacktrace dumped to C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/chef-stacktrace.out
       [2017-04-20T09:56:47-07:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2017-04-20T09:56:47-07:00] FATAL: ArgumentError: powershell_script[Install Chocolatey] (chocolatey::default line 35) had an error: ArgumentError: wrong number of arguments (given 0, expected 1)
mwrock commented 7 years ago

I have recently noticed this to on chef 13. I have not had a chance to dig so I'm not sure if it is a chef 13 bug or a chocolatey compatibility issue. We should definitely investigate but in the meantime you could use the last chef 12 release.

mwrock commented 7 years ago

Looks like this is definitely a bug in chef 13. It works for me on 2012R2 but not 2016. Any call to powershell_out! raises this error. I filed https://github.com/chef/chef/issues/6082 to track this.

mwrock commented 7 years ago

I was wrong and closed the chef issue. chef 13 defines a method env_path tha tconflicts with our helper.