Giter Club home page Giter Club logo

knife-windows's Introduction

Knife Windows Plugin

Build status Gem Version

Umbrella Project: Knife

Project State: Active

Issues Response Time Maximum: 14 days

Pull Request Response Time Maximum: 14 days

This plugin adds additional functionality to the Chef Knife CLI tool for configuring / interacting with nodes running Microsoft Windows:

  • Remote command execution using the WinRM protocol
  • Utilities to configure WinRM SSL endpoints on managed nodes

Knife bootstrap windows ssh/winrm

Core Chef now supports bootstrapping Windows systems without a knife plugin

knife-windows plugin Chef Infra Client 15+ Notes
knife windows bootstrap ssh knife bootstrap -o ssh or knife bootstrap Default is 'ssh'
knife windows bootstrap winrm knife bootstrap -o winrm

For more detail https://github.com/chef/chef/blob/master/RELEASE_NOTES.md#knife-bootstrap

Subcommands

This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a --help flag

knife winrm

The winrm subcommand allows you to invoke commands in parallel on a subset of the nodes in your infrastructure. The winrm subcommand uses the same syntax as the search subcommand; you could find the uptime of all your web servers using the command:

knife winrm "role:web" "net stats srv" -x Administrator -P 'super_secret_password'

Please note that to run a single command against multiple nodes, each node must share the same username and password.

Or force a chef run:

