# Bootstraping windows node using machine resource

**URL:** <https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490>\
**Category:** Chef Infra (archive)\
**Created:** [May 17, 2016, 3:06pm UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490 "2016-05-17T15:06:50Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![chernaj](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@chernaj](https://discourse.chef.io/u/chernaj)\
**Post date:** [May 17, 2016, 3:06pm UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/1 "2016-05-17T15:06:50Z")

</div>

Hi people,

I wrote this recipe to apply another recipe on a specific node:

require ‘chef/provisioning/ssh\_driver’

with\_chef\_server “[https://domain.local.com/organizations/exemple](https://domain.local.com/organizations/exemple)”

machine ‘node1’ do  
action [:ready, :setup, :converge]  
machine\_options :transport\_options =\> {  
‘is\_windows’ =\> true,  
‘host’ =\> ‘ipadress’,  
‘port’ =\> 5985,  
‘username’ =\> ‘username’,  
‘password’ =\> ‘password’  
}  
recipe 'test::default’  
converge true  
end

first of all how to apply it on the remote machine? and do i need to change the metadata.rb to declare test cookbook dependency?

thanks!

---

<div class="post-metadata">

**Author:** ![chernaj](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@chernaj](https://discourse.chef.io/u/chernaj)\
**Post date:** [May 18, 2016, 10:04am UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/2 "2016-05-18T10:04:20Z")

</div>

i tried this command chef-client -z cluster.rb after uploading the cookbook to the server but it doesn’t seem to connect to the server!

INFO: HTTP Request Returned 404 Object Not Found: error

```
================================================================================
Error executing action `ready` on resource 'machine[node1]'
================================================================================

RuntimeError

```

ERROR: machine[node1] (@recipe\_file::~/chef-repo/cookbooks/provisionning/recipes/cluster.rb line 8) had an error: RuntimeError: Driver not specified for machine node1

---

<div class="post-metadata">

**Author:** ![Christine\_Draper](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/christine_draper/32/68_2.png) [@Christine\_Draper](https://discourse.chef.io/u/Christine_Draper)\
**Post date:** [May 18, 2016, 12:25pm UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/3 "2016-05-18T12:25:37Z")

</div>

You need to add a `with_driver 'ssh'` statement to the provisioning recipe, or use the `driver` attribute on the machine resource.

You’ll also probably need to add credentials to the `with_chef_server` statement, as described here [https://github.com/chef/chef-provisioning#pointing-boxes-at-chef-servers](https://github.com/chef/chef-provisioning#pointing-boxes-at-chef-servers).

---

<div class="post-metadata">

**Author:** ![chernaj](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@chernaj](https://discourse.chef.io/u/chernaj)\
**Post date:** [May 18, 2016, 12:52pm UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/4 "2016-05-18T12:52:05Z")

</div>

I modified the recipe :  
require ‘chef/provisioning/ssh\_driver’

with\_chef\_server “[https://domain.local.com/organizations/exemple](https://domain.local.com/organizations/exemple)”,  
:client\_name =\> Chef::Config[:node\_name],  
:signing\_key\_filename =\> Chef::Config[:client\_key]

with\_driver ‘ssh’

machine “ssh” do  
action [:ready, :setup, :converge]

machine\_options :transport\_options =\> {  
‘is\_windows’ =\> true,  
‘host’ =\> ‘10.200.24.160’,  
‘port’ =\> 5985,  
‘username’ =\> ‘username’,  
‘password’ =\> ‘password’  
}  
recipe 'test::default’  
converge true

end

And i got this error now:

machine[ssh] (@recipe\_files::~/chef-repo/cookbooks/provisionning/recipes/cluster.rb line 9) had an error: RuntimeError: Machine Options for ssh are invalid cannot create machine.

---

<div class="post-metadata">

**Author:** ![nclemons](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/nclemons/32/3374_2.png) [@nclemons](https://discourse.chef.io/u/nclemons)\
**Post date:** [May 18, 2016, 1:21pm UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/5 "2016-05-18T13:21:56Z")

</div>

If it’s a windows node, I would think you need the winrm driver.

Nathan Clemons  
DevOps Engineer  
Moxie Cloud Services (MCS)

O +1.425.467.5075  
M +1.360.861.6291  
E [nclemons@gomoxie.com](mailto:nclemons@gomoxie.com)  
W [www.gomoxie.com](http://www.gomoxie.com)[http://www.gomoxie.com/](http://www.gomoxie.com/)

---

<div class="post-metadata">

**Author:** ![Christine\_Draper](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/christine_draper/32/68_2.png) [@Christine\_Draper](https://discourse.chef.io/u/Christine_Draper)\
**Post date:** [May 18, 2016, 1:30pm UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/6 "2016-05-18T13:30:52Z")

</div>

Looking at the [chef-provisioning-ssh code](https://github.com/chef/chef-provisioning-ssh/blob/ef89ed05e3a08818bbefe562d069ed2f1d35a7a8/lib/chef/provisioning/ssh_driver/driver.rb#L222), I think you have encountered a bug: validation is failing when the port is specified. As long as you’re using the default 5985 port, you can work around this by omitting the port.

fyi, I know it shows this in the example, but you may not want to specify all of the actions explicitly as this seems to trigger unnecessary additional processing. It should be sufficient to specify `action :converge` or omit the action entirely. You also only need `converge true` if you want to force a converge every time you run the provisioning recipe (rather than only if something has changed).

---

<div class="post-metadata">

**Author:** ![chernaj](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@chernaj](https://discourse.chef.io/u/chernaj)\
**Post date:** [May 18, 2016, 1:52pm UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/7 "2016-05-18T13:52:19Z")

</div>

Ok well it seems better without precising the port but now it looks like it doesn’t install chef-client :

ERROR: machine[exploitatos] (@recipe\_files::/~/chef-repo/cookbooks/provisionning/recipes/cluster.rb line 9) had an error: RuntimeError: Error: command ‘powershell.exe -ExecutionPolicy Unrestricted -NoProfile "& ““C:\chef\install.ps1"””’ exited with code 1.

---

<div class="post-metadata">

**Author:** ![chernaj](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@chernaj](https://discourse.chef.io/u/chernaj)\
**Post date:** [May 18, 2016, 3:18pm UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/8 "2016-05-18T15:18:02Z")

</div>

Do you have any idea please wheere the problem comes from?

thanks!

---

<div class="post-metadata">

**Author:** ![Christine\_Draper](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/christine_draper/32/68_2.png) [@Christine\_Draper](https://discourse.chef.io/u/Christine_Draper)\
**Post date:** [May 18, 2016, 3:25pm UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/9 "2016-05-18T15:25:40Z")

</div>

The error means that it is trying to run the bootstrap script `C:\chef\install.ps1` using powershell and it is failing. I would hazard a guess that there is some additional setup needed on your target Windows box to allow unattended execution, but I’m afraid I don’t use Windows,

---

<div class="post-metadata">

**Author:** ![chernaj](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@chernaj](https://discourse.chef.io/u/chernaj)\
**Post date:** [May 18, 2016, 3:35pm UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/10 "2016-05-18T15:35:07Z")

</div>

Okay here is my winrm config, my node is under windows 7 :  
Config  
MaxEnvelopeSizekb = 500  
MaxTimeoutms = 60000  
MaxBatchItems = 32000  
MaxProviderRequests = 4294967295  
Client  
NetworkDelayms = 5000  
URLPrefix = wsman  
AllowUnencrypted = true  
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 = 7200000  
MaxConcurrentUsers = 10  
MaxShellRunTime = 2147483647  
MaxProcessesPerShell = 25  
MaxMemoryPerShellMB = 1024  
MaxShellsPerUser = 30  
Obviously there is a problem with winrm because it fails to apply powershell script to install ?  
knife bootstrap windows winrm works

---

<div class="post-metadata">

**Author:** ![Matt\_Wrock](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/matt_wrock/32/3394_2.png) [@Matt\_Wrock](https://discourse.chef.io/u/Matt_Wrock)\
**Post date:** [May 19, 2016, 6:14am UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/11 "2016-05-19T06:14:22Z")

</div>

I think your winrm configuration is fine. The fact that the powershell command returns with an exit code of 1 indicates that it is at least being called. The real question is what’s the real error message.Not sure why thats not showing up. I’ve never used the ssh driver but I’d try running with debug logging and see if that provides a better error.

---

<div class="post-metadata">

**Author:** ![chernaj](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@chernaj](https://discourse.chef.io/u/chernaj)\
**Post date:** [May 19, 2016, 8:40am UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/12 "2016-05-19T08:40:52Z")

</div>

This is the error message detailed (sorry it’s in french but it looks like it doesn’t recognize the downloadstring in install.ps1)  
Exception lors de l’appel de «DownloadString» avec «1» argument(s): «  
Impossible de se connecter au serveur distant»  
Au caractère C:\chef\install.ps1:24 : 22  
+ Try { $response = ($c = Make-WebClient).DownloadString($url) }  
+ ~~~~~~~~~~~~~~~~~~~  
+ CategoryInfo : NotSpecified: (🙂 [], MethodInvocationException  
+ FullyQualifiedErrorId : WebException

```
              Impossible d’appeler une méthode dans une expression Null.
              Au caractère C:\chef\install.ps1:27 : 3
              + $md = ConvertFrom-StringData $response.Replace("`t", "=")
              + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  + CategoryInfo : InvalidOperation : (:) [], RuntimeException
                  + FullyQualifiedErrorId : InvokeMethodOnNull

```

Exception lors de l’appel de «DownloadFile» avec «2» argument(s): «Le chemin  
d’accès n’a pas une forme conforme.»  
Au caractère C:\chef\install.ps1:42 : 6  
+ ($c = Make-WebClient).DownloadFile($url, $dst)  
+ ~~~~~~~~~~~~~~~~~~~  
+ CategoryInfo : NotSpecified: (🙂 [], MethodInvocationException  
+ FullyQualifiedErrorId : ArgumentException  
msiexec was not successful. Received exit code 1619  
Au caractère C:\chef\install.ps1:55 : 28  
+ if ($p.ExitCode -ne 0) { throw "msiexec was not successful. Received exit  
code …  
+  
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
+ CategoryInfo : OperationStopped: (msiexec was not… exit code  
1619:String) [], RuntimeException  
+ FullyQualifiedErrorId : msiexec was not successful. Received exit code 1  
619

Again knife bootstrap windows winrm works fine. Do you see where the problem might come from?

thanks!

---

<div class="post-metadata">

**Author:** ![Matt\_Wrock](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/matt_wrock/32/3394_2.png) [@Matt\_Wrock](https://discourse.chef.io/u/Matt_Wrock)\
**Post date:** [May 19, 2016, 2:07pm UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/13 "2016-05-19T14:07:08Z")

</div>

Yeah it looks like its unable to reach the metadata\_url. This should be `https://www.chef.io/chef/metadata?p=windows&m=x86_64&pv=2008r2`. Try connecting to the node and see if you can access that url (or any url) from the node to isolate if there are network issues preventing your node from reaching the external web.

---

<div class="post-metadata">

**Author:** ![chernaj](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@chernaj](https://discourse.chef.io/u/chernaj)\
**Post date:** [May 19, 2016, 2:53pm UTC](https://discourse.chef.io/t/bootstraping-windows-node-using-machine-resource/8490/14 "2016-05-19T14:53:45Z")

</div>

Well very strange because i checked my node connection and it’s fine, i tried this on powershell using this:

$web = New-Object Net.WebClient  
$web | Get-Member  
$web.DownloadString(“[http://www.google.com](http://www.google.com)”)

and it seems to be ok.
