Giter Site home page Giter Site logo

chef-boneyard / windows Goto Github PK

View Code? Open in Web Editor NEW
252.0 72.0 270.0 1.8 MB

Development repository for Chef Cookbook windows

Home Page: https://supermarket.chef.io/cookbooks/windows

License: Apache License 2.0

Ruby 100.00%
chef cookbook windows hacktoberfest

windows's Introduction

Windows Cookbook

Build status Cookbook Version

Provides a set of Windows-specific resources to aid in the creation of cookbooks/recipes targeting the Windows platform.

EOL Notice

This cookbook is no longer required for managing Windows nodes with Chef Infra. The necessary resources and helpers are now built into Chef Infra Client itself. These built-in resources are more feature rich and execute faster.

Requirements

Platforms

  • Windows 7 (EOL)
  • Windows Server 2008 R2 (EOL)
  • Windows 8, 8.1
  • Windows Server 2012 (R1, R2)
  • Windows Server 2016

Chef

  • Chef 14.7+

Resources

windows_certificate_binding

Binds a certificate to an HTTP port to enable TLS communication.

Actions

  • :create - creates or updates a binding.
  • :delete - deletes a binding.

Properties

  • cert_name - name attribute. The thumbprint(hash) or subject that identifies the certificate to be bound.
  • name_kind - indicates the type of cert_name. One of :subject (default) or :hash.
  • address - the address to bind against. Default is 0.0.0.0 (all IP addresses). One of:
    • IP v4 address 1.2.3.4
    • IP v6 address [::1]
    • Host name www.foo.com
  • port - the port to bind against. Default is 443.
  • app_id - the GUID that defines the application that owns the binding. Default is the values used by IIS.
  • store_name - the store to locate the certificate in. One of:
    • MY (Personal)
    • CA (Intermediate Certification Authorities)
    • ROOT (Trusted Root Certification Authorities)
    • TRUSTEDPUBLISHER (Trusted Publishers)
    • CLIENTAUTHISSUER (Client Authentication Issuers)
    • REMOTE DESKTOP (Remote Desktop)
    • TRUSTEDDEVICES (Trusted Devices)
    • WEBHOSTING (Web Hosting)
    • AUTHROOT (Third-Party Root Certification Authorities)
    • TRUSTEDPEOPLE (Trusted People)
    • SMARTCARDROOT (Smart Card Trusted Roots)
    • TRUST (Enterprise Trust)

Examples

# Bind the first certificate matching the subject to the default TLS port
windows_certificate_binding "me.acme.com" do
end
# Bind a cert from the CA store with the given hash to port 4334
windows_certificate_binding "me.acme.com" do
    cert_name    "d234567890a23f567c901e345bc8901d34567890"
    name_kind    :hash
    store_name    "CA"
    port        4334
end

windows_dns

Note: This resource is now included in Chef 15 and later. If you are using newer versions of windows then should use the core resource instead of windows_dns.

Configures A and CNAME records in Windows DNS. This requires the DNSCMD to be installed, which is done by adding the DNS role to the server or installing the Remote Server Admin Tools.

Actions

  • :create: creates/updates the DNS entry
  • :delete: deletes the DNS entry

Properties

  • host_name: name attribute. FQDN of the entry to act on.
  • dns_server: the DNS server to update. Default is local machine (.)
  • record_type: the type of record to create. One of A (default) or CNAME
  • target: for A records an array of IP addresses to associate with the host; for CNAME records the FQDN of the host to alias
  • ttl: if > 0 then set the time to live of the record

Examples

# Create A record linked to 2 addresses with a 10 minute ttl
windows_dns "m1.chef.test" do
    target         ['10.9.8.7', '1.2.3.4']
    ttl            600
end
# Delete records. target is mandatory although not used
windows_dns "m1.chef.test" do
    action    :delete
    target    []
end
# Set an alias against the node in a role
nodes = search( :node, "role:my_service" )
windows_dns "myservice.chef.test" do
    record_type    'CNAME'
    target        nodes[0]['fqdn']
end

windows_http_acl

Sets the Access Control List for an http URL to grant non-admin accounts permission to open HTTP endpoints.

Actions

  • :create - creates or updates the ACL for a URL.
  • :delete - deletes the ACL from a URL.

Properties

  • url - the name of the url to be created/deleted.
  • sddl - the DACL string configuring all permissions to URL. Mandatory for create if user is not provided. Can't be use with user.
  • user - the name (domain\user) of the user or group to be granted permission to the URL. Mandatory for create if sddl is not provided. Can't be use with sddl. Only one user or group can be granted permission so this replaces any previously defined entry. If you receive a parameter error your user may not exist.

Examples

windows_http_acl 'http://+:50051/' do
    user 'pc\\fred'
end
# Grant access to users "NT SERVICE\WinRM" and "NT SERVICE\Wecsvc" via sddl
windows_http_acl 'http://+:5985/' do
  sddl 'D:(A;;GX;;;S-1-5-80-569256582-2953403351-2909559716-1301513147-412116970)(A;;GX;;;S-1-5-80-4059739203-877974739-1245631912-527174227-2996563517)'
end
windows_http_acl 'http://+:50051/' do
    action :delete
end

windows_schannel

Used to configure the schannel security settings in windows, this is used by dotnet apps and PowerShell to be able to speak to tls 1.2 endpoints

Actions

  • configure: Configures the setting

Properties

property type default description
use_strong_crypto True, False true Enables or disables the setting

windows_user_privilege

Adds the principal (User/Group) to the specified privileges (such as Logon as a batch job or Logon as a Service).

Actions

  • :add - add the specified privileges to the principal
  • :remove - remove the specified privilege of the principal

Properties

  • principal - Name attribute, Required, String. The user or group to be granted privileges.
  • privilege - Required, String/Array. The privilege(s) to be granted.

Examples

Grant the Administrator user the Logon as a batch job and Logon as a service privilege.

windows_user_privilege 'Administrator' do
  privilege %w(SeBatchLogonRight SeServiceLogonRight)
end

Remove Logon as a batch job privilege of Administrator.

windows_user_privilege 'Administrator' do
  privilege %w(SeBatchLogonRight)
  action :remove
end

Available Privileges

SeTrustedCredManAccessPrivilege      Access Credential Manager as a trusted caller
SeNetworkLogonRight                  Access this computer from the network
SeTcbPrivilege                       Act as part of the operating system
SeMachineAccountPrivilege            Add workstations to domain
SeIncreaseQuotaPrivilege             Adjust memory quotas for a process
SeInteractiveLogonRight              Allow log on locally
SeRemoteInteractiveLogonRight        Allow log on through Remote Desktop Services
SeBackupPrivilege                    Back up files and directories
SeChangeNotifyPrivilege              Bypass traverse checking
SeSystemtimePrivilege                Change the system time
SeTimeZonePrivilege                  Change the time zone
SeCreatePagefilePrivilege            Create a pagefile
SeCreateTokenPrivilege               Create a token object
SeCreateGlobalPrivilege              Create global objects
SeCreatePermanentPrivilege           Create permanent shared objects
SeCreateSymbolicLinkPrivilege        Create symbolic links
SeDebugPrivilege                     Debug programs
SeDenyNetworkLogonRight              Deny access this computer from the network
SeDenyBatchLogonRight                Deny log on as a batch job
SeDenyServiceLogonRight              Deny log on as a service
SeDenyInteractiveLogonRight          Deny log on locally
SeDenyRemoteInteractiveLogonRight    Deny log on through Remote Desktop Services
SeEnableDelegationPrivilege          Enable computer and user accounts to be trusted for delegation
SeRemoteShutdownPrivilege            Force shutdown from a remote system
SeAuditPrivilege                     Generate security audits
SeImpersonatePrivilege               Impersonate a client after authentication
SeIncreaseWorkingSetPrivilege        Increase a process working set
SeIncreaseBasePriorityPrivilege      Increase scheduling priority
SeLoadDriverPrivilege                Load and unload device drivers
SeLockMemoryPrivilege                Lock pages in memory
SeBatchLogonRight                    Log on as a batch job
SeServiceLogonRight                  Log on as a service
SeSecurityPrivilege                  Manage auditing and security log
SeRelabelPrivilege                   Modify an object label
SeSystemEnvironmentPrivilege         Modify firmware environment values
SeManageVolumePrivilege              Perform volume maintenance tasks
SeProfileSingleProcessPrivilege      Profile single process
SeSystemProfilePrivilege             Profile system performance
SeUnsolicitedInputPrivilege          "Read unsolicited input from a terminal device"
SeUndockPrivilege                    Remove computer from docking station
SeAssignPrimaryTokenPrivilege        Replace a process level token
SeRestorePrivilege                   Restore files and directories
SeShutdownPrivilege                  Shut down the system
SeSyncAgentPrivilege                 Synchronize directory service data
SeTakeOwnershipPrivilege             Take ownership of files or other objects

windows_zipfile

Note: This resource has been deprecated as Chef Infra Client 15.0 shipped with a new archive_file resource, which natively handles multiple archive formats. Please update any cookbooks using this resource to instead use the archive_file resource: https://docs.chef.io/resource_archive_file.html

Most versions of Windows do not ship with native cli utility for managing compressed files. This resource provides a pure-ruby implementation for managing zip files. Be sure to use the not_if or only_if meta parameters to guard the resource for idempotence or action will be taken every Chef run.

Actions

  • :unzip - unzip a compressed file
  • :zip - zip a directory (recursively)