knife winrm "myserver.myorganization.net" "chef-client -c c:/chef/client.rb" -m -x Administrator -P "super_secret_password"
myserver.myorganization.net [Fri, 04 Mar 2011 22:00:49 +0000] INFO: Starting Chef Run (Version 0.9.12)
myserver.myorganization.net [Fri, 04 Mar 2011 22:00:50 +0000] WARN: Node ip-0A502FFB has an empty run list.
myserver.myorganization.net [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Chef Run complete in 4.383966 seconds
myserver.myorganization.net [Fri, 04 Mar 2011 22:00:53 +0000] INFO: cleaning the checksum cache
myserver.myorganization.net [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Running report handlers
myserver.myorganization.net [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Report handlers complete

This subcommand operates in a manner similar to knife ssh...just leveraging the WinRM protocol for communication. It also includes knife ssh's "interactive session mode"

winrm-shell

By default, knife winrm runs in a cmd.exe shell. You can use the --winrm-shell argument to change the shell to powershell or elevated. An elevated shell is similar to the powershell shell but the powershell command is executed from a scheduled task using a local identity. This may be desirable for some operations such as running chef-client to converge recipes that work with windows updates, install sql server, etc.

Tip: Use SSL for WinRM communication

By default, the knife winrm subcommands use a plaintext transport, but they support an option --winrm-transport (or -t) with the argument ssl that allows the SSL to secure the WinRM payload. Here's an example:

knife winrm -t ssl "role:web" "net stats srv" -x Administrator -P "super_secret_password" -f ~/server_public_cert.crt

Use of SSL is strongly recommended, particularly when invoking knife-windows on non-Windows platforms, since without SSL there are limited options for ensuring the privacy of the plaintext transport. See the section on Platform authentication support.

SSL will become the default transport in future revisions of knife-windows.

knife wsman test

Connects to the remote WSMan/WinRM endpoint and verifies the remote node is listening. This is the equivalent of running Test-Wsman from PowerShell. Endpoints to test can be specified manually, or be driven by search and use many of the same connection options as knife winrm. To test a single node using the default WinRM port (5985)

knife wsman test 192.168.1.10 -m

or to test a single node with SSL enabled on the default port (5986)

knife wsman test 192.168.1.10 -m --winrm-transport ssl

or to test all windows nodes registered with your Chef Server organization

knife wsman test platform:windows

knife windows cert generate

Generates a certificate(x509) containing a public / private key pair for WinRM 'SSL' communication. The certificate will be generated in three different formats:

  • .pem - The *.pem is Base64 encoded public certificate only. One can use this file with the -f argument on knife winrm command.
  • .pfx - The PKCS12(i.e .pfx) contains both the public and private keys, usually used on the server. This can be added to a WinRM Server's Certificate Store using knife windows cert install (see command description below). Note: Do not use the *.pfx file with the -f argument on the knife winrm command. Use the *.pem file instead.
  • .b64 - The *.b64 is Base64 PKCS12 key pair. Contains both the public and private keys, for upload to the Cloud REST API. e.g. Azure.

This command also displays the thumbprint of the generated certificate.

knife windows cert generate --cert-passphrase "strong_passphrase" --hostname "myserver.myorganization.net" --output-file "~/server_cert.pfx"
# This command will generate certificates in the user's home directory with names server_cert.b64, server_cert.pfx and server_cert.pem.

knife windows cert install

This command only functions on Windows and is intended to be run on a chef node. It adds the specified certificate to its certificate store. This command must include a valid PKCS12(i.e *.pfx) certificate file path such as the *.pfx file generated by knife windows cert generate described above.

knife windows cert install "~/server_cert.pfx" --cert-passphrase "strong_passphrase"

knife windows listener create

This command only functions on Windows and is intended to be run on a chef node. It creates the winrm listener for SSL communication(i.e HTTPS). This command can also install certificate which is specified using --cert-install option and use the installed certificate thumbprint to create winrm listener. --hostname option is optional. Default value for hostname is *.

knife windows listener create --cert-passphrase "strong_passphrase" --hostname "myserver.mydomain.net" --cert-install "~/server_cert.pfx"

The command also allows you to use existing certificates from local store to create winrm listener. Use --cert-thumbprint option to specify the certificate thumbprint.

knife windows listener create --cert-passphrase "strong_passphrase" --hostname "myserver.mydomain.net" --cert-thumbprint "bf0fef0bb41be40ceb66a3b38813ca489fe99746"

You can get the thumbprint for existing certificates in the local store using the following PowerShell command:

ls cert:\LocalMachine\My

Requirements / setup

Ruby

Ruby 1.9.3+ is required.

Chef version

This knife plugins requires >= Chef 11.0.0. More details about Knife plugins can be found in the Chef documentation.

Nodes

WinRM versions

The node must be running Windows Remote Management (WinRM) 2.0+. WinRM allows you to call native objects in Windows. This includes, but is not limited to, running PowerShell scripts, batch scripts, and fetching WMI data. For more information on WinRM, please visit Microsoft's WinRM site.

WinRM is built into Windows 7 and Windows Server 2008+. It can also be installed on older version of Windows, including:

  • Windows Server 2003
  • Windows Vista

WinRM configuration

NOTE: Before any WinRM related knife subcommands will function a node's WinRM installation must be configured correctly. The settings below must be added to your base server image or passed in using some sort of user-data mechanism provided by your cloud provider. Some cloud providers will set up the required WinRM configuration through the cloud API for creating instances -- see the documentation for the provider.

A server running WinRM must also be configured properly to allow outside connections for the entire network path from the knife workstation to the server. The easiest way to accomplish this is to use WinRM's quick configuration option:

winrm quickconfig -q

This will set up an WinRM listener using the HTTP (plaintext) transport -- WinRM also supports the SSL transport for improved robustness against information disclosure and other threats.

The chef-client installation may take more memory than the default 150MB WinRM allocates per shell on older versions of Windows (prior to Windows Server 2012) -- this can slow it down or cause it to fail. The memory limit was increased to 1GB with Windows Management Framework 3 (and Server 2012). However, there is a bug in Windows Management Framework 3 (and Server 2012) which requires a hotfix from Microsoft. You can increase the memory limit to 1GB with the following PowerShell command:

    set-item wsman:\localhost\shell\maxmemorypershellmb 1024

Commands can take longer than the WinRM default 60 seconds to complete, optionally increase to 30 minutes if terminates a command prematurely:

    set-item wsman:\localhost\MaxTimeoutms 300000

Note that the winrm command itself supports the same configuration capabilities as the PowerShell commands given above -- if you need to configure WinRM without using PowerShell, use winrm -? to get help.

WinRM supports both the HTTP and HTTPS (SSL) transports and the following authentication schemes: Kerberos, Digest, Certificate and Basic. The details of these authentication transports are outside of the scope of this README but details can be found on the WinRM configuration guide.

Working with legacy Windows versions

If you are attempting to use knife winrm with a version of windows that is older than server 2008 R2 or older than Windows 7 then you may need to alter the default UTF-8 codepage (65001) using the --winrm-codepage argument. You can use the codepage native to your locale but 437 is a safe codepage for older Windows versions.

Configure SSL on a Windows node

WinRM supports use of SSL to provide privacy and integrity of communication using the protocol and to prevent spoofing attacks.

Configure SSL using knife

knife-windows includes three commands to assist with SSL configuration -- these commands support all versions of Windows and do not rely on PowerShell:

  • knife windows cert generate: creates a certificate that may be used to configure an SSL WinRM listener

  • knife windows cert install: Installs a certificate into the Windows certificate store so it can be used to configure an SSL WinRM listener.

  • knife windows listener create: Creates a WinRM listener on a Windows node -- it can use either a certificate already installed in the Windows certificate store, or one created by other tools including the knife windows cert generate command.

Here is an example that configures a listener on the node on which the commands are executed:

knife windows cert generate --domain myorg.org --output-file $env:userprofile/winrmcerts/winrm-ssl
knife windows listener create --hostname *.myorg.org --cert-install $env:userprofile/winrmcerts/winrm-ssl.pfx

Note that the first command which generates the certificate for the listener could be executed from any system that can run knife as long as the certificate it generates is made available at a path at which the second command can access it.

See previous sections for additional details of the windows cert generate, windows cert install and windows listener create subcommands.

Configure SSL using Windows Server 2012 or later

The following PowerShell commands may be used to create an SSL WinRM listener with a self-signed certificate on Windows 2012R2 or later systems:

$cert = New-SelfSignedCertificate -DnsName 'myserver.mydomain.org' -CertStoreLocation Cert:\LocalMachine\My
new-item -address * -force -path wsman:\localhost\listener -port 5986 -hostname ($cert.subject -split '=')[1] -transport https -certificatethumbprint $cert.Thumbprint
# Open the firewall for 5986, the default WinRM SSL port
netsh advfirewall firewall set rule name="Windows Remote Management (HTTPS-In)" profile=public protocol=tcp localport=5986 remoteip=localsubnet new remoteip=any

Note that the first command which uses the New-SelfSignedCertificate cmdlet is available only in PowerShell version 4.0 and later.

Configure SSL using winrm quickconfig

The following command can configure an SSL WinRM listener if the Windows certificate store's Local Machine store contains a certificate that meets certain criteria that are most likely to be met if the system is joined to a Windows Active Directory domain:

winrm quickconfig -transport:https -q

If the criteria are not met, an error message will follow with guidance on the certificate requirements; you may need to obtain a certificate from the appropriate source or use the PowerShell or knife techniques given above to create the listener instead.

Disabling peer verification

In the SSL examples above, the -f parameter was used to supply a certificate that could validate the identity of the remote server. For debugging purposes, this validation may be skipped if you have not obtained a public certificate that can validate the server. Here is an example:

knife winrm -m 192.168.0.6 -x "mydomain\myuser" -P $PASSWD -t ssl --winrm-ssl-verify-mode verify_none ipconfig

This option should be used carefully since disabling the verification of the remote system's certificate can subject knife commands to spoofing attacks.

Connecting securely to self-signed certs

If you generate a self-signed cert, the fqdn and ip may not match which will result in a certificate validation failure. In order to securely connect and reduce the risk of a "Man In The Middle" attack, you may use the certificate's fingerprint to precisely identify the known certificate on the WinRM endpoint.

The fingerprint can be supplied to --ssl-peer-fingerprint and instead of using a certificate chain and comparing the CommonName, it will only verify that the fingerprint matches:

knife winrm --ssl-peer-fingerprint 89255929FB4B5E1BFABF7E7F01AFAFC5E7003C3F \
	      -m $IP -x Administrator -P $PASSWD-t ssl --winrm-port 5986 hostname
	10.113.4.54 ip-0A710436

WinRM authentication

The default authentication protocol for knife-windows subcommands that use WinRM is the Negotiate protocol. The following commands show authentication for domain and local accounts respectively:

knife winrm -m web1.cloudapp.net -x "proddomain\webuser" -P "super_secret_password"
knife winrm -m db1.cloudapp.net -x "localadmin" -P "super_secret_password"

The remote system may also be configured with an SSL WinRM listener instead of a plaintext listener. Then the above commands should be modified to use the SSL transport as follows using the -t (or --winrm-transport) option with the ssl argument:

knife winrm -m web1.cloudapp.net -t ssl -x "proddomain\webuser" -P "super_secret_password" -f ~/mycert.crt
knife winrm -m db1.cloudapp.net -t ssl -x "localadmin" -P "super_secret_password" ~/mycert.crt

Troubleshooting authentication

Unencrypted traffic with Basic authentication should only be used for low level wire protocol debugging. The configuration for plain text connectivity to the remote system may be accomplished with the following PowerShell commands:

set-item wsman:\localhost\service\allowunencrypted $true
set-item wsman:\localhost\service\auth\basic $true

To use basic authentication connectivity via knife-windows, the default authentication protocol of Negotiate must be overridden using the --winrm-authentication-protocol option with the desired protocol, in this case Basic:

knife winrm -m web1.cloudapp.net --winrm-authentication-protocol basic ipconfig -x localadmin -P "super_secret_password"

Note that when using Basic authentication, domain accounts may not be used for authentication; an account local to the remote system must be used.

Platform WinRM authentication support

knife-windows supports Kerberos, Negotiate, and Basic authentication for WinRM communication.

The following table shows the authentication protocols that can be used with knife-windows depending on whether the knife workstation is a Windows system, the transport, and whether or not the target user is a domain user or local to the target Windows system.

* There is a known defect in the knife winrm winrm` subcommands invoked on any OS platform when authenticating with the Negotiate protocol over the SSL transport. The defect is tracked by knife-windows issue #176: If the remote system is domain-joined, local accounts may not be used to authenticate via Negotiate over SSL -- only domain accounts will work. Local accounts will only successfully authenticate if the system is not joined to a domain.

This is generally not an issue for bootstrap scenarios, where the system has yet to be joined to any domain, but can be a problem for remote management cases after the system is domain joined. Workarounds include using a domain account instead or bypassing SSL and using Negotiate authentication.

General troubleshooting

  • Windows 2008R2 and earlier versions require an extra configuration for MaxTimeoutms to avoid WinRM::WinRMHTTPTransportError: Bad HTTP response error while bootstrapping. It should be at least 300000.

    set-item wsman:\\localhost\\MaxTimeoutms 300000

  • When I run the winrm command I get: "Error: Invalid use of command line. Type "winrm -?" for help." You're running the winrm command from PowerShell and you need to put the key/value pair in single quotes. For example:

    winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="1024"}'

  • If you receive a timeout when trying to connect to your instance for the first time, make sure your Firewall setting is permissive enough.

    netsh advfirewall firewall set rule name="Windows Remote Management (HTTP-In)" profile=public protocol=tcp localport=5985 remoteip=localsubnet new remoteip=any

AWS User Data

If you are spinning up AWS instances to test against, you can use the following user data when spinning up your instances:

<powershell>
$logfile="C:\\Program Files\\Amazon\\Ec2ConfigService\\Logs\\kitchen-ec2.log"
# Allow script execution
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
# PS Remoting and & winrm.cmd basic config
Enable-PSRemoting -Force -SkipNetworkProfileCheck
& winrm.cmd set winrm/config '@{MaxTimeoutms="1800000"}' >> $logfile
& winrm.cmd set winrm/config/winrs '@{MaxMemoryPerShellMB="1024"}' >> $logfile
& winrm.cmd set winrm/config/winrs '@{MaxShellsPerUser="50"}' >> $logfile
#Server settings - support username/password login
& winrm.cmd set winrm/config/winrs '@{MaxMemoryPerShellMB="1024"}' >> $logfile
# Firewall Config
& netsh advfirewall firewall set rule name="Windows Remote Management (HTTP-In)" profile=public protocol=tcp localport=5985 remoteip=localsubnet new remoteip=any  >> $logfile
</powershell>

CONTRIBUTING:

Please file bugs against the KNIFE_WINDOWS project at https://github.com/chef/knife-windows/issues.

More information on the contribution process for Chef projects can be found in the Chef Contributions document.

LICENSE:

Author:: Seth Chisamore ([email protected]) Copyright:: Copyright (c) 2015-2016 Chef Software, Inc. License:: Apache License, Version 2.0

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.

knife-windows's People

Contributors

btm avatar chef-ci avatar dependabot-preview[bot] avatar dheerajd-msys avatar dpetzel avatar hh avatar jaym avatar jeppenejsum avatar jeremiahsnapp avatar johnmccrae avatar josephrdsmith avatar kaustubh-d avatar lamont-granquist avatar matschaffer avatar mwrock avatar nashwini avatar neshy avatar piyushawasthi avatar pmorton avatar prabhu-das avatar sanga1794 avatar schisamo avatar sean-horn avatar siddheshwar-more avatar smurawski avatar tas50 avatar tduffield avatar tyler-ball avatar vkarve-chef avatar vvchik 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

knife-windows's Issues

winrm/config/service AllowUnencrypted flag is true, but can't connect & error thinks it is false

Error: Unencrypted communication not supported. Please check winrm configuration winrm/config/service AllowUnencrypted flag.

Unfortunately, the mentioned flag is already appropriately set: https://gist.github.com/philax/004f0f38426381dcd049

I'm just running: https://gist.github.com/philax/5434a8917b2ef57c6fab

I get the same response if I use chef server to search the name instead of -m.

I'm running knife from a windows machine. gem list | egrep knife-windows returns version 0.8.2. I've tried in both Powershell and GitBash just in case.

Allow a proc/lambda for knife[:winrm_password]

Our Administrator passwords vary per machine (for best security). It would be nice if we could use a callback for knife[:winrm_password] so that we could look up the password (it's in a yaml file that becomes a databag, but other users might want to look it up some other way) on a per machine basis.

I'm imagining something like:

def lookup_admin_password(node_name):
  YAML.load('my_passwords.yml')[node_name]
end

knife[:winrm_user] = 'Administrator'
knife[:winrm_password] = method(:lookup_admin_password)

"Error: Unencrypted communication not supported" with 0.8.0 and winrm

I've just upgraded from 0.6.0 to 0.8.0 and now I get

ERROR: RuntimeError: Error: Unencrypted communication not supported. Please check winrm configuration winrm/config/service AllowUnencrypted flag.

when trying to bootstrap. The command

knife winrm myserver.me.com dir -m -x user -P pass

gives the same error. Uninstalling 0.8.0 fixes the problem.

The error seems to be coming from the winrm-s gem's sspi.rb class (decrypt_payload).

The 2 machines are Windows 2012 R2 and not on a domain. The client machine has Client/AllowUnencrypted set to true and service/AllowUnencrypted set to false. The target machine has service/AllowUnencrypted set to true.

no suck file to load 'windows/api'

Hi Seth,

I'm trying to get the knife windows bootstrap thing going. My test with the ruby gem winrm went ok, but it seems that the windows/api is not loaded. If I understand it right this is part of the windows-api gem, but that doesn't compile on my mac?

I'd love to get some guidance whether this is possible or not, or maybe I'm missing something?
Or is it windows only for the client too.

Thanks for the hard work!

knife windows bootstrap
internal:lib/rubygems/custom_require:29:in require': no such file to load -- windows/api (LoadError) from <internal:lib/rubygems/custom_require>:29:inrequire'
from /Users/patrick/.rvm/gems/ruby-1.9.2-p136@veeweetest/gems/chef-0.9.14/lib/chef/util/windows.rb:19:in <top (required)>' from <internal:lib/rubygems/custom_require>:29:inrequire'
from internal:lib/rubygems/custom_require:29:in require' from /Users/patrick/.rvm/gems/ruby-1.9.2-p136@veeweetest/gems/chef-0.9.14/lib/chef/util/windows/net_use.rb:23:in<top (required)>'
from internal:lib/rubygems/custom_require:29:in require' from <internal:lib/rubygems/custom_require>:29:inrequire'
from /Users/patrick/.rvm/gems/ruby-1.9.2-p136@veeweetest/gems/chef-0.9.14/lib/chef/knife/windows_bootstrap.rb:109:in run' from /Users/patrick/.rvm/gems/ruby-1.9.2-p136@veeweetest/gems/chef-0.9.14/lib/chef/knife.rb:127:inrun'
from /Users/patrick/.rvm/gems/ruby-1.9.2-p136@veeweetest/gems/chef-0.9.14/lib/chef/application/knife.rb:121:in run' from /Users/patrick/.rvm/gems/ruby-1.9.2-p136@veeweetest/gems/chef-0.9.14/bin/knife:25:in<top (required)>'
from /Users/patrick/.rvm/gems/ruby-1.9.2-p136@veeweetest/bin/knife:19:in load' from /Users/patrick/.rvm/gems/ruby-1.9.2-p136@veeweetest/bin/knife:19:in

'

Add a 'desktop' subcommand

It would be cool to have a 'desktop' subcommand that opened the correct Microsoft Remote Desktop application.

You can do this by constructing an rdp_uri and passing it to the correct program.

An example rdp_uri: rdp://full%20address=s:10.0.0.15&username=s:Administrator

You then pass this to the proper program on the OS:

  • OS X: Use the open command.
  • Linux: Use the xdg-open command.
  • Windows: Pass it to Explorer.

It could use the same winrm_user and winrm_password values. It would make bug #169 all that more useful too.

NTLM auth for knife winrm / windows bootstrap fails in Ruby 2.0

Currently, if you specify the -x (user) argument as domain\user, knife-windows is supposed to use negotiate authentication if you're running knife on Windows. However, it can't do this correctly without some modifications to http traffic that are now failing in Ruby 2.0.

Specifically this is an issue with the winrm-s gem. A potential fix is here: chef-boneyard/winrm-s#14.

recipes requiring elevated privileges fail under winrm bootstrap

I'm working with chef 10.12.0 and knife-windows 0.5.8

I'm trying to bootstrap a Windows XP machine with a role that includes the following recipe:
https://github.com/dougm/site-cookbooks/blob/master/windows/recipes/update.rb

This recipe runs just fine if I run chef-client as Administrator locally on the Windows XP machine. The recipe also works if I'm logged in locally to the Windows XP machine and use runas /user:Administrator with chef-client.

What doesn't work is a regular winrm bootstrap (e.g. knife bootstrap windows winrm IPADDRESS -r 'role[windows-xp]' -x 'Administrator' -P 'PASSWORD' -p 80). The bootstrap will kick off fine, but when it reaches the update recipe it dies with what amounts to a 'permission denied' error code:

[2012-08-09T14:43:25-04:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
[2012-08-09T14:43:25-04:00] FATAL: WIN32OLERuntimeError: (in OLE method `AcceptEula': )
OLE error code:80070005 in

HRESULT error code:0x80020009
Exception occurred.

I believe that recipe is sound given that it works when run directly as Administrator on the machine.

I've attempted work on the windows_boostrap_context.rb to have start_chef write a vb script using runas but I haven't had luck with getting it to actually run. if I use WshShell.run I can feed in the password and get it to run but not report back. If I use WshShell.exe I can get it to report back but not feed in the password.

Is there a known problem with winrm not elevating privileges properly? Is there a work around?

Knife windows winrm hasn't worked since Patch Tuesday

I can connect using winrs, but winrm is no good anymore. I'm just getting timeouts.

Servers created at Rackspace last week work fine, servers created since Wednesday, not so much.

knife rackspace server create

creates the servers fine, but bootstrapping fails to connect.

Anyone else experiencing this?

Error: cmd.exe is not recognised

I receive following error while executing chef recipe using "batch" resource


23.20.28.208
23.20.28.208 Mixlib::ShellOut::ShellCommandFailed
23.20.28.208 ------------------------------------
23.20.28.208 Expected process to exit with [0], but received '1'
23.20.28.208 ---- Begin output of "cmd.exe" /c "C:/Users/ADMINI~1/AppData/Local/Temp/chef-script20140929-2460-1wxmaos.bat" ----
23.20.28.208 STDOUT:
23.20.28.208 STDERR: '"cmd.exe"' is not recognized as an internal or external command,


This is seen on latest Amazon windows 2008 server AMI mostly patched with latest updates.

The Amazon AMI is also affected by
#96,
I removed the related security patch to enable chef installation

This was working two months back, it might be related to latest windows patches.

deprecate knife bootstrap --distro

From lib/chef/knife/bootstrap.rb:

      # DEPR: Remove this option in Chef 13
      option :distro,
        :short => "-d DISTRO",
        :long => "--distro DISTRO",
        :description => "Bootstrap a distro using a template. [DEPRECATED] Use -t / --bootstrap-template option instead.",
        :proc        => Proc.new { |v|
          Chef::Log.warn("[DEPRECATED] -d / --distro option is deprecated. Use -t / --bootstrap-template option instead.")
          v
        }

The above deprecation is from chef/chef#1885. We should deprecate both --distro --template in knife-windows in lib/chef/knife/bootstrap_windows_base.rb.

Which is easy enough, except theres some inconsistency in --bootstrap-template in knife-windows.

again from lib/chef/knife/bootstrap.rb:

      option :bootstrap_template,
        :short => "-t TEMPLATE",
        :long => "--bootstrap-template TEMPLATE",
        :description => "Bootstrap Chef using a built-in or custom template. Set to the full path of an erb template or use one of the built-in templates."

We need to add this option to knife-windows as the preferred option as well.

NameError: undefined local variable or method `path_separator'

I am running knife bootstrap command from my workstation( which is windows) and my target bootstrap system also windows. while executing below command getting below error message. Please give solution for this.

C:\chef>knife bootstrap windows winrm Desktop1.test.com -x user1 -P password1
Bootstrapping Chef on Desktop1.test.com
ERROR: knife encountered an unexpected error
This may be a bug in the 'bootstrap windows ssh' knife command or plugin
Please collect the output of this command with the `-VV` option before filing a
bug report.
Exception: NameError: undefined local variable or method `path_separator' for #<
Chef::Knife::Core::WindowsBootstrapContext:0x31ff3b0>


C:\chef>knife bootstrap windows ssh Desktop1.test.com
Bootstrapping Chef on Desktop1.test.com
ERROR: knife encountered an unexpected error
This may be a bug in the 'bootstrap windows ssh' knife command or plugin
Please collect the output of this command with the `-VV` option before filing a
bug report.
Exception: NameError: undefined local variable or method `path_separator' for #<
Chef::Knife::Core::WindowsBootstrapContext:0x31ff3b0>


C:\chef>knife bootstrap windows ssh Desktop1.test.com -VV
Bootstrapping Chef on Desktop1.test.com
DEBUG: Looking for bootstrap template in E:/opscode/chef/embedded/lib/ruby/gems/
1.9.1/gems/knife-windows-1.0.0.dev.0/lib/chef/knife/bootstrap
DEBUG: Found bootstrap template in E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/
gems/knife-windows-1.0.0.dev.0/lib/chef/knife/bootstrap
E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-windows-1.0.0.dev.0/lib/
chef/knife/core/windows_bootstrap_context.rb:267:in `cleanpath': undefined local
 variable or method `path_separator' for #<Chef::Knife::Core::WindowsBootstrapCo
ntext:0x2fc89c8> (NameError)
        from E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-windows-1.0
.0.dev.0/lib/chef/knife/core/windows_bootstrap_context.rb:249:in `escape_glob'
        from E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-windows-1.0
.0.dev.0/lib/chef/knife/core/windows_bootstrap_context.rb:238:in `trusted_certs_
content'
        from E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-windows-1.0
.0.dev.0/lib/chef/knife/core/windows_bootstrap_context.rb:56:in `trusted_certs_s
cript'
        from (erubis):200:in `block in evaluate'
        from E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/erubis-2.7.0/lib/
erubis/evaluator.rb:74:in `instance_eval'
        from E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/erubis-2.7.0/lib/
erubis/evaluator.rb:74:in `evaluate'
        from E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-windows-1.0
.0.dev.0/lib/chef/knife/bootstrap_windows_base.rb:138:in `render_template'
        from E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-windows-1.0
.0.dev.0/lib/chef/knife/bootstrap_windows_base.rb:183:in `create_bootstrap_bat_c
ommand'
        from E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-windows-1.0
.0.dev.0/lib/chef/knife/bootstrap_windows_base.rb:154:in `bootstrap'
        from E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-windows-1.0
.0.dev.0/lib/chef/knife/bootstrap_windows_ssh.rb:75:in `run'
        from E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.4-x86-
mingw32/lib/chef/knife.rb:493:in `run_with_pretty_exceptions'
        from E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.4-x86-
mingw32/lib/chef/knife.rb:174:in `run'
        from E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.4-x86-
mingw32/lib/chef/application/knife.rb:139:in `run'
        from E:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.16.4-x86-
mingw32/bin/knife:25:in `<top (required)>'
        from E:/opscode/chef/bin/knife:23:in `load'
        from E:/opscode/chef/bin/knife:23:in `<main>'

My gem env details are below

RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.28
  - RUBY VERSION: 1.9.3 (2013-11-22 patchlevel 484) [i386-mingw32]
  - INSTALLATION DIRECTORY: E:/opscode/chef/embedded/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: E:/opscode/chef/embedded/bin/ruby.exe
  - EXECUTABLE DIRECTORY: E:/opscode/chef/embedded/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-mingw32
  - GEM PATHS:
     - E:/opscode/chef/embedded/lib/ruby/gems/1.9.1
     - C:/Users/ponnusamy/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

Bootstrap Windows Server 2003 Fails to download

Version:

12.0.3

Environment:

Windows Server 2003

Scenario:

I'm trying to bootstrap a Windows Server 2003 host, it's correctly identifying the OS however the download url does not exist. Going to the website when you attempt to download the Windows 2003 version it will download the 2008 version.

Steps to Reproduce:

bootstrap a Windows 2003 server

Expected Result:

Chef Client is downloaded and installed

Actual Result:

Download fails

Knife winrm times out with HTTP 500 after 30 minutes

I have a windows machine with WinRM configured as follows:

C:\Users\Administrator>winrm get winrm/config
Config
    MaxEnvelopeSizekb = 500
    MaxTimeoutms = 14400000
    MaxBatchItems = 32000
    MaxProviderRequests = 4294967295
    Client
        NetworkDelayms = 5000
        URLPrefix = wsman
        AllowUnencrypted = false
        Auth
            Basic = true
            Digest = true
            Kerberos = true
            Negotiate = true
            Certificate = true
            CredSSP = false
        DefaultPorts
            HTTP = 5985
            HTTPS = 5986
        TrustedHosts
    Service
        RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)
        MaxConcurrentOperations = 4294967295
        MaxConcurrentOperationsPerUser = 1500
        EnumerationTimeoutms = 240000
        MaxConnections = 300
        MaxPacketRetrievalTimeSeconds = 120
        AllowUnencrypted = true
        Auth
            Basic = true
            Kerberos = true
            Negotiate = true
            Certificate = false
            CredSSP = false
            CbtHardeningLevel = Relaxed
        DefaultPorts
            HTTP = 5985
            HTTPS = 5986
        IPv4Filter = *
        IPv6Filter = *
        EnableCompatibilityHttpListener = false
        EnableCompatibilityHttpsListener = false
        CertificateThumbprint
        AllowRemoteAccess = true
    Winrs
        AllowRemoteShellAccess = true
        IdleTimeout = 14400000
        MaxConcurrentUsers = 10
        MaxShellRunTime = 2147483647
        MaxProcessesPerShell = 25
        MaxMemoryPerShellMB = 4096
        MaxShellsPerUser = 30

When I run this command against that machine:

knife winrm -m 10.xxx.xxx.xxx -x username -P password "powershell -Command \"Start-Sleep -s 3600\""

Then after exactly 30 minutes I get this error:

ERROR: WinRM::WinRMHTTPTransportError: Bad HTTP response returned from server (500).

When I run this command against the same machine:

winrs -r:10.xxx.xxx.xxx -u:username -p:password "powershell -command Start-Sleep -s 3600"

Then the command runs the full hour.

winrm bootstrap timeout

My first run with 'winrm bootstrap' included '-r role[windows]', which happens to take quite a long time and knife bailed about halfway through with:

ERROR: HTTPClient::ReceiveTimeoutError: execution expired

I haven't looked into where the timeout could be changed or what the default is.. but might be good to bump the default and/or have an option to pass in via knife.

ERROR: While executing gem ... (Errno::ENOENT)

Hi,
I tried to install knife-windows but there was "no such file or directory " error

C:\opscode\chef\embedded\bin>gem install knife-windows
ERROR: While executing gem ... (Errno::ENOENT)
No such file or directory - F:/

knife winrm should fail if commands that it executes on remote fail

On linux hosts we can have scripts which use knife ssh or bootstrap and count on them properly failing if the client run fails. It appears on winrm this isn't the case. i.e.

 $ knife winrm -m localhost "ipconf" -x vagrant -p 55985 -P vagrant || "echo didn't work"
localhost 'ipconf' is not recognized as an internal or external command,
localhost operable program or batch file.
~/workspace/projects/chefgen/windows/windows_2008 $ knife ssh -m 10.63.20.196 -x jmahowald "ifonf" || echo "no works"
10.63.20.196 bash: ifonf: command not found
no works

uninitialized constant Chef::Knife::Bootstrap (NameError)

Upgraded to Chef client 11.18 on my windows machine today and get an error when I try to upload a cookbook to the Chef server. Has anyone else seen this error? Uninstalling knife-windows does not solve the error.

$ knife cookbook upload <cookbook_name> 
c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-windows-0.8.2/lib/chef/knife/bootstrap_windows_ssh.rb:23:in `<class:Knife>': uninitialized constant Chef::Knife::Bootstrap (NameError) 
from c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-windows-0.8.2/lib/chef/knife/bootstrap_windows_ssh.rb:22:in `<class:Chef>' 
from c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/knife-windows-0.8.2/lib/chef/knife/bootstrap_windows_ssh.rb:21:in `<top(required)>' 
from c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.18.0-x86-mingw32/lib/chef/knife/core/subcommand_loader.rb:37:in`load' 
from c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.18.0-x86-mingw32/lib/chef/knife/core/subcommand_loader.rb:37:in`block in load_commands' 
from c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.18.0-x86-mingw32/lib/chef/knife/core/subcommand_loader.rb:37:in`each' 
from c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.18.0-x86-mingw32/lib/chef/knife/core/subcommand_loader.rb:37:in`load_commands' 
from c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.18.0-x86-mingw32/lib/chef/knife.rb:120:in `load_commands' 
from c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.18.0-x86-mingw32/lib/chef/knife.rb:168:in `run' 
from c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.18.0-x86-mingw32/lib/chef/application/knife.rb:139:in `run' 
from c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.18.0-x86-mingw32/bin/knife:25:in `<top (required)>' 
from c:/opscode/chef/bin/knife:23:in `load' 
from c:/opscode/chef/bin/knife:23:in `<main>'

Warning messages on OS X Mavericks

When trying to run a bootstrap I receive the following warning messages on OS X Mavericks:

WARNING: Could not load IOV methods. Check your GSSAPI C library for an update
WARNING: Could not load AEAD methods. Check your GSSAPI C library for an update

Incompatible with httpclient 2.2.0.1

May also be incompatible with versions 2.2.0.0 and 2.2.0.2. Recommend dropping back to httpclient 2.1.7.2 to get knife-windows working.

Using knife-windows with 2.2.0.1 throws an exception about the content method not existing on the string class. This isn't really an issue caused by knife-windows. The issue is in the winrm-1.0.0rc4 gem in the file lib/winrm/http/transport.rb:22. winrm is calling resp.body.content and the content method doesn't seem to exist in the latest versions of httpclient

I can see that schisamo (the author of this gem) has already raised this as an issue for the winrm gem: https://github.com/zenchild/WinRM/pull/8

knife bootstrap windows winrm failing after Windows patch KB2918614

When trying to bootstrap a new Windows node, the process fails with the following error:

Installing downloaded client package...

C:\Users\useraccount>msiexec /qn /log "C:\Users\accoun~1\AppData\Local\Temp\chef-client-msi24561.log" /i "C:\Users\accoun~1\AppData\Local\Temp\chef-client-latest.msi" 
Chef-client package failed to install with status code 1603. 
See installation log for additional detail: C:\Users\accoun~1\AppData\Local\Temp\chef-client-msi24561.log. 

The listed log file includes the following:

The requested operation cannot be completed. The computer must be trusted for delegation and the current user account must be configured to allow delegation.

This is using knife-windows 0.6.0 with chef 11.12.8 to connect to an AD-bound Windows Server 2008 R2 system over SSL. I assume this is related to the issues described in https://tickets.opscode.com/browse/KNIFE-298 ? Verified that the issue doesn't appear until KB2918614 is applied to the system.

knife bootstrap windows winrm error

This is copied from chef/chef#1760

Hi Team,

When i tried to bootstrap a windows 7 machine under open source chef server using below method, i'm getting the error could you please help me on this

"knife bootstrap windows winrm ip/hostname -x doimain\usernama-p 5985"

error:-
Waiting for remote response before bootstrap.Enter your password:******
ruby: symbol lookup error: /usr/local/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.0.beta.3/lib/rubyeventmachine.so: undefined symbol: rb_enable_interrupt

try : 2
knife winrm -m IP -x user -P password 'dir c:'
ruby: symbol lookup error: /usr/local/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.0.beta.3/lib/rubyeventmachine.so: undefined symbol: rb_enable_interrupt

Note: i can able tpo telnet destination Windows server successfully.

appreciate your earlier response.

bootstrap's creation of client.rb should mimic chef gem's code

The code that creates the client.rb config during bootstrap should manage the same options that chef gem's code does.

Now that Chef Client 12 is out and SSL verification is enabled by default the knife-windows' code should auto-transfer trusted_certs_dir and manage verify_api_cert and ssl_verify_mode.

https://github.com/opscode/knife-windows/blob/0.8.2/lib/chef/knife/core/windows_bootstrap_context.rb#L47-L80

https://github.com/opscode/chef/blob/12.0.0/lib/chef/knife/core/bootstrap_context.rb#L56-L116

Specs broken on Chef 12 due to removal of read_template method from base class in Chef

See the following tests on Chef 12 -- these tests pass on Chef 11:

  1. Chef::Knife::BootstrapWindowsWinrm specifying no_proxy with various entries via --bootstrap-no-proxy renders the client.rb with a single FQDN no_proxy entry
    Failure/Error: template_string = knife.read_template.gsub(/^.[Vv]alidation_key.$/, '')
    NoMethodError:
    undefined method `read_template' for #Chef::Knife::BootstrapWindowsWinrm:0x007fe61359c710

    ./spec/unit/knife/bootstrap_template_spec.rb:72:in`block (3 levels) in <top (required)>'

    ./spec/unit/knife/bootstrap_template_spec.rb:80:in `block (4 levels) in <top (required)>'

  2. Chef::Knife::BootstrapWindowsWinrm specifying no_proxy with various entries via --bootstrap-no-proxy multiple renders the client.rb with comma-separated FQDN and wildcard IP address no_proxy entries
    Failure/Error: template_string = knife.read_template.gsub(/^.[Vv]alidation_key.$/, '')
    NoMethodError:
    undefined method `read_template' for #Chef::Knife::BootstrapWindowsWinrm:0x007fe613617a00

    ./spec/unit/knife/bootstrap_template_spec.rb:72:in`block (3 levels) in <top (required)>'

    ./spec/unit/knife/bootstrap_template_spec.rb:87:in `block (4 levels) in <top (required)>'

Bootstrap version is not as predictable compared to bootstrapping linux nodes.

With the recent release of client 12 it was brought to my attention that the windows bootstrap command did not act as predictably as its linux counterpart. When bootstrapping a new node the linux template will stay within the same major release version if no versions are specified (or in older versions would default to the version doing the bootstrapping). But unless a version is specified in the knife.rb it appears as though the msi template will always pull latest.

Perhaps I am missing something, but as far as I can tell the exact same setup will bootstrap a linux node at 11.12.8, but a windows node at 12.0.1

Installing gem requires a dependency unfulfilled on ruby 1.8.7

On OSX 10.7.3:

$ sudo gem install knife-windows
Password:
Fetching: eventmachine-1.0.0.beta.3.gem (100%)
Building native extensions.  This could take a while...
Fetching: gssapi-1.0.3.gem (100%)
ERROR:  Error installing knife-windows:
    gssapi requires Ruby version >= 1.9.1.

$ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]

Dependency listed here: https://github.com/zenchild/gssapi/blob/master/gssapi.gemspec#L31 as well as https://github.com/opscode/knife-windows/blob/master/knife-windows.gemspec#L17

The Requirements section of the readme should list that this gem will only work on ruby v1.9.1 and higher. It is stated in the summary, but not the requirements.

knife-windows bundler gem conflict Ohai 8.0 on Ruby 2.0 in Chef 11

Ohai 8.0 which is required for Chef 12 is not compatible with the knife-windows when installing the knife-windows gem through bundle install. This was caused by the release of Chef 12 and Ohai 8.0 to RubyGems.

The desired behavior is that the same knife-windows gem can be used on Chef 11 and Chef 12.

See repro below:

seaedwards01:knife-windows adamedwards$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using rake (10.4.2) 
Using builder (3.2.2) 
Using gyoku (1.2.2) 
Using mini_portile (0.6.1) 
Using nokogiri (1.6.5) 
Using akami (1.2.2) 
Using ffi (1.9.6) 
Using libyajl2 (1.2.0) 
Using ffi-yajl (1.3.1) 
Using hashie (2.1.2) 
Using mixlib-log (1.6.0) 
Using rack (1.5.2) 
Using uuidtools (2.1.5) 
Using chef-zero (3.2.1) 
Using diff-lcs (1.2.5) 
Using erubis (2.7.0) 
Using highline (1.6.21) 
Using mixlib-authentication (1.3.0) 
Using mixlib-cli (1.5.0) 
Using mixlib-config (2.1.0) 
Using mixlib-shellout (2.0.0) 
Using net-ssh (2.9.1) 
Using net-ssh-gateway (1.2.0) 
Using net-ssh-multi (1.2.0) 
Using ipaddress (0.8.0) 
Using mime-types (1.25.1) 
Using net-dhcp (1.3.2) 
Using systemu (2.6.4) 
Using wmi-lite (1.0.0) 
Installing ohai (8.0.1) 
Gem::InstallError: ohai requires Ruby version >= 2.0.0.
An error occurred while installing ohai (8.0.1), and Bundler cannot continue.
Make sure that `gem install ohai -v '8.0.1'` succeeds before bundling.

knife winrm: Local account auth fails over SSL transport on systems joined to a domain

If a system is joined to a domain, communication over an SSL listener on a remote system fails with a 401 error if credentials local to the remote system (i.e. non-domain credentials) are used, even when those credentials are part of the local administrators group and may be used to successfully communicate over ssl with the winrs tool in Windows or the Enter-PSSession command in PowerShell.

However, if domain credentials are used for that same system, authentication succeeds and the commands are executed.

Here's an example from master with verbose failure logging:
bundle exec knife winrm -f /Users/myuser/downloads/winrmcert.pem -m mysystem.myorg.org -t ssl ipconfig -x 'administrator' -P 'xxxxx' -p 5986

WARNING: No knife configuration file found

WARNING: --winrm-authentication-protocol option is not specified. Switching to Negotiate authentication

DEBUG: Adding mysystem.myorg.com

DEBUG: Trying WinRM communication with negotiate authentication and :ssl transport

DEBUG: WinRM::WinRMWebService options: {:user=>"administrator", :pass=>"xxxxxxx", :basic_auth_only=>false, :disable_sspi=>true, :no_ssl_peer_verification=>false, :ca_trust_path=>"/Users/myuser/downloads/winrmcert.pem"}

DEBUG: Endpoint: https://mysystem.myorg.com:5986/wsman

DEBUG: Transport: ssl

DEBUG: ipconfig

ERROR: Failed to authenticate to ["mysystem.myorg.org"] as administrator

Response: Bad HTTP response returned from server (401).

Hint: Please check winrm configuration 'winrm get winrm/config/service' AllowUnencrypted flag on remote server.

/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/winrm-1.2.0/lib/winrm/http/transport.rb:48:in `send_request': Bad HTTP response returned from server (401). (WinRM::WinRMHTTPTransportError)

Knife Bootstrap using WINRM.

Hi

I am trying to bootstrap a windows node. I tried following command but I got error.
C:\Users\Administrator\chef-repo>knife bootstrap windows winrm node_ip_address -x Administrator -P p@ssword.
WARNING: Hostname containing 'windows' specified. Please install 'knife-windows' if you are attempting to bootstrap a Windows node v
ia WinRM.
Connecting to windows
ERROR: Network Error: getaddrinfo: No such host is known.
Check your knife configuration and network settings

Please have a look and suggest solution.

Installing Gems During Bootstrap

I've found that during a bootstrap of a Windows 2008 R2 machine (via Knife-ec2), if the recipe requires a gem and installs it, the bootstrap intermittently fails with a "memory exception".

For example, when we use the windows_zipFile resource from the windows cookbook in our recipe, it requires the rubyzip gem, which is has to install. When it attempts to, it fails with a memory exception.

I've read around and it sounds like installing gems on windows machines is memory intensive, but this seems like such a basic thing that you would want to do in a recipe that it shouldn't fail this easily. So, I'm forced to think I'm doing something wrong, and I wanted to post this here to see if this is a known issue, and if so, if it has a work around.

I've double checked to make sure that WinrRM is setup correctly in our image, and even upped the max memory in the shell to 1024, instead of the recommended 300.

WinRM::WinRMHTTPTransportError: Bad HTTP response returned from server (503) in the middle of bootsrap

When attempting to bootstrap a Windows VM using WinRM from a Windows machine, we've been receiving this error:

10.208.149.188 powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -command "& 'C:\chef\wget.ps1' 'https://www.opscode.com/chef/download?p=windows&pv=2008r2&m=x86_64&v=11.16.4&DownloadContext=PowerShell' 'C:\Users\ADMINI1\AppData\Local\Temp\chef-client-latest.msi'"
DEBUG: :relay_output_from_backend => ["10.208.149.188", "Download via PowerShell succeeded.\r\n"]
10.208.149.188 Download via PowerShell succeeded.
DEBUG: :relay_output_from_backend => ["10.208.149.188", "Installing downloaded client package...\r\n\r\nC:\Users\Administrator>msiexec /qn /log "C:\Users\ADMINI
1\AppData\Local\Temp\chef-client-msi23576.log" /i "C:\Users\ADMINI1\AppData\Local\Temp\chef-client-latest.msi" \r\n"]
10.208.149.188 Installing downloaded client package...
10.208.149.188
10.208.149.188 C:\Users\Administrator>msiexec /qn /log "C:\Users\ADMINI
1\AppData\Local\Temp\chef-client-msi23576.log" /i "C:\Users\ADMINI~1\AppData\Local\Temp\chef-client-latest.msi"
ERROR: WinRM::WinRMHTTPTransportError: Bad HTTP response returned from server (503).

It usually fails during the installation of chef, but sometimes that succeeds, and it fails later during a different installation that the recipe is performing. This seems to have started recently (last few weeks) but I've been unable to get a working state of knife-windows, winrm, etc.

To bootstrap we're simply doing 'knife bootstrap windows winrm' with the ip, credentials, and role passed in.

`winrm_port` option should default to 5986 if `winrm_transport` option is `ssl`

Windows will configure the SSL WinRM transport on port 5986 by default, so when the winrm_transport option is set to ssl for the knife winrm or knife bootstrap windows winrm subcommands, the port should be set to 5986 instead of 5985 as it is currently unless the user overrides this by explicitly specifying the winrm_port option. This allows users to specify one less option on the command line (no need to specify winrm_port when winrm_transport is set to ssl if you're using the standard Windows port conventions) in the common case.

RESPONSE was 500

I've tried "winrm bootstrap" against new ec2 instances running Windows 2008 R2. The bootstrap continually fails (I've tried it many times) due to a 500 status code part way through the bootstrap process. It's getting a fair way through the process but fails during the install of the json gem. Here's a typical example of the failure:

Installing gem json-1.5.1
Downloading gem json-1.5.1.gem
GET http://rubygems.org/gems/json-1.5.1.gem
302 Found
GET http://production.cf.rubygems.org/gems/json-1.5.1.gem
200 OK
Temporarily enhancing PATH to include DevKit...
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/CHANGES
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/bin/edit_json.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/bin/prettify_json.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/VERSION
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/GPL
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/TODO
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/README
C:/ruby/lib/ru
by/gems/1.8/gems/json-1.5.1/benchmarks/ohai.json
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/parser_benchmark.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log
C:/ruby/lib/ruby/gems/1.
8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/generator2_benchmark.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/generator_benchmark.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/parser2_benchmark.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/benchmarks/ohai.ruby
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/ext/json/ext/generator/extconf.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/ext/json/ext/generator/generator.c
C:/ruby/lib/ruby/gems/
1.8/gems/json-1.5.1/ext/json/ext/generator/generator.h
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/ext/json/ext/parser/extconf.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/ext/json/ext/parser/parser.rl
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/ext/json/ext/parser/parser.h
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/ext/json/ext/parser/parser.c
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/Rakefile
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/README-json-jruby.markdown
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tools/fuzz.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tools/server.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/src/json/ext/Parser.rl
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/src/json/ext/StringDecoder.java
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/src/json/ext/GeneratorMethods.java
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/src/json/ext/StringEncoder.java
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/src/json/ext/Generator.java
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/sr
c/json/ext/GeneratorService.java
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/src/json/ext/Utils.java
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/src/json/ext/ByteListTranscoder.java
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/src/json/ext/RuntimeInfo.java
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/src/json/ext/ParserService.java
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/src/json/ext/OptionsReader.java
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/src/json/ext/GeneratorState.java
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/src/json/ext/Parser.java
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/lib/bytelist-1.0.6.jar
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/java/lib/jcodings.jar
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/COPYING-json-jruby
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/json.xpm
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/Key.xpm
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/String.xpm
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/Numeric.xpm
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/Hash.xpm
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/add/rails.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/add/core.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/common.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/Array.xpm
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/FalseClass.xpm
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/pure/generator.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/pure/parser.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/TrueClass.xpm
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/pure.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/version.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/ext.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/editor.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/lib/json/NilClass.xpm
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/data/example.json
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/data/index.html
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/data/prototype.js
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/test_json_encoding.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/test_json_addition.rb
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/fixtures/pass16.json
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/fixtures/fail4.json
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/fixtures/fail1.json
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/fixtures/fail28.json
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/fixtures/fail8.json
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/fixtures/fail19.json
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/fixtures/pass2.json
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/fixtures/pass26.json
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/fixtures/pass1.json
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/fixtures/fail3.json
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/fixtures/fail20.json
C:/ruby/lib/ruby/gems/1.8/gems/json-1.5.1/tests/fixtures/pass3.json
RESPONSE was 500
ERROR: knife encountered an unexpected error
This may be a bug in the 'winrm bootstrap' knife command or plugin
Exception: NoMethodError: undefined method `/' for nil:NilClass

I notice from reading the source code of the winrm gem that it hasn't implemented correct handling of HTTP status codes (see the "# TODO: raise error" line in transport.rb of winrm), which leads to the cryptic "undefined method" errors you often see with knife-windows. The "RESPONSE was YYY" bit is often the giveaway.

escape_glob missing for Chef::Util::PathHelper::Class

When using 1.0.0.dev.0 with ChefDK 3.5 on a Mac - I get a failure to bootstrap a windows node due to a missing 'escape_glob' in Chef::Util::PathHelper::Class.

The full -VV output is here -

smurawski@remmurawski01:chef-repo$ knife bootstrap windows winrm armory -x Administrator -P WalkerBlack!

Waiting for remote response before bootstrap.armory Response received.
armory 
Remote node responded after 0.01 minutes.
Bootstrapping Chef on armory
ERROR: knife encountered an unexpected error
This may be a bug in the 'bootstrap windows winrm' knife command or plugin
Please collect the output of this command with the `-VV` option before filing a bug report.
Exception: NoMethodError: undefined method `escape_glob' for Chef::Util::PathHelper:Class
smurawski@remmurawski01:chef-repo$ knife bootstrap windows winrm armory -x Administrator -P Passw@rd! -VV

Waiting for remote response before bootstrap.DEBUG: Adding armory
DEBUG: WinRM::WinRMWebService options: {:user=>"Administrator", :pass=>"Passw@rd!", :basic_auth_only=>true, :disable_sspi=>true, :no_ssl_peer_verification=>false, :ca_trust_path=>nil}
DEBUG: Endpoint: http://armory:5985/wsman
DEBUG: Transport: plaintext
DEBUG: echo . & echo Response received.
armory Response received.
armory 
Remote node responded after 0.0 minutes.
Bootstrapping Chef on armory
DEBUG: Looking for bootstrap template in /Users/smurawski/.chefdk/gem/ruby/2.1.0/gems/knife-windows-1.0.0.dev.0/lib/chef/knife/bootstrap
DEBUG: Found bootstrap template in /Users/smurawski/.chefdk/gem/ruby/2.1.0/gems/knife-windows-1.0.0.dev.0/lib/chef/knife/bootstrap
ERROR: knife encountered an unexpected error
This may be a bug in the 'bootstrap windows winrm' knife command or plugin
Please collect the output of this command with the `-VV` option before filing a bug report.
Exception: NoMethodError: undefined method `escape_glob' for Chef::Util::PathHelper:Class

Default timeout on knife bootstrap winrm is a bit high

Waiting for remote response before bootstrap...............................................................................................................................................................................................................................................................................................ERROR: No response received from remote node after 25.15 minutes, giving up.

The default timeout should probably be a lot lower than 25+ minutes. If it's not responding in a few minutes, it's not responding.

knife bootstrap run-list role would generate "Missing Cookbook" <...> *roles

I've been able to reproduce CHEF-4519 logged back in September 2013 initially logged on chef.opscode.com:

"When attempting to bootstrap a node with a single role listed in the run-list, an error is presented "Missing Cookbook". It appears that if you put a comma at the end of the single role[rolename], the same bootstrap command works."

My environment is as follows:

I've been able to reproduce this same issue. Environment details:
OS: Windows Server 2012 R2
Terminal: Power Shell (run as admin)
ChefDK: v0.3.2
Knife Windows: 0.8.2
Appending the comma after the closing bracket fixes the issue (exactly as detailed in the original bug).

Original ticket: https://tickets.opscode.com/browse/CHEF-4519

windows only commands should exit when not on windows

On OS X:

$ knife windows listener create --cert-thumbprint 1F3A70E2601FA1576BC4850ED2D7EF6587076423
sh: winrm: command not found
WinRM listener created
$ knife windows cert install winrmcert.b64
Enter given certificate's passphrase (empty for no passphrase):
Adding certificate to the Certificate Store...
sh: powershell.exe: command not found
Error adding the certificate. Use -VV option for details
  1. we shouldn't even try to run winrm if we're not on windows, we should exit with an error.
  2. even on windows, if the winrm command fails we shouldn't say that the listener was created

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.