misheska / basebox-packer

Packer templates for vagrant baseboxes
286 stars 80 forks source link

Fixes #31, #32 fixes WinRM installation #39

Closed rasa closed 10 years ago

rasa commented 10 years ago

Moved WinRM configuration commands to install-winrm.cmd, to allow easier logging/debugging (Autounattend.xml) Fixed several WinRM configuration (http://pastie.org/8581033 ) (install-winrm.cmd) All WinRM configuration commands now run without error (http://pastie.org/8582660 ) Added floppy/set-all-networks-to-private.ps1, which is called by install-winrm.cmd

misheska commented 10 years ago

Were you able to test this on Windows 7? It doesn't seem to work under vagrant-windows. The box hangs on a WinRM error. But progress in the sense that the network adapter is NOT Public during up the box and WINrm doesn't error on configure. But it looks like there is still a Network Location prompt appearing on boot that is preventing WinRM from working (even though the adapter is properly set to 'Work')

rasa commented 10 years ago

Were you able to test this on Windows 7? It doesn't seem to work under vagrant-windows

The HelloWorld.bat provisioner worked for me, yes. See https://gist.github.com/rasa/8459561

Here's my setup:

Windows 7 pro 64 host VMWare Workstation 10.0.1 Vagrant 1.4.3 vagrant-vmware-workstation plugin 2.2.8 vagrant-windows 1.5.1 Windows 7 pro 64 guest

Built box using #37, #38, #39, and #41 merged into integration branch Used template windows/win7x64-pro.json

Brought up box, using windows7/vagrantfile-win7x64-pro.template , with line 25 uncommented out.

But it looks like there is still a Network Location prompt appearing on boot that is preventing WinRM from working (even though the adapter is properly set to 'Work')

I think that's because we're installing a new vmxnet3 network adapter in windows7/vagrantfile-win7x64-pro

I ran net stop opensshd on the guest before running vagrant provision on the host, to make sure it's not communicating using ssh.

misheska commented 10 years ago

Merged to Windows 7 tree for further testing - seems to work. Great job adding more troubleshooting support to the templates - these are some excellent improvements.

Needed to change the line in install-winrm.cmd that calls "floppy/set-all-networks-to-private.ps1" to not "double-shell" Powershell in Cmd to work reliably: "cmd.exe /c powershell -File a:\fixentwork.ps1" became "powershell -File a:\fixnetwork.ps1" (This was the issue I was encountering during testing)

I also want to clean this file up some more as I don't like the clunky echoing of the ERRORLEVEL, but working is much better than non-working ;-)

Once things are settled down and finalized in the Windows 7 template, I'll flood them over to the rest.

Some other things I'm currently investigating are:

rasa commented 10 years ago

"cmd.exe /c powershell -File a:\fixentwork.ps1" became "powershell -File a:\fixnetwork.ps1" (This was the issue I was encountering during testing)

Yeah, all those cmd /cs seem unnecessary to me. Please remove as you see fit.

I also want to clean this file up some more as I don't like the clunky echoing of the ERRORLEVEL, but working is much better than non-working ;-)

Those echo ERRORLEVEL=%ERRORLEVEL%s were just to document the new code working, and should have been removed. Sorry.

I'm happy to make any changes you want in my branch, if it's easier.

misheska commented 10 years ago

Actually it does seem like some of the “cmd /c”’s are necessary. I tried removing all of them and it failed to install WinRM. So I left them in except that one Powershell ones. I haven’t had time yet to dig into why.

I love the feedback of those “ERRORLEVEL=%ERRORLEVEL%” statements - I’d just like to see if perhaps it could be done in a way that didn’t need so much duplication of code (and perhaps only print out the errorlevel when it is != 0).

You’ve done an amazing job in not only fixing the Win7 template, but also thinking more deeply and delving deeper to figure out ways to make it easier to troubleshoot the Windows template-creation work. Awesome work Ross! I love what you’ve done with moving stuff out of Autounattend.xml. Great stuff! I just want to take a refinement pass is all.

On Jan 19, 2014, at 3:11 PM, Ross Smith II notifications@github.com wrote:

"cmd.exe /c powershell -File a:\fixentwork.ps1" became "powershell -File a:\fixnetwork.ps1" (This was the issue I was encountering during testing)

Yeah, all those cmd /cs seem unnecessary to me. Please remove as you see fit.

I also want to clean this file up some more as I don't like the clunky echoing of the ERRORLEVEL, but working is much better than non-working ;-)

Those echo ERRORLEVEL=%ERRORLEVEL%s were just to document the new code working, and should have been removed. Sorry.

I'm happy to make any changes you want in my branch, if it's easier.

— Reply to this email directly or view it on GitHub.

misheska commented 10 years ago

Also building on your debugging work, I’d like to add an automated sanity check at the end to automate box verification (perhaps with serverspec). That just gives a simple thumbs-up/thumbs-down on the box by firing it up, trying to vagrant ssh in and run a few simple commands (and even better, if the box failed, dump your wonderful tracing output). I’m taking the opportunity to use the Win7 template as a testbed.

For sure, I’ll roll in your other improvements as well, like the additional ssh provider, the cygwin variable enhancements, etc. Just prioritizing.

On Jan 20, 2014, at 7:30 AM, Mischa Taylor mischataylor@gmail.com wrote:

Actually it does seem like some of the “cmd /c”’s are necessary. I tried removing all of them and it failed to install WinRM. So I left them in except that one Powershell ones. I haven’t had time yet to dig into why.

I love the feedback of those “ERRORLEVEL=%ERRORLEVEL%” statements - I’d just like to see if perhaps it could be done in a way that didn’t need so much duplication of code (and perhaps only print out the errorlevel when it is != 0).

You’ve done an amazing job in not only fixing the Win7 template, but also thinking more deeply and delving deeper to figure out ways to make it easier to troubleshoot the Windows template-creation work. Awesome work Ross! I love what you’ve done with moving stuff out of Autounattend.xml. Great stuff! I just want to take a refinement pass is all.

On Jan 19, 2014, at 3:11 PM, Ross Smith II notifications@github.com wrote:

"cmd.exe /c powershell -File a:\fixentwork.ps1" became "powershell -File a:\fixnetwork.ps1" (This was the issue I was encountering during testing)

Yeah, all those cmd /cs seem unnecessary to me. Please remove as you see fit.

I also want to clean this file up some more as I don't like the clunky echoing of the ERRORLEVEL, but working is much better than non-working ;-)

Those echo ERRORLEVEL=%ERRORLEVEL%s were just to document the new code working, and should have been removed. Sorry.

I'm happy to make any changes you want in my branch, if it's easier.

— Reply to this email directly or view it on GitHub.

rasa commented 10 years ago

I love the feedback of those “ERRORLEVEL=%ERRORLEVEL%” statements - I’d just like to see if perhaps it could be done in a way that didn’t need so much duplication of code (and perhaps only print out the errorlevel when it is != 0).

We could add something like this:

if errorlevel 1 echo ERROR: The previous command returned error %ERRORLEVEL% & exit

This will return a non-zero exit status.

If we want, we could even fail the build, by simply calling shutdown (in 00-run-all-scripts.cmd).

Adding those lines to our scripts/ batch files will also cause the build to fail, but then packer will delete the output- folder!

misheska commented 10 years ago

The other trick I was playing with was adding this to every line (remember the && (success clause) || (failure clause) syntax):

<statement> || goto :error

goto :end

:error
echo Failed with error #%errorlevel%
exit /b %errorlevel%

But that seemed too clunky.

Perhaps a modification of your code using the failure clause:

<statement> || echo ERROR: The previous command returned error %ERRORLEVEL% & exit

would be best…

On Jan 20, 2014, at 7:36 AM, Ross Smith II notifications@github.com wrote:

I love the feedback of those “ERRORLEVEL=%ERRORLEVEL%” statements - I’d just like to see if perhaps it could be done in a way that didn’t need so much duplication of code (and perhaps only print out the errorlevel when it is != 0).

We could add something like this:

if errorlevel 1 echo ERROR: The previous command returned error %ERRORLEVEL% & exit This will return a non-zero exit status.

If we want, we could even fail the build, by simply calling shutdown (in 00-run-all-scripts.cmd).

Adding those lines to our scripts/ batch files will also cause the build to fail, but then packer will delete the output folder!

— Reply to this email directly or view it on GitHub.

rasa commented 10 years ago

and even better, if the box failed, dump your wonderful tracing output

Great idea. I actually have hacked packer to allow me to upload a file to the host, by grabbing packer's http server's ip/port via

d-i preseed/late_command string \
    sed 's|.*url=\([^ ]*/\).*|\1|' /proc/cmdline >/target/var/tmp/packer-host.txt

then running

PACKER_HTTP=$(</target/var/tmp/packer-host.txt)
 curl --data-binary @${filename} --dump-header - --insecure --request POST --verbose "${PACKER_HTTP}save?name=${upload_name}" 

to upload the file to the host, before the build dies.

Unfortunately, I can't think of an elegant way to get packer's HTTP server's IP/port for a Windows build. Can you?

rasa commented 10 years ago

I really appreciate the positive feedback, thanks. I really appreciate all the work you've down to build this awesome framework!

rasa commented 10 years ago

Mischa,

You're latest commits, such as https://github.com/misheska/basebox-packer/commit/1bf435f459bab566a4923dfcbd96ce921e82b762 appear to be my work, but for some reason, it doesn't appear that the commit came from me.

Also, I don't know why, but these commits generate lots of merge conflicts when I try to merge these changes back into my clone. For example, after I merge your updates into my clone I have 195 conflicts:

$ git diff | grep '<<<<<' | wc 195 390 2925

Is there any way you can merge in my PRs in a commit, and then add your customizations, so I'm attributed, and I can merge easily?

Otherwise, I don't think we'll be able to stay in sync any more, which would be a real bummer.

Thanks,

Ross

On Mon, Jan 20, 2014 at 7:42 AM, Mischa Taylor notifications@github.comwrote:

The other trick I was playing with was adding this to every line (remember the && (success clause) || (failure clause) syntax):

|| goto :error goto :end :error echo Failed with error #%errorlevel% exit /b %errorlevel% But that seemed too clunky. Perhaps a modification of your code using the failure clause: || echo ERROR: The previous command returned error %ERRORLEVEL% & exit would be best… On Jan 20, 2014, at 7:36 AM, Ross Smith II notifications@github.com wrote: > I love the feedback of those “ERRORLEVEL=%ERRORLEVEL%” statements - I’d > just like to see if perhaps it could be done in a way that didn’t need so > much duplication of code (and perhaps only print out the errorlevel when it > is != 0). > > We could add something like this: > > if errorlevel 1 echo ERROR: The previous command returned error > %ERRORLEVEL% & exit > This will return a non-zero exit status. > > If we want, we could even fail the build, by simply calling shutdown (in > 00-run-all-scripts.cmd). > > Adding those lines to our scripts/ batch files will also cause the build > to fail, but then packer will delete the output folder! > > — > Reply to this email directly or view it on GitHub. — Reply to this email directly or view it on GitHubhttps://github.com/misheska/basebox-packer/pull/39#issuecomment-32769878 .
misheska commented 10 years ago

Sure.

It will be impossible for me to do that for what is currently in the PR queue. But, if you would please sync up with what is there now, then submit the additional stuff as modified PRs from that base, then things can be reconciled (and I’ll do a better job of syncing in the future, by trying what you suggest - merging yours, then adding my mods). There was just too much in what you originally submitted for me to easily unsnarl. I was just initially trying to add just enough to fix the Windows 7 templates, and no more, so it would be more clear what was done to fix Windows 7 code-wise, as that will need to be DRYed up later into the other templates.

I still want to add the rest, feature by feature - the Cygwin improvements, and the rest of your debugging enhancements,

Sorry I wasn’t careful about setting the author bit properly in migrating the changes from Windows 7. Will be better about that in the future.

Thanks. Apologies on this latest batch. I still want to make sure we’re all synched up, and I hope it doesn’t deter you from continuing to contribute PRs in the future.

On Jan 26, 2014, at 11:20 AM, Ross Smith II notifications@github.com wrote:

Mischa,

You're latest commits, such as https://github.com/misheska/basebox-packer/commit/1bf435f459bab566a4923dfcbd96ce921e82b762 appear to be my work, but for some reason, it doesn't appear that the commit came from me.

Also, I don't know why, but these commits generate lots of merge conflicts when I try to merge these changes back into my clone. For example, after I merge your updates into my clone I have 195 conflicts:

$ git diff | grep '<<<<<' | wc 195 390 2925

Is there any way you can merge in my PRs in a commit, and then add your customizations, so I'm attributed, and I can merge easily?

Otherwise, I don't think we'll be able to stay in sync any more, which would be a real bummer.

Thanks,

Ross

On Mon, Jan 20, 2014 at 7:42 AM, Mischa Taylor notifications@github.comwrote:

The other trick I was playing with was adding this to every line (remember the && (success clause) || (failure clause) syntax):

|| goto :error goto :end :error echo Failed with error #%errorlevel% exit /b %errorlevel% But that seemed too clunky. Perhaps a modification of your code using the failure clause: || echo ERROR: The previous command returned error %ERRORLEVEL% & exit would be best… On Jan 20, 2014, at 7:36 AM, Ross Smith II notifications@github.com wrote: > I love the feedback of those “ERRORLEVEL=%ERRORLEVEL%” statements - I’d > just like to see if perhaps it could be done in a way that didn’t need so > much duplication of code (and perhaps only print out the errorlevel when it > is != 0). > > We could add something like this: > > if errorlevel 1 echo ERROR: The previous command returned error > %ERRORLEVEL% & exit > This will return a non-zero exit status. > > If we want, we could even fail the build, by simply calling shutdown (in > 00-run-all-scripts.cmd). > > Adding those lines to our scripts/ batch files will also cause the build > to fail, but then packer will delete the output folder! > > — > Reply to this email directly or view it on GitHub. — Reply to this email directly or view it on GitHubhttps://github.com/misheska/basebox-packer/pull/39#issuecomment-32769878 . — Reply to this email directly or view it on GitHub.
misheska commented 10 years ago

Also, what you suggest in me merging, then changing should address any future author issues - as then your stuff will be clearly attributed. Again apologies for me trying to do it in one lump.

misheska commented 10 years ago

Speaking of which, please send me your personal e-mail to misheska@getchef.com. I’d like to let you know more about an upcoming project related to Packer templates that will be sponsored by Chef which will be a big new community effort. But I can’t yet share all the details publicly.

On Jan 26, 2014, at 11:42 AM, Mischa Taylor mischataylor@gmail.com wrote:

Sure.

It will be impossible for me to do that for what is currently in the PR queue. But, if you would please sync up with what is there now, then submit the additional stuff as modified PRs from that base, then things can be reconciled (and I’ll do a better job of syncing in the future, by trying what you suggest - merging yours, then adding my mods). There was just too much in what you originally submitted for me to easily unsnarl. I was just initially trying to add just enough to fix the Windows 7 templates, and no more, so it would be more clear what was done to fix Windows 7 code-wise, as that will need to be DRYed up later into the other templates.

I still want to add the rest, feature by feature - the Cygwin improvements, and the rest of your debugging enhancements,

Sorry I wasn’t careful about setting the author bit properly in migrating the changes from Windows 7. Will be better about that in the future.

Thanks. Apologies on this latest batch. I still want to make sure we’re all synched up, and I hope it doesn’t deter you from continuing to contribute PRs in the future.

On Jan 26, 2014, at 11:20 AM, Ross Smith II notifications@github.com wrote:

Mischa,

You're latest commits, such as https://github.com/misheska/basebox-packer/commit/1bf435f459bab566a4923dfcbd96ce921e82b762 appear to be my work, but for some reason, it doesn't appear that the commit came from me.

Also, I don't know why, but these commits generate lots of merge conflicts when I try to merge these changes back into my clone. For example, after I merge your updates into my clone I have 195 conflicts:

$ git diff | grep '<<<<<' | wc 195 390 2925

Is there any way you can merge in my PRs in a commit, and then add your customizations, so I'm attributed, and I can merge easily?

Otherwise, I don't think we'll be able to stay in sync any more, which would be a real bummer.

Thanks,

Ross

On Mon, Jan 20, 2014 at 7:42 AM, Mischa Taylor notifications@github.comwrote:

The other trick I was playing with was adding this to every line (remember the && (success clause) || (failure clause) syntax):

|| goto :error goto :end :error echo Failed with error #%errorlevel% exit /b %errorlevel% But that seemed too clunky. Perhaps a modification of your code using the failure clause: || echo ERROR: The previous command returned error %ERRORLEVEL% & exit would be best… On Jan 20, 2014, at 7:36 AM, Ross Smith II notifications@github.com wrote: > I love the feedback of those “ERRORLEVEL=%ERRORLEVEL%” statements - I’d > just like to see if perhaps it could be done in a way that didn’t need so > much duplication of code (and perhaps only print out the errorlevel when it > is != 0). > > We could add something like this: > > if errorlevel 1 echo ERROR: The previous command returned error > %ERRORLEVEL% & exit > This will return a non-zero exit status. > > If we want, we could even fail the build, by simply calling shutdown (in > 00-run-all-scripts.cmd). > > Adding those lines to our scripts/ batch files will also cause the build > to fail, but then packer will delete the output folder! > > — > Reply to this email directly or view it on GitHub. — Reply to this email directly or view it on GitHubhttps://github.com/misheska/basebox-packer/pull/39#issuecomment-32769878 . — Reply to this email directly or view it on GitHub.
misheska commented 10 years ago

Merged