Properties

  • path - name attribute. The path where files will be (un)zipped to.
  • source - source of the zip file (either a URI or local path) for :unzip, or directory to be zipped for :zip.
  • overwrite - force an overwrite of the files if they already exist.
  • checksum - for :unzip, useful if source is remote, if the local file matches the SHA-256 checksum, Chef will not download it.

Examples

Unzip a remote zip file locally

windows_zipfile 'c:/bin' do
  source 'http://download.sysinternals.com/Files/SysinternalsSuite.zip'
  action :unzip
  not_if {::File.exists?('c:/bin/PsExec.exe')}
end

Unzip a local zipfile

windows_zipfile 'c:/the_codez' do
  source 'c:/foo/baz/the_codez.zip'
  action :unzip
end

Create a local zipfile

windows_zipfile 'c:/foo/baz/the_codez.zip' do
  source 'c:/the_codez'
  action :zip
end

Libraries

WindowsHelper

Helper that allows you to use helpful functions in windows

installed_packages

Returns a hash of all DisplayNames installed

# usage in a recipe
::Chef::DSL::Recipe.send(:include, Windows::Helper)
hash_of_installed_packages = installed_packages

is_package_installed?

  • package_name - The name of the package you want to query to see if it is installed
  • returns - true if the package is installed, false if it the package is not installed

Download a file if a package isn't installed

# usage in a recipe to not download a file if package is already installed
::Chef::DSL::Recipe.send(:include, Windows::Helper)
is_win_sdk_installed = is_package_installed?('Windows Software Development Kit')

remote_file 'C:\windows\temp\windows_sdk.zip' do
  source 'http://url_to_download/windows_sdk.zip'
  action :create_if_missing
  not_if {is_win_sdk_installed}
end

Do something if a package is installed

# usage in a provider
include Windows::Helper
if is_package_installed?('Windows Software Development Kit')
  # do something if package is installed
end

Windows::VersionHelper

Helper that allows you to get information on the windows version running on your node. It leverages windows ohai from kernel.os_info, easy to mock and to use even on Linux.

core_version?

Determines whether the given node is running on a Windows Core.

if ::Windows::VersionHelper.core_version? node
  fail 'Windows Core is not supported'
end

workstation_version?

Determines whether the given node is a windows workstation version (XP, Vista, 7, 8, 8.1, 10)

if ::Windows::VersionHelper.workstation_version? node
  fail 'Only server version of windows are supported'
end

server_version?

Determines whether the given node is a windows server version (Server 2003, Server 2008, Server 2012, Server 2016)

if ::Windows::VersionHelper.server_version? node
  puts 'Server version of windows are cool'
end

nt_version

Determines NT version of the given node

case ::Windows::VersionHelper.nt_version node
  when '6.0' then 'Windows vista or Server 2008'
  when '6.1' then 'Windows 7 or Server 2008R2'
  when '6.2' then 'Windows 8 or Server 2012'
  when '6.3' then 'Windows 8.1 or Server 2012R2'
  when '10.0' then 'Windows 10'
end

Usage

