packer virtual box image failing with pywinauto

41 views
Skip to first unread message

Shubham Bansal

unread,
Jun 20, 2019, 10:50:30 AM6/20/19
to Packer
I was using a script in the provisioners of packer in windows virtual box machine, which would automate installing of windows desktop app using pywinauto. But it is not able to detect any open windows and not even able to take screenshot.
it gives error for screenshot as "OSError: screen grab failed"

Is there a way to see the provisioner script actually running in packer built machine?

Udbhav

unread,
Jun 20, 2019, 2:24:55 PM6/20/19
to packe...@googlegroups.com
Packer logs what provisioner it's running. Follow this to enable logging in packer


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/d3d4dc02-043d-4cdd-bf8d-77f49116bd67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shubham Bansal

unread,
Jun 20, 2019, 2:37:22 PM6/20/19
to Packer
I tried this, but the logs are not very clear as of why the GUI cannot be captured with packer.
Even with the headless set as false, virtual box opens but remains stuck at login screen, while the scripts are running in the console of the host machine.

Udbhav

unread,
Jun 20, 2019, 2:39:34 PM6/20/19
to packe...@googlegroups.com
Can you please provide the logs of the packer?


On Thu, Jun 20, 2019 at 11:37 AM Shubham Bansal <sbans...@gmail.com> wrote:
I tried this, but the logs are not very clear as of why the GUI cannot be captured with packer.
Even with the headless set as false, virtual box opens but remains stuck at login screen, while the scripts are running in the console of the host machine.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.

Shubham Bansal

unread,
Jun 20, 2019, 2:43:50 PM6/20/19
to Packer

virtualbox-ovf output will be in this color.


==> virtualbox-ovf: Creating floppy disk...

    virtualbox-ovf: Copying files flatly from floppy_files

    virtualbox-ovf: Copying file: ./scripts/win_auto.py

    virtualbox-ovf: Copying file: ./answer_files/Autounattend.xml

    virtualbox-ovf: Done copying files from floppy_files

    virtualbox-ovf: Collecting paths from floppy_dirs

    virtualbox-ovf: Resulting paths from floppy_dirs : []

    virtualbox-ovf: Done copying paths from floppy_dirs

==> virtualbox-ovf: Creating ephemeral key pair for SSH communicator...

==> virtualbox-ovf: Created ephemeral SSH key pair for communicator

==> virtualbox-ovf: Retrieving Guest additions

==> virtualbox-ovf: Trying /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso

==> virtualbox-ovf: Trying /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso

==> virtualbox-ovf: /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso => /Users/shubhambansal/rippling/rippling-hardware-client-tests/packer_cache/7784a55a71d48a1e9b5c487431438fef0f19d87f.iso

==> virtualbox-ovf: leaving retrieve loop for Guest additions

==> virtualbox-ovf: Retrieving OVF/OVA

==> virtualbox-ovf: Trying ../../Documents/MSEdge-Win10.ovf

==> virtualbox-ovf: Using ovf inplace

==> virtualbox-ovf: leaving retrieve loop for OVF/OVA

==> virtualbox-ovf: Importing VM: ../../Documents/MSEdge-Win10.ovf

==> virtualbox-ovf: Attaching floppy disk...

==> virtualbox-ovf: Creating forwarded port mapping for communicator (SSH, WinRM, etc) (host port 3152)

==> virtualbox-ovf: Executing custom VBoxManage commands...

    virtualbox-ovf: Executing: modifyvm packer-virtualbox-ovf-1561034336 --memory 4096

    virtualbox-ovf: Executing: modifyvm packer-virtualbox-ovf-1561034336 --cpus 2

    virtualbox-ovf: Executing: modifyvm packer-virtualbox-ovf-1561034336 --vrde on

==> virtualbox-ovf: Starting the virtual machine...

    virtualbox-ovf: The VM will be run headless, without a GUI. If you want to

    virtualbox-ovf: view the screen of the VM, connect via VRDP without a password to

    virtualbox-ovf: rdp://127.0.0.1:5961