Place an explicit dependency on this cookbook (using depends in the cookbook's metadata.rb) from any cookbook where you would like to use the Windows-specific resources/providers that ship with this cookbook.

depends 'windows'

License & Authors

Copyright 2011-2018, Chef Software, Inc.
Copyright 2010, VMware, Inc.
Copyright 2011, Business Intelligence Associates, Inc
Copyright 2012, Nordstrom, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

windows's People

Contributors

alexpop avatar annih avatar axos88 avatar btm avatar easyasabc123 avatar iennae avatar jakauppila avatar jaym avatar joelhandwell avatar joemillerr avatar juliandunn avatar lambacck avatar lamont-granquist avatar mattstratton avatar mwrock avatar petewest avatar piyushawasthi avatar pmorton avatar prajaktapurohit avatar rlaveycal avatar ruicovelo avatar schisamo avatar sethvargo avatar shoekstra avatar smurawski avatar sneal avatar spuder avatar tas50 avatar xorima avatar xorimabot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

windows's Issues

commands on path are not available after running windows_path

Chef: 11.14.6
Windows Cookbook: 1.34.2
Node : Windows 2012
Iโ€™ve encountered a scenario where after the windows_path resource is ran in a Chef run, other resources can't find items currently on the Windows path. For example the batch resource fails with โ€œSTDERR: โ€˜cmd.exeโ€™ is not recognized as an internal or external command.โ€ If you donโ€™t have the windows_path resource in your recipe or if you run the recipe again, the batch resource can find the cmd command on the path.

Undefined method `checksum' for Chef::Resource::WindowsPackage after v1.32.0

After upgrading to the latest release v1.32.0 my provision fails for the sql_server cookbook but it appears to be based on a change in windows. (reverting to 1.31.0 makes the provision work without a problem)

The main error seems to be:

undefined method `checksum' for Chef::Resource::WindowsPackage

This is on OS X with a Windows 2008R2 guest and using berkshelf/vagrant-berkshelf.

Below is my stack trace. Let me know if this should be opened as an issue in the sql_server cookbook instead.

$ vagrant provision
Updating Vagrant's berkshelf: '/Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default'
Resolving cookbook dependencies...
Using apt (2.4.0)
Using aws (2.3.0)
Using build-essential (2.0.4)
Using chef-sugar (2.0.0)
Using chef_handler (1.1.6)
Using database (2.2.0)
Using hostsfile (2.4.4)
Using iis (2.1.2)
Using initial-setup (1.3.6) from [email protected]:user/chef-recipes/chef-recipes.git (at master/cookbooks/initial-setup)
Using mysql (5.3.6)
Using mysql-chef_gem (0.0.2)
Using openssl (2.0.0)
Using postgresql (3.4.1)
Using sql_server (2.2.0)
Using windows (1.32.0)
Using windows_ad (0.2.0)
Using xfs (1.1.0)
Using yum (3.2.2)
Using yum-mysql-community (0.1.8)
Vendoring apt (2.4.0) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/apt
Vendoring aws (2.3.0) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/aws
Vendoring build-essential (2.0.4) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/build-essential
Vendoring chef-sugar (2.0.0) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/chef-sugar
Vendoring chef_handler (1.1.6) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/chef_handler
Vendoring database (2.2.0) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/database
Vendoring hostsfile (2.4.4) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/hostsfile
Vendoring iis (2.1.2) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/iis
Vendoring initial-setup (1.3.6) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/initial-setup
Vendoring mysql (5.3.6) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/mysql
Vendoring mysql-chef_gem (0.0.2) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/mysql-chef_gem
Vendoring openssl (2.0.0) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/openssl
Vendoring postgresql (3.4.1) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/postgresql
Vendoring sql_server (2.2.0) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/sql_server
Vendoring windows (1.32.0) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/windows
Vendoring windows_ad (0.2.0) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/windows_ad
Vendoring xfs (1.1.0) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/xfs
Vendoring yum (3.2.2) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/yum
Vendoring yum-mysql-community (0.1.8) to /Users/user/.berkshelf/default/vagrant/berkshelf-20140712-6749-1d9m7sr-default/yum-mysql-community
==> default: Running provisioner: chef_solo...
Generating chef JSON and uploading...
==> default: Running chef-solo...
==> default: [2014-07-13T01:46:50+10:00] WARN:
==> default: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
==> default: SSL validation of HTTPS requests is disabled. HTTPS connections are still
==> default: encrypted, but chef is not able to detect forged replies or man in the middle
==> default: attacks.
==> default:
==> default: To fix this issue add an entry like this to your configuration file:
==> default:
==> default: ==> default: # Verify all HTTPS connections (recommended) ==> default: ssl_verify_mode :verify_peer ==> default: ==> default: # OR, Verify only connections to chef-server ==> default: verify_api_cert true ==> default:
==> default:
==> default: To check your SSL configuration, or troubleshoot errors, you can use the
==> default: knife ssl check command like so:
==> default:
==> default: ==> default: knife ssl check -c c:\tmp\vagrant-chef-3\solo.rb ==> default:
==> default:
==> default: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
==> default:
==> default: [2014-07-13T01:46:52+10:00] INFO: *** Chef 11.12.8 ***
==> default: [2014-07-13T01:46:52+10:00] INFO: Chef-client pid: 2736
==> default: [2014-07-13T01:48:06+10:00] INFO: Setting the run_list to ["recipe[initial-setup::hosts]", "recipe[initial-setup::iis]", "recipe[initial-setup::sqlsrv]", "recipe[initial-setup::php_ini]", "recipe[initial-setup::nssm_service]"] from CLI options
==> default:
==> default: [2014-07-13T01:48:06+10:00] INFO: Run List is [recipe[initial-setup::hosts], recipe[initial-setup::iis], recipe[initial-setup::sqlsrv], recipe[initial-setup::php_ini], recipe[initial-setup::nssm_service]]
==> default: [2014-07-13T01:48:06+10:00] INFO: Run List expands to [initial-setup::hosts, initial-setup::iis, initial-setup::sqlsrv, initial-setup::php_ini, initial-setup::nssm_service]
==> default: [2014-07-13T01:48:06+10:00] INFO: Starting Chef Run for WIN-9DD123V48QV
==> default: [2014-07-13T01:48:06+10:00] INFO: Running start handlers
==> default: [2014-07-13T01:48:06+10:00] INFO: Start handlers complete.
==> default: ================================================================================
==> default: Recipe Compile Error in C:/tmp/vagrant-chef-3/chef-solo-1/cookbooks/initial-setup/recipes/sqlsrv.rb
==> default: ================================================================================
==> default:
==> default: NoMethodError
==> default: -------------
==> default: undefined method checksum' for Chef::Resource::WindowsPackage ==> default: ==> default: Cookbook Trace: ==> default: --------------- ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/resource.rb:298:inmethod_missing'
==> default: C:/tmp/vagrant-chef-3/chef-solo-1/cookbooks/sql_server/recipes/client.rb:28:in block (2 levels) in from_file' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/dsl/recipe.rb:123:ininstance_eval'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/dsl/recipe.rb:123:in build_resource' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/dsl/recipe.rb:86:indeclare_resource'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/dsl/recipe.rb:42:in method_missing' ==> default: C:/tmp/vagrant-chef-3/chef-solo-1/cookbooks/sql_server/recipes/client.rb:26:inblock in from_file'
==> default: C:/tmp/vagrant-chef-3/chef-solo-1/cookbooks/sql_server/recipes/client.rb:24:in each' ==> default: C:/tmp/vagrant-chef-3/chef-solo-1/cookbooks/sql_server/recipes/client.rb:24:infrom_file'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/mixin/from_file.rb:30:in instance_eval' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/mixin/from_file.rb:30:infrom_file'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/cookbook_version.rb:237:in load_recipe' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/run_context.rb:165:inload_recipe'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/run_context.rb:134:in block in include_recipe' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/run_context.rb:133:ineach'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/run_context.rb:133:in include_recipe' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/dsl/include_recipe.rb:26:ininclude_recipe'
==> default: C:/tmp/vagrant-chef-3/chef-solo-1/cookbooks/initial-setup/recipes/sqlsrv.rb:12:in from_file' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/mixin/from_file.rb:30:ininstance_eval'
==> default:
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/mixin/from_file.rb:30:in from_file' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/cookbook_version.rb:237:inload_recipe'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/run_context.rb:165:in load_recipe' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/run_context/cookbook_compiler.rb:140:inblock in compile_recipes'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/run_context/cookbook_compiler.rb:138:in each' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/run_context/cookbook_compiler.rb:138:incompile_recipes'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/run_context/cookbook_compiler.rb:75:in compile' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/run_context.rb:88:inload'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/policy_builder/expand_node_object.rb:73:in setup_run_context' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/client.rb:265:insetup_run_context'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/client.rb:429:in do_run' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/client.rb:227:inrun'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/application.rb:217:in run_chef_client' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/application/solo.rb:221:inblock in run_application'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/application/solo.rb:213:in loop' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/application/solo.rb:213:inrun_application'
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/application.rb:67:in run' ==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/bin/chef-solo:25:in<top (required)>'
==> default: C:/opscode/chef/bin/chef-solo:23:in load' ==> default: C:/opscode/chef/bin/chef-solo:23:in

'
==> default:
==> default: Relevant File Content:
==> default: ----------------------
==> default: C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8-x86-mingw32/lib/chef/resource.rb:
==> default:
==> default: 291: # If an unknown method is invoked, determine whether the enclosing Provider's
==> default: 292: # lexical scope can fulfill the request. E.g. This happens when the Resource's
==> default: 293: # block invokes new_resource.
==> default: 294: def method_missing(method_symbol, *args, &block)
==> default: 295: if enclosing_provider && enclosing_provider.respond_to?(method_symbol)
==> default: 296: enclosing_provider.send(method_symbol, *args, &block)
==> default: 297: else
==> default: 298>> raise NoMethodError, "undefined method #{method_symbol.to_s}' for #{self.class.to_s}" ==> default: 299: end ==> default: 300: end ==> default: 301: ==> default: 302: def load_prior_resource ==> default: 303: begin ==> default: 304: prior_resource = run_context.resource_collection.lookup(self.to_s) ==> default: 305: # if we get here, there is a prior resource (otherwise we'd have jumped ==> default: 306: # to the rescue clause). ==> default: 307: Chef::Log.warn("Cloning resource attributes for #{self.to_s} from prior resource (CHEF-3694)") ==> default: ==> default: [2014-07-13T01:48:22+10:00] ERROR: Running exception handlers ==> default: [2014-07-13T01:48:22+10:00] ERROR: Exception handlers complete ==> default: [2014-07-13T01:48:22+10:00] FATAL: Stacktrace dumped to C:/var/chef/cache/chef-stacktrace.out ==> default: [2014-07-13T01:48:22+10:00] FATAL: NoMethodError: undefined methodchecksum' for Chef::Resource::WindowsPackage
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

Remove action doesn't work in some cases

Example Uninstall string in registry:

"C:\ProgramData\Package Cache\{983dbe6a-0ba2-4e3c-9228-213eb66281fb}\Setup.exe"  /uninstall

That results in construction of following uninstall_string:

cmd /c start "" /wait /d"C:\ProgramData\Package Cache\{983dbe6a-0ba2-4e3c-9228-213eb66281fb}\Setup.exe " uninstall /S

which of course doesn't work.

What was the reason of processing uninstall string with gsub, taking basename, etc ?

Uninstall in registry should give full command for uninstallation, so no postprocessing should be done.
Monkey patch I'm using

class Chef::Provider::WindowsPackage
    def remove_package(name, version)
        uninstall_string = installed_packages[@new_resource.package_name][:uninstall_string]
        Chef::Log.info("Registry provided uninstall string for #{@new_resource} is '#{uninstall_string}'")
        uninstall_command = begin
            if uninstall_string =~ /msiexec/i
              "#{uninstall_string} /qn"
            else
              "start \"\" /wait #{uninstall_string} #{expand_options(@new_resource.options)}"
            end
        end
        Chef::Log.info("Removing #{@new_resource} with uninstall command '#{uninstall_command}'")
        shell_out!(uninstall_command, {:returns => @new_resource.success_codes})
    end
end

undefined method `step_into?' for nil:NilClass - v1.34.0

I upgraded to the latest version (1.34.0) to correct the ruby-wmi dependency error and although that issue is corrected, I now encounter the above error when executing my chefspec tests. Please find an excerpt of the error encountered below;

NoMethodError
chefspec             | -------------
chefspec             | undefined method `step_into?' for nil:NilClass
chefspec             | Cookbook Trace:
chefspec             | ---------------
chefspec             | /tmp/d20140805-20520-1d9qqxd/cookbooks/windows/libraries/wmi-lite-gem.rb:33:in `rescue in <top (required)>'
chefspec             | /tmp/d20140805-20520-1d9qqxd/cookbooks/windows/libraries/wmi-lite-gem.rb:25:in `<top (required)>'
chefspec             | Relevant File Content:
chefspec             | ----------------------
chefspec             | /tmp/d20140805-20520-1d9qqxd/cookbooks/windows/libraries/wmi-lite-gem.rb:
chefspec             | 26:    require 'wmi-lite'
chefspec             | 27:  rescue LoadError
chefspec             | 28:    empty_node = Chef::Node.new
chefspec             | 29:    empty_events = Chef::EventDispatch::Dispatcher.new
chefspec             | 30:    run_context = Chef::RunContext.new(empty_node, {}, empty_events)
chefspec             | 31:
chefspec             | 32:    wmi_gem = Chef::Resource::ChefGem.new('wmi-lite', run_context)
chefspec             | 33>>   wmi_gem.run_action(:install)
chefspec             | 34:
chefspec             | 35:    require 'wmi-lite'
chefspec             | 36:  end

Updated to 1.36.0, compile error now

Hi, my cookbooks have a transitive dependency to this one. Looks like what was just updated is causing some problems:

constant Chef::Resource::WindowsPackage not defined

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/windows/libraries/windows_package.rb:

257:          @provider = Chef::Provider::WindowsCookbookPackage
258:        end
259:      end
260:    end
261:  end
262:
263:  if Gem::Version.new(Chef::VERSION) < Gem::Version.new('12')
264>>   Chef::Resource.send(:remove_const, :WindowsPackage)
265:    Chef::Resource.const_set("WindowsPackage", Chef::Resource::WindowsCookbookPackage)
266:  end

I am not running chef 12.

install_windows_feature matcher throwing "TypeError: no implicit conversion of nil into String"

I'm tying to use ChefSpec to test a cookbook that uses the windows_feature provider.
However, I'm always getting a "TypeError: no implicit conversion of nil into String" exception.

I've created an example cookbook that shows the issue, here https://github.com/miguelaferreira/chefspec_windows_tests

My recipe looks like this:

windows_feature 'NET-Framework-Core' do
  all true
  provider Chef::Provider::WindowsFeaturePowershell
  action :install
end

My spec looks like this:

describe 'chefspec_windows_tests::default' do
  let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'windows', version: '2012R2').converge(described_recipe) }

  it 'installs a windows feature' do
    expect(chef_run).to install_windows_feature('NET-Framework-Core')
  end
end

And the output of rspec looks like this:

================================================================================
Recipe Compile Error in /var/folders/sm/tcsqvyfd7hvcw__25f6t7_016l9l6z/T/d20141216-4140-8ewh8o/cookbooks/chefspec_windows_tests/recipes/default.rb
================================================================================

TypeError
---------
no implicit conversion of nil into String

Cookbook Trace:
---------------
  /var/folders/sm/tcsqvyfd7hvcw__25f6t7_016l9l6z/T/d20141216-4140-8ewh8o/cookbooks/windows/resources/feature.rb:32:in `initialize'
  /var/folders/sm/tcsqvyfd7hvcw__25f6t7_016l9l6z/T/d20141216-4140-8ewh8o/cookbooks/chefspec_windows_tests/recipes/default.rb:10:in `from_file'

Relevant File Content:
----------------------
/var/folders/sm/tcsqvyfd7hvcw__25f6t7_016l9l6z/T/d20141216-4140-8ewh8o/cookbooks/windows/resources/feature.rb:

 25:  attribute :feature_name, :kind_of => String, :name_attribute => true
 26:  attribute :source, :kind_of => String
 27:  attribute :all, :kind_of => [ TrueClass, FalseClass ], :default => false
 28:  
 29:  def initialize(name, run_context=nil)
 30:    super
 31:    @action = :install
 32>>   @provider = lookup_provider_constant(locate_default_provider)
 33:  end
 34:  
 35:  private
 36:  def locate_default_provider
 37:    if  node['windows'].attribute?(:feature_provider)
 38:      "windows_feature_#{node['windows']['feature_provider']}"
 39:    elsif ::File.exists?(locate_sysnative_cmd('dism.exe'))
 40:      :windows_feature_dism
 41:    elsif ::File.exists?(locate_sysnative_cmd('servermanagercmd.exe'))

F

Failures:

  1) chefspec_windows_tests::default installs a windows feature
     Failure/Error: let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'windows', version: '2012R2').converge(described_recipe) }
     TypeError:
       no implicit conversion of nil into String
     # /var/folders/sm/tcsqvyfd7hvcw__25f6t7_016l9l6z/T/d20141216-4140-8ewh8o/cookbooks/windows/resources/feature.rb:32:in `initialize'
     # /var/folders/sm/tcsqvyfd7hvcw__25f6t7_016l9l6z/T/d20141216-4140-8ewh8o/cookbooks/chefspec_windows_tests/recipes/default.rb:10:in `from_file'
     # ./spec/default_spec.rb:5:in `block (2 levels) in <top (required)>'
     # ./spec/default_spec.rb:8:in `block (2 levels) in <top (required)>'

Finished in 0.76679 seconds (files took 2.04 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/default_spec.rb:7 # chefspec_windows_tests::default installs a windows feature

I'm using ChefDK 0.3.5

windows_task isn't idempotent

I observed this running chef-zero; I will try to reproduce it using chef-client.

Changing the command attribute in a recipe did not result in the task being updated.

powershell_out use 32-bit powershell on x64 node

Hi,

Recently I encountered some weird errors with my powershell scripts and I finally discovered that powershell_out just run powershell [flags] [script].
At first look, it seems correct... but because currently chef is running with a 32-bit ruby this is wrong!

I found out that the module Powerhell::Helper has an interpreter function doing what we need :)

1.32 features disappeared

It seems that the features added in 1.32 are not in master or 1.34. Apparently they got lost in 2aa2981. Seems like a merge accident.

Chef 11.14.2 breaks due to ruby-wmi dependency

Just a heads up, if you start using Chef 11.14.2 with this cookbook (as I am while using the latest Chef Omnibus installer via vagrant), it breaks on the ruby-wmi dependencies.

One of the notes on Chef 11.14.2 here is that the ruby-wmi gem was replaced with the wmi-lite gem. Is that something you guys plan to also do in the windows cookbook?

vm_hostname is set to false in test-kitchen config

sometimes windows images wouldn't come up with an error around setting the hostname, so we set vm_hostname to false. Apparently this is now setting the hostname to false. According to the Vagrant Docs we may want to set that to nil to avoid setting the hostname, but ideally we fix the error.

Best theory right now is vagrant is breaking with long host name. We should figure it out and get it fixed in vagrant.

It looks like currently there's a reboot involved:
https://github.com/mitchellh/vagrant/blob/master/plugins/guests/windows/cap/change_host_name.rb#L10

Vagrant tried to remove the reboot in hashicorp/vagrant#4693 but it caused problems and it was reverted in hashicorp/vagrant#5240.

/cc @cmluciano

Gemfile not found error

Hi,

I am getting below error when processing chef_gem[wmi-lite] action install (dynamically defined) using windows (1.34.0)

Recipe Compile Error in /var/lib/aws/opsworks/cache/cookbooks/windows/libraries/wmi-lite-gem.rb

Bundler::GemfileNotFound

chef_gem[wmi-lite](dynamically defined) had an error: Bundler::GemfileNotFound: Could not locate Gemfile

Cookbook Trace:

/var/lib/aws/opsworks/cache/cookbooks/windows/libraries/wmi-lite-gem.rb:33:in rescue in <top (required)>' /var/lib/aws/opsworks/cache/cookbooks/windows/libraries/wmi-lite-gem.rb:25:in<top (required)>'

Relevant File Content:

/var/lib/aws/opsworks/cache/cookbooks/windows/libraries/wmi-lite-gem.rb:

26: require 'wmi-lite'
27: rescue LoadError
28: empty_node = Chef::Node.new
29: empty_events = Chef::EventDispatch::Dispatcher.new
30: run_context = Chef::RunContext.new(empty_node, {}, empty_events)
31:
32: wmi_gem = Chef::Resource::ChefGem.new('wmi-lite', run_context)
33>> wmi_gem.run_action(:install)
34:
35: require 'wmi-lite'
36: end
37:

Please look in to this

Thanks
Abhijit

windows_auto_run complains that registry_key should be used.

When using windows_auto_run it complains:

WARN: Please use the registry_key resource in Chef Client 11. The windows_registry LWRP is still supported for Chef Client 10, but is deprecated in future versions.

I don't know if it is related (yet) but it also doesn't seem to be working for me... but I'm still researching that.

Undefined method "compile_time" Chef 12.0.3

I am trying to run a Berkshelf cookbook which requires the windows cookbook to be ran first.

However when it runs the follow error is displayed

Undefined method "compile_time"

Note I am running this on a Windows Server 2012 R2 box.

Any ideas?

Remove action with some MSI does not work

Hi,

Many MSIs contains a "MSIExec /qn /i"{...}" as UninstallString key in the windows registry. (see http://stackoverflow.com/questions/10280952/uninstallstring-being-set-with-i-not-x-param)

The reason for this is that modyfiable packages use to put /i in order to make the user chose between install/repair or remove package.

Consequently remove action do not have any effect when called in a non-interactive way.

What about calling 'wmic package where name="PACKAGE_NAME" call uninstall' instead ?

This command works well and do not need to fetch the program guid from the registry.

Bests

windows_package implementation does not use resource name as source attribute

When using the windows_package resource implementation in windows cookbook, the source attributed MUST explicitly be specified. Otherwise, users get the error below. However, according to https://docs.chef.io/resource_windows_package.html, the source attribute is optional, and should default to the resource name.

============================================================================

Error executing action `install` on resource 'windows_package[c:\windows\tem

p\chef-client\DbBuilder-0.0.0051-339.msi]'

============================================================================

Chef::Exceptions::ValidationFailed
----------------------------------
Required argument source is missing!

Cookbook Trace:
---------------
c:/chef/cache/cookbooks/windows/libraries/windows_package.rb:106:in `install

_package'
c:/chef/cache/cookbooks/windows/libraries/windows_package.rb:31:in `block in
class:WindowsCookbookPackage'

Resource Declaration:
---------------------
# In c:/chef/cache/cookbooks/db-mssql/recipes/install_dbbuilder.rb

 26: windows_package "#{win_pkg}" do
 27:   action :install
 28:   installer_type :msi
29:   options "quiet"
 30: end
 31:

Compiled Resource:
------------------
# Declared in c:/chef/cache/cookbooks/db-mssql/recipes/install_dbbuilder.rb:

26:in `from_file'

windows_cookbook_package("c:\windows\temp\chef-client\DbBuilder-0.0.0051-339

.msi") do
provider Chef::Provider::WindowsCookbookPackage
action [:install]
retries 0
retry_delay 2
default_guard_interpreter :default
declared_type :windows_package
cookbook_name "db-mssql"
recipe_name "install_dbbuilder"
installer_type :msi
options "quiet"
package_name "c:\windows\temp\chef-client\DbBuilder-0.0.0051-339.msi"
end

[2015-02-22T20:22:24-05:00] INFO: Running queued delayed notifications before re
-raising exception

Running handlers:
[2015-02-22T20:22:24-05:00] ERROR: Running exception handlers
Running handlers complete
[2015-02-22T20:22:24-05:00] ERROR: Exception handlers complete
[2015-02-22T20:22:24-05:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stack
trace.out
Chef Client failed. 14 resources updated in 37.360134 seconds
[2015-02-22T20:22:24-05:00] INFO: Sending resource update report (run-id: 10c432
fa-7efa-49de-8248-e91238e1a0a8)
[2015-02-22T20:22:24-05:00] FATAL: Chef::Exceptions::ValidationFailed: windows_p
ackage[c:\windows\temp\chef-client\DbBuilder-0.0.0051-339.msi](db-mssql::instal
l_dbbuilder line 26) had an error: Chef::Exceptions::ValidationFailed: Required
argument source is missing!

From: Fouts, Chris [mailto:[email protected]]
Sent: Sunday, February 22, 2015 8:28 PM
To: [email protected]
Subject: [chef] Please help with windows_package exception

If I install the *.msi manually, it installs. When installing it via windows_package resource, I get an exception. I canโ€™t find what Chef means by โ€œRequired argument source is missing!โ€

==========================================================================

Error executing action `install` on resource 'windows_package[c:\windows\t

p\chef-client\DbBuilder-0.0.0051-339.msi]'

==========================================================================

Chef::Exceptions::ValidationFailed
----------------------------------
Required argument source is missing!

Cookbook Trace:
---------------
c:/chef/cache/cookbooks/windows/libraries/windows_package.rb:106:in `insta

_package'
c:/chef/cache/cookbooks/windows/libraries/windows_package.rb:31:in `block
class:WindowsCookbookPackage'

Resource Declaration:
---------------------
# In c:/chef/cache/cookbooks/db-mssql/recipes/install_dbbuilder.rb

 26: windows_package "#{win_pkg}" do
 27:   action :install
 28:   installer_type :msi
 29:   options "quiet"
 30: end
 31:

Compiled Resource:
------------------
# Declared in c:/chef/cache/cookbooks/db-mssql/recipes/install_dbbuilder.r

26:in `from_file'

windows_cookbook_package("c:\windows\temp\chef-client\DbBuilder-0.0.0051-3

.msi") do
provider Chef::Provider::WindowsCookbookPackage
action [:install]
retries 0
retry_delay 2
default_guard_interpreter :default
declared_type :windows_package
cookbook_name "db-mssql"
recipe_name "install_dbbuilder"
installer_type :msi
options "quiet"
package_name "c:\windows\temp\chef-client\DbBuilder-0.0.0051-339.msi
end

[2015-02-22T20:22:24-05:00] INFO: Running queued delayed notifications before
-raising exception
[2015-02-22T20:22:24-05:00] INFO: Running queued delayed notifications before re
-raising exception

Running handlers:
[2015-02-22T20:22:24-05:00] ERROR: Running exception handlers
Running handlers complete
[2015-02-22T20:22:24-05:00] ERROR: Exception handlers complete
[2015-02-22T20:22:24-05:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stack
trace.out
Chef Client failed. 14 resources updated in 37.360134 seconds
[2015-02-22T20:22:24-05:00] INFO: Sending resource update report (run-id: 10c432
fa-7efa-49de-8248-e91238e1a0a8)
[2015-02-22T20:22:24-05:00] FATAL: Chef::Exceptions::ValidationFailed: windows_p
ackage[c:\windows\temp\chef-client\DbBuilder-0.0.0051-339.msi](db-mssql::instal
l_dbbuilder line 26) had an error: Chef::Exceptions::ValidationFailed: Required
argument source is missing!

ruby_block[fix ruby ENV['PATH']] had an error: RuntimeError: can't modify frozen String

I was executing recipe[sql_server::client] which depends on windows cookbook, then this happens. not sure what went wrong. using chefdk 0.3.1

RuntimeError: windows_path[C:\Program Files\Microsoft SQL Server\100\Tools\Binn;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files (x86)\OpenSSH\bin;C:\Program Files (x86)\OpenSSL\bin;%systemroot%\System32\WindowsPowerShell\v1.0;c:\opscode\chefdk\bin;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\Redist] (sql_server::client line 37) had an error: RuntimeError: ruby_block[fix ruby ENV['PATH']](C:/Users/Administrator/.chef/local-mode-cache/cache/cookbooks/windows/providers/path.rb line 38) had an error: RuntimeError: can't modify frozen String

C:/opscode/chefdk/embedded/lib/ruby/2.0.0/Win32API.rb:23:in pack' C:/opscode/chefdk/embedded/lib/ruby/2.0.0/Win32API.rb:23:inblock in call'
C:/opscode/chefdk/embedded/lib/ruby/2.0.0/Win32API.rb:22:in each' C:/opscode/chefdk/embedded/lib/ruby/2.0.0/Win32API.rb:22:ineach_with_index'
C:/opscode/chefdk/embedded/lib/ruby/2.0.0/Win32API.rb:22:in call' C:/Users/Administrator/.chef/local-mode-cache/cache/cookbooks/windows/libraries/windows_helper.rb:93:inexpand_env_vars'
C:/opscode/chefdk/embedded/apps/chef/lib/chef/resource.rb:298:in method_missing' C:/Users/Administrator/.chef/local-mode-cache/cache/cookbooks/windows/providers/path.rb:40:inblock (3 levels) in class_from_file'

windows_task doesn't work at all on non-english windows

Hello!

This is output of schtasks /Query /FO LIST /V /TN "burp cron":

Folder:
Nazwa hosta: VAGRANT-BOX
Nazwa zadania: \burp cron
Czas nast. uruchomienia: 2015-02-12 16:00:00
Stan: Gotowe
Tryb logowania: Interakcyjne/W tle
Czas ostat. uruchomienia: 2015-02-12 15:40:00
Ostatni wynik: 0
Autor: vagrant
Zadanie do uruchomienia: "C:\Program Files\Burp\bin\burp.exe" -a t
Rozpocznij w: Brak
Komentarz: Brak
Stan zaplanowanego zadania: Wล‚ฤ…czony
Czas bezczynnoล›ci: Wyล‚ฤ…czony
Zarzฤ…dzanie energiฤ…: Zatrzymaj w trybie zasilania bateryjnego, Nie uruchamiaj w trybie zasilania bateryjnego
Uruchom jako uลผytkownik: SYSTEM
Usuล„ zadanie, jeล›li nie jest ponownie zaplanowane: Wล‚ฤ…czony
Zatrzymaj zadanie, jeล›li dziaล‚a X godzin i X minut: 72:00:00
Harmonogram: Dane planowania nie sฤ… dostฤ™pne w tym formacie.
Zaplanowany typ: Tylko raz, Co minutฤ™
Godzina rozpoczฤ™cia: 17:00:00
Data rozpoczฤ™cia: 2015-02-11
Data zakoล„czenia: Brak
dni: Brak
miesiฤ™cy: Brak
Powtรณrz: co: 0 godz., 20 min
Powtรณrz do: godzina: Brak
Powtรณrz do: czas trwania: Wyล‚ฤ…czony
Powtรณrz: zatrzymaj, jeล›li wciฤ…ลผ uruchomione: Wyล‚ฤ…czony

So, there is no chance that task.rb provider will guess valid name. Efect - I get error, that task cannot be created, and even I see question, if I want to override (I cannot answer, but it's there).

I suspect this will be problem on any windows with language other, than english.

Possible solution:

  • using ole api directory
  • using xml mode

Any change to do something with that?

Windows Task, with its current logic, should never work with :create

In the task.rb, it loads the current resource (load_current_resource, line 90). One of the steps, on line 94, is to load a task hash. This calls the load_task_hash method on line 108.

In this method, it calls the schtasks exe with the following general query:

output = shell_out("schtasks /Query /FO LIST /V /TN "#{task_name}"").stdout

This query will return an error code of [1] if the task does not exist. This is actually expected since if we're using the :create action on the resource, the task should certainly not exist.

The chef-run will error saying it received an error code of [1] and expected the error code to be [0].

If we pre-create the task the if statement on line 25 is true on the :create action, which then returns the response:

Chef::Log.info "#{@new_resource} task already exists - nothing to do"

The load_task_hash method should not error out if the task does not already exist.

ChefSpec deprecation warnings in libraries/matchers.rb

Running ChefSpec on a cookbook that includes this cookbook causes deprecation warning spam like so:

[DEPRECATION] `ChefSpec::Runner.define_runner_method' is deprecated. Please use `ChefSpec.define_matcher' instead.

Creating windows_task fails with shell_out error

Creating windows_tasks fails with the following error

FATAL: Mixlib::ShellOut::ShellCommandFailed: windows_task[chef-client-after-joining-domain](base::set-hostname-join-domain line 36) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit
with [0], but received '1'
---- Begin output of schtasks /Query /FO LIST /V /TN "chef-client-after-joining-domain" 2> NUL ----
STDOUT:
STDERR:
---- End output of schtasks /Query /FO LIST /V /TN "chef-client-after-joining-domain" 2> NUL ----

Ran schtasks /Query /FO LIST /V /TN "chef-client-after-joining-domain" 2> NUL returned 1

Checked the load_task_hash function in https://github.com/opscode-cookbooks/windows/blob/master/providers/task.rb#L111 where it tries to query whether a task exists using the task name. Since the task doesnโ€™t exists schtasks /Query returns non-zero return code which causes shell_out to fail. This will always fail when we try to create a new task. This bug was introduced with latest commit c92cbb0#diff-2b7fe0dd5a48d99464330b36ee9f1dc1

windows_task 'cwd' attribute doesn't seem to work

My windows_task resource looks like this:

windows_task "Do something" do
  command "C:\\Apps\\Directory\\do-something.bat"
  cwd "C:\\Apps\\Directory"
  ...
  action [:create, :run]
end

When I inspect the action in the task in Task Scheduler the Start in (optional) field is blank.

install_windows_package matcher throwing "TypeError: no implicit conversion of nil into String"

Similarly to what I've reported in #157, I'm tying to use ChefSpec to test a cookbook that uses the windows_package provider.
However, I'm always getting a "TypeError: no implicit conversion of nil into String" exception.

I've created an example cookbook that shows the issue, here https://github.com/miguelaferreira/chefspec_windows_tests

My recipe looks like this:

windows_package '7zip' do
  source 'C:\7z920.msi'
  action :install
end

My spec looks like this:

describe 'chefspec_windows_tests::windows_package' do
  let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'windows', version: '2012R2').converge(described_recipe) }

  it 'installs a windows package' do
    expect(chef_run).to install_windows_package('7zip')
  end
end

The output of rspec is the follwoing:

================================================================================
Recipe Compile Error in /var/folders/sm/tcsqvyfd7hvcw__25f6t7_016l9l6z/T/d20141216-28196-1jayy3w/cookbooks/chefspec_windows_tests/recipes/windows_package.rb
================================================================================

TypeError
---------
no implicit conversion of nil into String

Cookbook Trace:
---------------
  /var/folders/sm/tcsqvyfd7hvcw__25f6t7_016l9l6z/T/d20141216-28196-1jayy3w/cookbooks/chefspec_windows_tests/recipes/windows_package.rb:10:in `from_file'

Relevant File Content:
----------------------
/var/folders/sm/tcsqvyfd7hvcw__25f6t7_016l9l6z/T/d20141216-28196-1jayy3w/cookbooks/chefspec_windows_tests/recipes/windows_package.rb:

  3:  # Recipe:: default
  4:  #
  5:  # Copyright (C) 2014 YOUR_NAME
  6:  #
  7:  # All rights reserved - Do Not Redistribute
  8:  #
  9:  
 10>> windows_package '7zip' do
 11:    source 'C:\7z920.msi'
 12:    action :install
 13:  end
 14:  
 15:  

F

Failures:

  1) chefspec_windows_tests::windows_package installs a windows package
     Failure/Error: let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'windows', version: '2012R2').converge(described_recipe) }
     TypeError:
       no implicit conversion of nil into String
     # /var/folders/sm/tcsqvyfd7hvcw__25f6t7_016l9l6z/T/d20141216-28196-1jayy3w/cookbooks/chefspec_windows_tests/recipes/windows_package.rb:10:in `from_file'
     # ./spec/windows_package_spec.rb:5:in `block (2 levels) in <top (required)>'
     # ./spec/windows_package_spec.rb:8:in `block (2 levels) in <top (required)>'

Finished in 0.76953 seconds (files took 1.91 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/windows_package_spec.rb:7 # chefspec_windows_tests::windows_package installs a windows package

As opposed in issue #157, the stack-trace of this issue does not point to the windows cookbook code. It points to my own recipe.

Unable to find 'gem' binary in path

While executing recipe[sql_server::client] which depends on windows cookbook, chef fails (only) at the first execution with Unable to find 'gem' binary in path

[2015-02-24T16:51:30+00:00] INFO: Starting installation...this could take awhile.
[2015-02-24T16:51:32+00:00] INFO: Processing windows_path[C:\Program Files\Microsoft SQL Server\100\Tools\Binn] action add (sql_server::client line 37)
[2015-02-24T16:51:32+00:00] INFO: Processing env[path] action modify (C:\chef\cookbooks\windows\providers\path.rb line 25)
[2015-02-24T16:51:33+00:00] INFO: env[path] modified
[2015-02-24T16:51:33+00:00] INFO: env[path] sending run action to ruby_block[fix ruby ENV['PATH']] (immediate)
[2015-02-24T16:51:33+00:00] INFO: Processing ruby_block[fix ruby ENV['PATH']] action run (C:\chef\cookbooks\windows\providers\path.rb line 38)
[2015-02-24T16:51:33+00:00] INFO: ruby_block[fix ruby ENV['PATH']] called
[2015-02-24T16:51:33+00:00] INFO: Processing ruby_block[fix ruby ENV['PATH']] action nothing (C:\chef\cookbooks\windows\providers\path.rb line 38)
[2015-02-24T16:51:33+00:00] INFO: Processing gem_package[tiny_tds] action install (sql_server::client line 45)
[2015-02-24T16:51:34+00:00] INFO: Running queued delayed notifications before re-raising exception
[2015-02-24T16:51:34+00:00] ERROR: Running exception handlers
[2015-02-24T16:51:34+00:00] ERROR: Exception handlers complete
[2015-02-24T16:51:34+00:00] FATAL: Stacktrace dumped to C:/chef/cache/chef-stacktrace.out
[2015-02-24T16:51:34+00:00] FATAL: Chef::Exceptions::FileNotFound: gem_package[tiny_tds] (sql_server::client line 45) had an error: Chef::Exceptions::FileNotFound: Unable to find 'gem' binary in path: C:\Program Files\Microsoft SQL Server\100\Tools\Binn;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\opscode\chef\bin;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\Redist\
[2015-02-24T16:55:39+00:00] INFO: *** Chef 12.0.3 ***

Dependencies are

depends          'windows', '~> 1.36.1'
depends          'iis', '~> 2.1.6'
depends          'sql_server', '~> 2.2.0'

cannot load such file -- ruby-wmi

For any weird reason this dependency is making troubles ... Using Chef version 11.16.0

       [2014-09-13T15:25:03-07:00] INFO: *** Chef 11.16.0 ***

This is the trace error:

       ================================================================================
       Recipe Compile Error in C:/tmp/kitchen/cookbooks/windows/libraries/registry_helper.rb
       ================================================================================

       LoadError
       ---------
       cannot load such file -- ruby-wmi

       Cookbook Trace:
       ---------------
         C:/opscode/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
         C:/opscode/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
         C:/tmp/kitchen/cookbooks/windows/libraries/registry_helper.rb:27:in `<top (required)>'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/run_context/cookbook_compiler.rb:191:in `load'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/run_context/cookbook_compiler.rb:191:in `block in load_libraries_from_cookbook'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/run_context/cookbook_compiler.rb:188:in `each'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/run_context/cookbook_compiler.rb:188:in `load_libraries_from_cookbook'       
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/run_context/cookbook_compiler.rb:99:in `block in compile_libraries'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/run_context/cookbook_compiler.rb:98:in `each'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/run_context/cookbook_compiler.rb:98:in `compile_libraries'       
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/run_context/cookbook_compiler.rb:71:in `compile'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/run_context.rb:89:in `load'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/policy_builder/expand_node_object.rb:73:in `setup_run_context'   
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/client.rb:265:in `setup_run_context'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/client.rb:429:in `do_run'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/client.rb:227:in `run'                                                                           
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/application.rb:236:in `run_chef_client'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/application/solo.rb:226:in `block in run_application'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/application/solo.rb:218:in `loop'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/application/solo.rb:218:in `run_application'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/lib/chef/application.rb:55:in `run'
         C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.0-x86-mingw32/bin/chef-solo:25:in `<top (required)>'
         C:/opscode/chef/bin/chef-solo:23:in `load'
         C:/opscode/chef/bin/chef-solo:23:in `<main>'

How do I access the "installed?" method for the feature_servermanagercmd provider

If I run the following using servermanagercmd and the feature is already installed, the chef client will fail with an error noting that the feature is already installed.

windows_feature 'Web-Common-Http' do
  action :install
end

I see that the provider feature_servermanagercmd has a installed? method but I am unsure how to use it to first check if the feature is installed. Could someone give me a hand? Thanks.

Upgrading Windows cookbook causes windows_package resource failure installing PowerShell4

I upgraded the Windows cookbook from 1.31.2 to 1.36.6, without changing anything else and now the powershell::powershell4 recipe is failing. Downgrading the Windows cookbook to the old version and re-running succeeds, so something in the Windows cookbook has changed that the PowerShell cookbook doesn't like.

  • Windows Server 2008 R2 SP1 fully patched
  • NET 4.5.2
  • Chef 11.12.4

Here's the output:

[2015-02-19T16:08:53-08:00] INFO: Processing remote_file[c:/chef/cache/Windows6.1-KB2819745-x64-MultiPkg.msu] action create (dynamically defined)
[2015-02-19T16:08:54-08:00] INFO: Starting installation...this could take awhile.

================================================================================
Error executing action `install` on resource 'windows_package[Windows Management Framework Core4.0]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0, 42, 127, 3010], but received '2359302'
---- Begin output of start "" /wait "c:\chef\cache\Windows6.1-KB2819745-x64-MultiPkg.msu" /quiet /norestart & exit %%ERRORLEVEL%% ----
STDOUT: 
STDERR: 
---- End output of start "" /wait "c:\chef\cache\Windows6.1-KB2819745-x64-MultiPkg.msu" /quiet /norestart & exit %%ERRORLEVEL%% ----
Ran start "" /wait "c:\chef\cache\Windows6.1-KB2819745-x64-MultiPkg.msu" /quiet /norestart & exit %%ERRORLEVEL%% returned 2359302

Cookbook Trace:
---------------
c:/chef/cache/cookbooks/windows/libraries/windows_package.rb:109:in `install_package'
c:/chef/cache/cookbooks/windows/libraries/windows_package.rb:31:in `block in <class:WindowsCookbookPackage>'

Resource Declaration:
---------------------
# In c:/chef/cache/cookbooks/powershell/recipes/powershell4.rb

 36:     windows_package 'Windows Management Framework Core4.0' do
 37:       source node['powershell']['powershell4']['url']
 38:       checksum node['powershell']['powershell4']['checksum']
 39:       installer_type :custom
 40:       options '/quiet /norestart'
 41:       action :install
 42:       success_codes [0, 42, 127, 3010]
 43:       # Note that the :immediately is to immediately notify the other resource,
 44:       # not to immediately reboot. The windows_reboot 'notifies' does that.
 45:       notifies :request, 'windows_reboot[powershell]', :immediately if reboot_pending? && node['powershell']['installation_reboot_mode'] != 'no_reboot'
 46:       not_if do
 47:         begin
 48:           registry_data_exists?('HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine', { :name => 'PowerShellVersion', :type => :string, :data => '4.0' })
 49:         rescue Chef::Exceptions::Win32RegKeyMissing
 50:           false
 51:         end
 52:       end
 53:     end
 54:   else

Compiled Resource:
------------------
# Declared in c:/chef/cache/cookbooks/powershell/recipes/powershell4.rb:36:in `from_file'

windows_cookbook_package("Windows Management Framework Core4.0") do
  provider Chef::Provider::WindowsCookbookPackage
  action [:install]
  retries 0
  retry_delay 2
  guard_interpreter :default
  cookbook_name "powershell"
  recipe_name "powershell4"
  source "http://download.microsoft.com/download/3/D/6/3D61D262-8549-4769-A660-230B67E15B25/Windows6.1-KB2819745-x64-MultiPkg.msu"
  checksum "fbc0889528656a3bc096f27434249f94cba12e413142aa38946fcdd8edf6f4c5"
  installer_type :custom
  options "/quiet /norestart"
  timeout 600
  success_codes [0, 42, 127, 3010]
  package_name "Windows Management Framework Core4.0"
  not_if { #code block }
end

windows_package fails to install MSI with error 1603

This is probably the same problem that caused chef/knife-windows#96 and probably needs whatever fix they used.

Here's a snip from my logfile:

windows_package("Applicaton Request Routing 3.0") do
  action [:install]
  retries 0
  retry_delay 2
  guard_interpreter :default
  cookbook_name "imagekind_windows"
  recipe_name "iis_arr"
  source "http://download.microsoft.com/download/6/3/D/63D67918-483E-4507-939D-7F8C077F889E/requestRouter_x64.msi"
  package_name "Applicaton Request Routing 3.0"
  timeout 600
  success_codes [0, 42, 127]
end

[2014-10-15T18:40:53+00:00] INFO: Running queued delayed notifications before re-raising exception
[2014-10-15T18:40:53+00:00] ERROR: Running exception handlers
[2014-10-15T18:40:53+00:00] ERROR: Exception handlers complete
[2014-10-15T18:40:53+00:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
[2014-10-15T18:40:53+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: windows_package[Applicaton Request Routing 3.0] (imagekind_windows::iis_arr line 12) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0, 42, 127], but received '1603'

From what I can tell Microsoft put out a security patch that breaks installing programs remotely, unless you've logged into a graphical session.

NoMethodErrors using Windows and Powershell cookbooks

I updated our chef-server to v12.0.0 today (chasing SSL issues), now a chef-client run returns this:

Windows PowerShell
Copyright (C) 2013 Microsoft Corporation. All rights reserved.

PS C:\Windows\system32> chef-client
Starting Chef Client, version 12.0.1
[2014-12-12T13:33:02-05:00] INFO: *** Chef 12.0.1 ***
[2014-12-12T13:33:02-05:00] INFO: Chef-client pid: 5012
[2014-12-12T13:33:10-05:00] INFO: Run List is [recipe[windows], role[CORP-baseWindows]]
[2014-12-12T13:33:10-05:00] INFO: Run List expands to [windows, CORP-Roles::CORP-baseWindows]
[2014-12-12T13:33:10-05:00] INFO: Starting Chef Run for servername
[2014-12-12T13:33:10-05:00] INFO: Running start handlers
[2014-12-12T13:33:10-05:00] INFO: Start handlers complete.
[2014-12-12T13:33:10-05:00] INFO: HTTP Request Returned 404 Not Found:
resolving cookbooks for run list: ["windows", "CORP-Roles::CORP-baseWindows"]
[2014-12-12T13:33:10-05:00] INFO: Loading cookbooks [windows@1.34.8, chef_handler@1.1.6, CORP-Roles@0.1.0, CORP-baseWindows@0.1.0, CORP-WindowsWebLayer@0.1.0, iis@2.1.6, CORP-WELT@0.1.0, ResponseDriver.WebUI@0.1.0, NXlog@0.1.0, CheckMKagent@0.1
.0, CORP-graphite_powershell_functions@1.1.0, powershell@3.0.7, ms_dotnet45@2.0.0, ms_dotnet4@1.0.2, ms_dotnet2@1.0.0, ms_dotnet35@1.0.1]
Synchronizing Cookbooks:
  - windows
  - chef_handler
  - CORP-Roles
  - CORP-baseWindows
  - CORP-WindowsWebLayer
  - iis
  - CORP-WELT
  - ResponseDriver.WebUI
  - CORP-graphite_powershell_functions
  - CheckMKagent
  - powershell
  - ms_dotnet45
  - ms_dotnet4
  - ms_dotnet2
  - ms_dotnet35
  - NXlog
Compiling Cookbooks...
[2014-12-12T13:33:11-05:00] INFO: WindowsPackage light-weight resource is already initialized -- Skipping loading c:/chef/cache/cookbooks/windows/resources/package.rb!
[2014-12-12T13:33:11-05:00] INFO: Powershell light-weight provider is already initialized -- Skipping loading c:/chef/cache/cookbooks/powershell/providers/default.rb!
Recipe: windows::default
  * chef_gem[win32-api] action install[2014-12-12T13:33:11-05:00] INFO: Processing chef_gem[win32-api] action install (windows::default line 23)
 (up to date)
  * chef_gem[win32-service] action install[2014-12-12T13:33:11-05:00] INFO: Processing chef_gem[win32-service] action install (windows::default line 23)
 (up to date)
  * chef_gem[windows-api] action install[2014-12-12T13:33:11-05:00] INFO: Processing chef_gem[windows-api] action install (windows::default line 31)
 (up to date)
  * chef_gem[windows-pr] action install[2014-12-12T13:33:11-05:00] INFO: Processing chef_gem[windows-pr] action install
(windows::default line 31)
 (up to date)
  * chef_gem[win32-dir] action install[2014-12-12T13:33:11-05:00] INFO: Processing chef_gem[win32-dir] action install (windows::default line 31)
 (up to date)
  * chef_gem[win32-event] action install[2014-12-12T13:33:11-05:00] INFO: Processing chef_gem[win32-event] action install (windows::default line 31)
 (up to date)
  * chef_gem[win32-mutex] action install[2014-12-12T13:33:11-05:00] INFO: Processing chef_gem[win32-mutex] action install (windows::default line 31)
 (up to date)
[2014-12-12T13:33:11-05:00] WARN: PowerShell 4.0 is not supported or already installed on this version of Windows: 6.3.9600
  Converging 31 resources
  * chef_gem[win32-api] action install[2014-12-12T13:33:11-05:00] INFO: Processing chef_gem[win32-api] action install (windows::default line 23)
 (up to date)
  * chef_gem[win32-service] action install[2014-12-12T13:33:11-05:00] INFO: Processing chef_gem[win32-service] action install (windows::default line 23)
 (up to date)
  * chef_gem[windows-api] action install[2014-12-12T13:33:11-05:00] INFO: Processing chef_gem[windows-api] action install (windows::default line 31)
 (up to date)
  * chef_gem[windows-pr] action install[2014-12-12T13:33:11-05:00] INFO: Processing chef_gem[windows-pr] action install
(windows::default line 31)
 (up to date)
  * chef_gem[win32-dir] action install[2014-12-12T13:33:12-05:00] INFO: Processing chef_gem[win32-dir] action install (windows::default line 31)
 (up to date)
  * chef_gem[win32-event] action install[2014-12-12T13:33:12-05:00] INFO: Processing chef_gem[win32-event] action install (windows::default line 31)
 (up to date)
  * chef_gem[win32-mutex] action install[2014-12-12T13:33:12-05:00] INFO: Processing chef_gem[win32-mutex] action install (windows::default line 31)
 (up to date)
Recipe: CORP-baseWindows::default
  * windows_feature[TelnetClient] action install[2014-12-12T13:33:12-05:00] INFO: Processing windows_feature[TelnetClient] action install (CORP-baseWindows::default line 12)
 (up to date)
  * directory[C:\temp] action create[2014-12-12T13:33:14-05:00] INFO: Processing directory[C:\temp] action create (CORP-baseWindows::default line 18)
 (up to date)
  * directory[C:\coldStorage] action create[2014-12-12T13:33:15-05:00] INFO: Processing directory[C:\coldStorage] action
 create (CORP-baseWindows::default line 27)
 (up to date)
Recipe: NXlog::default
  * cookbook_file[nxlog-ce-2.8.1248.msi] action create[2014-12-12T13:33:15-05:00] INFO: Processing cookbook_file[nxlog-ce-2.8.1248.msi] action create (NXlog::default line 14)
 (up to date)
  * windows_package[NXlog] action install[2014-12-12T13:33:15-05:00] INFO: Processing windows_package[NXlog] action install (NXlog::default line 20)


    ================================================================================
    Error executing action `install` on resource 'windows_package[NXlog]'
    ================================================================================

    NoMethodError
    -------------
    undefined method `shell_out!' for #<Chef::Provider::Package::Windows::MSI:0x1d14b90>

    Resource Declaration:
    ---------------------
    # In c:/chef/cache/cookbooks/NXlog/recipes/default.rb

     20: windows_package "NXlog" do
     21:        package_name "NXlog-client"
     22:        source 'C:\temp\nxlog-ce-2.8.1248.msi'
     23:        installer_type :msi
     24:        action :install
     25:        not_if 'C:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoLogo -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned Get-Service -Name NXlog'
     26: end
     27:

    Compiled Resource:
    ------------------
    # Declared in c:/chef/cache/cookbooks/NXlog/recipes/default.rb:20:in `from_file'

    windows_package("NXlog") do
      action [:install]
      retries 0
      retry_delay 2
      default_guard_interpreter :default
      package_name "NXlog-client"
      source "C:\\temp\\nxlog-ce-2.8.1248.msi"
      version "2.8.1248\x00"
      timeout 600
      installer_type :msi
      returns [0]
      cookbook_name "NXlog"
      recipe_name "default"
      not_if "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned Get-Service -Name NXlog"
    end

[2014-12-12T13:33:17-05:00] INFO: Running queued delayed notifications before re-raising exception

Running handlers:
[2014-12-12T13:33:17-05:00] ERROR: Running exception handlers
Running handlers complete
[2014-12-12T13:33:17-05:00] ERROR: Exception handlers complete
[2014-12-12T13:33:17-05:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 24.469287 seconds
[2014-12-12T13:33:17-05:00] FATAL: NoMethodError: windows_package[NXlog] (NXlog::default line 20) had an error: NoMethod
Error: undefined method `shell_out!' for #<Chef::Provider::Package::Windows::MSI:0x1d14b90>

On hosts that need powershell v4 installed (the above is 2012R2), like 2008R2, I was also seeing the same error style but for 'checksum'. Commenting out the 'checksum' line in the powershell v4 recipe allowed the install to complete.

This link describes my issue pretty close: http://lists.opscode.com/sympa/arc/chef/2014-07/msg00226.html

Debug info looks like this:

servername [2014-12-12T13:22:01-05:00] DEBUG: Server doesn't support resource history, skipping resource report.
servername [2014-12-12T13:22:01-05:00] FATAL: NoMethodError: windows_package[NXlog] (NXlog::default line 20) had an erro
r: NoMethodError: undefined method `shell_out!' for #<Chef::Provider::Package::Windows::MSI:0x103eae0>
ERROR: Failed to execute command on servername return code 1

Line#20 of the referenced recipe:

# Install NXlog
windows_package "NXlog" do
    package_name "NXlog-client"
    source 'C:\temp\nxlog-ce-2.8.1248.msi' 
    installer_type :msi
    action :install
    not_if 'C:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoLogo -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned Get-Service -Name NXlog'  
end

At this point, unless this is an easy fix, I have no choice but to downgrade. Pretty sure this is an issue with the windows cookbook, but still a Chef newbie....so...maybe I've broken something?

windows_task does not delete task

I have tried the following on one of our cloud VM's and also on a local Vagrant Windows 2008R2 test VM.

I create a scheduled task pretty much using your sample code:

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

I confirm that the task is there. I then run only the following:

windows_task 'Chef client' do
action :delete
end

Logging reports the task has successfully been deleted. It has not.

I am getting around this at the moment by using the batch resource to run SchTasks with the /F to silently delete the task.

Install MSI for ALLUSERS by default

When a MSI does not install for all users by default, it is only installed for the user that runs chef-client.

Installing windows package for all users by default is a reasonable default and is consistent with the way it's done on other plaforms.

v1.32.0 version does not work with providers

We are using Chef version 11.10.4 and we get this error trying to use the windows_package or windows_path provider:

   ==> default: NoMethodError
   ==> default: -------------
   ==> default: No resource or method named `windows_package' for `Chef::Recipe myrecipe'

This is working fine with v1.31.0

"Registry is not a module" error under Chef Client 12

This cookbook won't load under Chef Client 12's release candidate. It was working fine under 11.16.4.

Paging @jdmundrawala ... haven't dug into it more yet myself.

Compiling Cookbooks...

================================================================================
Recipe Compile Error in c:/chef/cache/cookbooks/windows/libraries/registry_helper.rb
================================================================================

TypeError
---------
Registry is not a module

Cookbook Trace:
---------------
  c:/chef/cache/cookbooks/windows/libraries/registry_helper.rb:361:in `<top (required)>'

Relevant File Content:
----------------------
c:/chef/cache/cookbooks/windows/libraries/registry_helper.rb:

354:          Chef::Log.debug("Hive was loaded, we really should unload it")
355:          unload_hive(path)
356:        end
357:      end
358:    end
359:  end
360:
361>> module Registry
362:    module_function
363:    extend Windows::RegistryHelper
364:  end
365:

Undefined method `checksum' for Chef::Resource::WindowsPackage with Chef 12.0.0

This seems to be an issue with Chef 12.0.0 and windows_package (Windows Server 2012 R2):

10.168.18.67 [2014-12-05T17:45:15+00:00] INFO: *** Chef 12.0.0 ***
...
10.168.18.67 [2014-12-05T17:45:57+00:00] INFO: Loading cookbooks [[email protected], [email protected], [email protected], [email protected], [email protected], [email protected]]
...
10.168.18.67 NoMethodError
10.168.18.67 -------------
10.168.18.67 undefined method `checksum' for Chef::Resource::WindowsPackage
10.168.18.67
10.168.18.67 Cookbook Trace:
10.168.18.67 ---------------
10.168.18.67   c:/chef/cache/cookbooks/java/recipes/windows.rb:73:in `block in from_file'
10.168.18.67   c:/chef/cache/cookbooks/java/recipes/windows.rb:71:in `from_file'
10.168.18.67   c:/chef/cache/cookbooks/java/recipes/default.rb:28:in `from_file'
10.168.18.67   c:/chef/cache/cookbooks/sikulix_test/recipes/default.rb:1:in `from_file'
10.168.18.67
10.168.18.67 Relevant File Content:
10.168.18.67 ----------------------
10.168.18.67 c:/chef/cache/cookbooks/java/recipes/windows.rb:
10.168.18.67
10.168.18.67  66:      action :add
10.168.18.67  67:    end
10.168.18.67  68:  end
10.168.18.67  69:
10.168.18.67  70:
10.168.18.67  71:  windows_package node['java']['windows']['package_name'] do
10.168.18.67  72:    source cache_file_path
10.168.18.67  73>>   checksum node['java']['windows']['checksum']
10.168.18.67  74:    action :install
10.168.18.67  75:    installer_type :custom
10.168.18.67  76:    options "/s #{additional_options}"
10.168.18.67  77:  end

Reboot handler being overridden by notifications

So this is an interesting issue in theory - how to solve is a different matter.

Take the sample use case where I have several recipes working togetjer that does the following:

Recipe1:
Calls windows_package and does a delayed notification to a Windows_reboot call
This delayed notification, will execute at end of chef run.

Recipe2
We have another recipe that says we want to reboot immediately and end the chef-run. The implementation of how to end the chef-run would be something like the following:
Windows_reboot with action of nothing
ruby_block that exits with specific error code
log resource that notifies the above 2 - reboot first, then ruby block

The problem is at the end of the chef_run - what is the value of the windows_reboot handler....
It is the value of the delayed notification. This is unexpected, and difficult to debug due to the fact that the delayed notification is basically updating the handler after the other reboot code is executed. So now if I had code outside of chef was expecting the box to reboot in 5 seconds, but the delayed notification gives 10 minutes - then I will not know when it will reboot appropriately.

Options to fix:
Make it so we can freeze the values of the reboot handler. Basically will ignore delayed notifications if there are values for reason/timeout. Allows for one to freeze the settings as desired.

Attempt to delete notification using a seperate action in the reboot provider. - Seems doable - but not sure the roadmap of handlers in chef - and if handlers should be messing with notification collections. Not sure if this is technically feasible.

Come up with another way to reboot the box in a deterministic way that guarantees the last windows_reboot resource call is honored. Skip notifications altogether - this has far reaching consequences.

I am open to ideas how to solve this. I didnt want to go implementing because I know chef is implementing reboot in Core Chef and I dont know if they have this use case in mind.

Add some basic tests to this cookbook

Seeing how a lot of other cross-os cookbooks depend on this particular cookbook, I think some basic tests would go a long way to prevent issues like #92.

Even a simple ruby -c before uploading would've caught this error, but possibly adding Rubocop and Foodcritic would also help to prevent unwanted issues. Ideally some unit tests would be best.

Just writing this down here, I'm not in a position to do this right now, but perhaps someone else can, or I can take a shot at it in a few weeks, after I'm done moving.

knife windows bootstrap should support enabling the service

On other platforms, we've left the business of how to run Chef after the first run to the user to decide using a cookbook, because so many installations are different. Some use cron, others the chef-client as a daemon, others choose to only run Chef manually. The chef-client cookbook contains over a dozen implementation possibilities.

However, we did choose to have the MSI be able to install and enable the service on Windows. It would make sense to enable knife windows bootstrap to do this on installation as well:

From https://docs.chef.io/install_windows.html:

msiexec /qn /i C:\inst\chef-client-11.8.0-1.windows.msi ADDLOCAL="ChefClientFeature,ChefServiceFeature"

Installing package with other msiexec running in parallel fails run

If some other installation is in progress, msiexec finishes with exit code 1618 and message:

STDOUT: Another program is being installed. Please wait until that installation is complete, and then try installing this software again.

resulting resource run to fail.

Probably it would be better, if resource checked that exit code and retried several times with some graceful timeout.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.