==> virtualbox-ovf: Waiting 2m0s for boot...

==> virtualbox-ovf: Typing the boot command...

==> virtualbox-ovf: Using winrm communicator to connect: 127.0.0.1

==> virtualbox-ovf: Waiting for WinRM to become available...

    virtualbox-ovf: WinRM connected.

==> virtualbox-ovf: #< CLIXML

==> virtualbox-ovf: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S="progress" RefId="1"><TNRef RefId="0" /><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>

==> virtualbox-ovf: Connected to WinRM!

==> virtualbox-ovf: Uploading VirtualBox version info (6.0.8)

==> virtualbox-ovf: Provisioning with Powershell...

==> virtualbox-ovf: Provisioning with powershell script: ./scripts/demo.ps1

    virtualbox-ovf: Checking for elevation...

    virtualbox-ovf: in admin mode..

    virtualbox-ovf: True

==> virtualbox-ovf: Traceback (most recent call last):

==> virtualbox-ovf:   File "A:/WIN_AUTO.PY", line 5, in <module>

==> virtualbox-ovf:     screenshot = pyautogui.screenshot(r"C:Users\IEUser\Desktop\file.png")

==> virtualbox-ovf:   File "C:\Users\IEUser\AppData\Local\Programs\Python\Python37\lib\site-packages\pyscreeze\__init__.py", line 347, in _screenshot_win32

==> virtualbox-ovf:     im = ImageGrab.grab()

==> virtualbox-ovf:   File "C:\Users\IEUser\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\ImageGrab.py", line 41, in grab

==> virtualbox-ovf:     size, data = grabber()

==> virtualbox-ovf: OSError: screen grab failed

==> virtualbox-ovf: Script exited with non-zero exit status: 1.Allowed exit codes are: [0]

==> virtualbox-ovf: Step "StepProvision" failed

==> virtualbox-ovf: [c] Clean up and exit, [a] abort without cleanup, or [r] retry step (build may fail even if retry succeeds)? c

==> virtualbox-ovf: Deregistering and deleting imported VM...

==> virtualbox-ovf: Deleting output directory...

Build 'virtualbox-ovf' errored: Build was cancelled.

Cleanly cancelled builds after being interrupted.


On Friday, 21 June 2019 00:09:34 UTC+5:30, Udbhav wrote:
Can you please provide the logs of the packer?


On Thu, Jun 20, 2019 at 11:37 AM Shubham Bansal <sbans...@gmail.com> wrote:
I tried this, but the logs are not very clear as of why the GUI cannot be captured with packer.
Even with the headless set as false, virtual box opens but remains stuck at login screen, while the scripts are running in the console of the host machine.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packe...@googlegroups.com.

Jordan Borean

unread,
Jun 20, 2019, 3:40:01 PM6/20/19
to Packer
Not much you can do here, commands are run over WinRM which is run in console 0 and has no interactive console. Tools that rely on an interactive console when running over WinRM are going to have a bad time. Even if you specify headless: false that just means the actual VM Window will appear and not be hidden, this has no control over the execution on the VM side as you've noted that only the logon screen is shown.

Thanks

Jordan

Udbhav

unread,
Jun 20, 2019, 3:40:42 PM6/20/19
to packe...@googlegroups.com
I am not sure on what can be the root cause but some general comments (I am sure you would have done this but still...)
- It looks like it failed to initialize the grabber. You might want to try running the script outside the packer to see if that works.
- Are all external dependency satisfied to run the script?
- Your path seems to be wrong "C:Users\IEUser\Desktop\file.png" shouldn't it be "C:\Users\IEUser\Desktop\file.png". General recommendation is to use Public folders when you are running some automation tasks in windows.

Thanks
Udbhav

To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/290b8dae-76f0-4ee5-af98-ce6e0a5a1452%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages