Packer VMware Workstation deployment to vSphere

748 views
Skip to first unread message

dlhak...@gmail.com

unread,
Oct 16, 2017, 2:11:35 PM10/16/17
to Packer
Hello All,

I'm trying to get my feet wet with using packer for template management in my vSphere environment.   I've started with a simple case following this blog ( https://theithollow.com/2017/03/06/using-packer-create-vsphere-aws-images/ ) and adjusting based on other examples I've found online.    

Using VMware workstation (trying both windows and linux as a host) on my local VM, I've attempted to use either the vmware-iso or vmware-vmx builders to create a VM within Workstation and then use the vsphere post-provisioner to distribute to my vsphere environment.  While the builders and provisioner seem to work flawlessly, the vsphere post-provisioner keeps erroring out with "Script disconnected unexpectedly" and deleting the working directory.   

ovftool is in the $PATH


Is there something I'm missing?   Is there some other method or plugin that I need here?

Example of my json:

{
    "builders": [
        {
            "type": "vmware-vmx",
            "source_path": "/root/Downloads/output-vmware-iso/test-centos.vmx",
            "ssh_username": "vagrant",
            "ssh_password": "vagrant",
            "ssh_wait_timeout": "10000s",
            "shutdown_command": "echo 'shutdown -P now' > shutdown.sh; echo 'vagrant' | sudo -S sh 'shutdown.sh'"
        }],
    "provisioners": [
        {
            "type": "shell",
            "inline":
            [
                "sleep 30",
                "sudo yum -y update ",
                "sudo yum -y install git",
                "sudo touch ~/I_DID_MORE_THINGS",
                "sudo shutdown -h now"
            ]
        }],
        "post-processors": [
            {
                "type": "vsphere",
                "host": "vCenter-hostname",
                "username": "vCenter-user",
                "password": "vCenter-password",
                "cluster": "CLUSTERNAME",
                "datacenter": "DATACENTERNAME",
                "resource_pool": "RPNAME",
                "datastore": "DATASTORENAME",
                "vm_folder": "FOLDER",
                "vm_name": "test1",
                "vm_network": "PORTGROUP",
                "disk_mode": "thin",
                "insecure": "true"
            }
        ]

}

Alvaro Miranda Aguilera

unread,
Oct 16, 2017, 11:39:37 PM10/16/17
to packe...@googlegroups.com
can you share a verbose log and the error ?

set this var
PACKER_LOG=1

Alvaro

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/db842bd2-ba62-4169-8468-fb8bd9154048%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

dlhak...@gmail.com

unread,
Oct 17, 2017, 2:42:07 AM10/17/17
to Packer
I really appreciate the assistance.    Full output is attached.   

End of the output is:

......
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 [INFO] Attempting SSH connection...
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 reconnecting to TCP connection for SSH
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 handshaking with SSH
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 handshake complete!
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 opening new ssh session
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 [INFO] agent forwarding enabled
2017/10/17 02:36:13 ui: ==> vmware-vmx: Connected to SSH!
==> vmware-vmx: Connected to SSH!
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 Running the provision hook
2017/10/17 02:36:13 [INFO] (telemetry) Starting provisioner shell
2017/10/17 02:36:13 ui: ==> vmware-vmx: Provisioning with shell script: /tmp/packer-shell888268440
==> vmware-vmx: Provisioning with shell script: /tmp/packer-shell888268440
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 Opening /tmp/packer-shell888268440 for reading
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 [INFO] 118 bytes written for 'uploadData'
2017/10/17 02:36:13 [INFO] 118 bytes written for 'uploadData'
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 opening new ssh session
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 Starting remote scp process:  scp -vt /tmp
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 Started SCP session, beginning transfers...
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 Copying input data into temporary file so we can read the length
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 [DEBUG] scp: Uploading script_3281.sh: perms=C0644 size=118
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 SCP session complete, closing stdin pipe.
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 Waiting for SSH session to complete.
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 scp stderr (length 31): Sink: C0644 118 script_3281.sh
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 opening new ssh session
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 starting remote command: chmod 0755 /tmp/script_3281.sh
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 [INFO] RPC endpoint: Communicator ended with: 0
2017/10/17 02:36:13 [INFO] RPC client: Communicator ended with: 0
2017/10/17 02:36:13 [INFO] RPC endpoint: Communicator ended with: 0
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 [INFO] RPC client: Communicator ended with: 0
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 opening new ssh session
2017/10/17 02:36:13 packer: 2017/10/17 02:36:13 starting remote command: chmod +x /tmp/script_3281.sh; PACKER_BUILDER_TYPE='vmware-vmx' PACKER_BUILD_NAME='vmware-vmx'  /tmp/script_3281.sh
2017/10/17 02:36:44 ui:     vmware-vmx: Loaded plugins: fastestmirror
    vmware-vmx: Loaded plugins: fastestmirror
2017/10/17 02:36:44 ui:     vmware-vmx: Loading mirror speeds from cached hostfile
    vmware-vmx: Loading mirror speeds from cached hostfile
2017/10/17 02:36:44 ui:     vmware-vmx:  * base: centos.mirror.colo-serv.net
    vmware-vmx:  * base: centos.mirror.colo-serv.net
2017/10/17 02:36:44 ui:     vmware-vmx:  * extras: centos.mirror.netelligent.ca
    vmware-vmx:  * extras: centos.mirror.netelligent.ca
2017/10/17 02:36:44 ui:     vmware-vmx:  * updates: centos.mirror.netelligent.ca
    vmware-vmx:  * updates: centos.mirror.netelligent.ca
2017/10/17 02:36:45 ui:     vmware-vmx: No packages marked for update
    vmware-vmx: No packages marked for update
2017/10/17 02:36:45 ui:     vmware-vmx: Loaded plugins: fastestmirror
    vmware-vmx: Loaded plugins: fastestmirror
2017/10/17 02:36:45 ui:     vmware-vmx: Loading mirror speeds from cached hostfile
    vmware-vmx: Loading mirror speeds from cached hostfile
2017/10/17 02:36:45 ui:     vmware-vmx:  * base: centos.mirror.colo-serv.net
    vmware-vmx:  * base: centos.mirror.colo-serv.net
2017/10/17 02:36:45 ui:     vmware-vmx:  * extras: centos.mirror.netelligent.ca
    vmware-vmx:  * extras: centos.mirror.netelligent.ca
2017/10/17 02:36:45 ui:     vmware-vmx:  * updates: centos.mirror.netelligent.ca
    vmware-vmx:  * updates: centos.mirror.netelligent.ca
2017/10/17 02:36:46 ui:     vmware-vmx: Package git-1.8.3.1-12.el7_4.x86_64 already installed and latest version
    vmware-vmx: Package git-1.8.3.1-12.el7_4.x86_64 already installed and latest version
2017/10/17 02:36:46 ui:     vmware-vmx: Nothing to do
    vmware-vmx: Nothing to do
2017/10/17 02:36:46 packer: 2017/10/17 02:36:46 Remote command exited without exit status or exit signal.
2017/10/17 02:36:46 packer: 2017/10/17 02:36:46 [INFO] RPC endpoint: Communicator ended with: 2300218
2017/10/17 02:36:46 [INFO] 499 bytes written for 'stdout'
2017/10/17 02:36:46 [INFO] 0 bytes written for 'stderr'
2017/10/17 02:36:46 [INFO] RPC client: Communicator ended with: 2300218
2017/10/17 02:36:46 [INFO] RPC endpoint: Communicator ended with: 2300218
2017/10/17 02:36:46 packer: 2017/10/17 02:36:46 [INFO] 499 bytes written for 'stdout'
2017/10/17 02:36:46 packer: 2017/10/17 02:36:46 [INFO] 0 bytes written for 'stderr'
2017/10/17 02:36:46 packer: 2017/10/17 02:36:46 [INFO] RPC client: Communicator ended with: 2300218
2017/10/17 02:36:46 [INFO] (telemetry) ending shell
2017/10/17 02:36:46 [INFO] (telemetry) found error: Script disconnected unexpectedly.
2017/10/17 02:36:46 packer: 2017/10/17 02:36:46 Executing: /usr/bin/vmrun [-T ws list]
2017/10/17 02:36:46 packer: 2017/10/17 02:36:46 stdout: Total running VMs: 1
2017/10/17 02:36:46 packer: /root/Downloads/testdir/packer-vmware-vmx-1508222149.vmx
2017/10/17 02:36:46 packer: 2017/10/17 02:36:46 stderr:
2017/10/17 02:36:46 ui: ==> vmware-vmx: Stopping virtual machine...
==> vmware-vmx: Stopping virtual machine...
2017/10/17 02:36:46 packer: 2017/10/17 02:36:46 Executing: /usr/bin/vmrun [-T ws stop testdir/packer-vmware-vmx-1508222149.vmx hard]
2017/10/17 02:36:47 packer: 2017/10/17 02:36:47 stdout:
2017/10/17 02:36:47 packer: 2017/10/17 02:36:47 stderr:
2017/10/17 02:36:47 ui: ==> vmware-vmx: Deleting output directory...
==> vmware-vmx: Deleting output directory...
2017/10/17 02:36:47 [INFO] (telemetry) ending vmware-vmx
2017/10/17 02:36:47 [INFO] (telemetry) found error: Script disconnected unexpectedly.
2017/10/17 02:36:47 ui error: Build 'vmware-vmx' errored: Script disconnected unexpectedly.
2017/10/17 02:36:47 Builds completed. Waiting on interrupt barrier...
2017/10/17 02:36:47 machine readable: error-count []string{"1"}
2017/10/17 02:36:47 ui error: 
==> Some builds didn't complete successfully and had errors:
2017/10/17 02:36:47 machine readable: vmware-vmx,error []string{"Script disconnected unexpectedly."}
2017/10/17 02:36:47 ui error: --> vmware-vmx: Script disconnected unexpectedly.
2017/10/17 02:36:47 ui: 
==> Builds finished but no artifacts were created.
Build 'vmware-vmx' errored: Script disconnected unexpectedly.

==> Some builds didn't complete successfully and had errors:
--> vmware-vmx: Script disconnected unexpectedly.

==> Builds finished but no artifacts were created.
2017/10/17 02:36:48 waiting for all plugin processes to complete...
2017/10/17 02:36:48 /root/Downloads/packer: plugin process exited
2017/10/17 02:36:48 /root/Downloads/packer: plugin process exited
2017/10/17 02:36:48 /root/Downloads/packer: plugin process exited
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.



--
Alvaro

packer_output.txt

Rickard von Essen

unread,
Oct 17, 2017, 3:18:11 AM10/17/17
to packe...@googlegroups.com
2300218 is a canary value set when SSH is disconnected without the server closing the channel. Usually this happens when you restart/upgrade sshd or reboots in a script. See https://www.packer.io/docs/provisioners/shell.html#expect_disconnect

expect_disconnect should only be set  to true if you understand why the disconnect is happening.

// Rickard

To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/0ccde473-e899-49a7-ad5a-3af4e217e96d%40googlegroups.com.

Alvaro Miranda Aguilera

unread,
Oct 17, 2017, 9:27:20 AM10/17/17
to packe...@googlegroups.com
Ok

The output shows the buikd failed from packer point of view

the issue is here\

                "sudo shutdown -h now"

you shoudln't do that

there is a section in the configuration that after all the provisioners are done, will continue with poweroff


    "builders": [
        {
..
            "shutdown_command": "echo 'shutdown -P now' > shutdown.sh; echo 'vagrant' | sudo -S sh 'shutdown.sh'"
        }],

So the shutdown in the provisining is causing the problems

Alvaro

To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/0ccde473-e899-49a7-ad5a-3af4e217e96d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alvaro

dlhak...@gmail.com

unread,
Oct 17, 2017, 10:56:44 AM10/17/17
to Packer
I've tried removing the "sudo shutdown -h now" line from the provisioner and I'm still getting errors where the run isn't completing.  

2017/10/17 10:51:59 packer: 2017/10/17 10:51:59 Writing VMX to: testdir/packer-vmware-vmx-1508251834.vmx
2017/10/17 10:51:59 ui: ==> vmware-vmx: Cleaning VMX prior to finishing up...
==> vmware-vmx: Cleaning VMX prior to finishing up...
2017/10/17 10:51:59 ui:     vmware-vmx: Unmounting floppy from VMX...
    vmware-vmx: Unmounting floppy from VMX...
2017/10/17 10:51:59 packer: 2017/10/17 10:51:59 Deleting key: floppy0.present
2017/10/17 10:51:59 ui:     vmware-vmx: Disabling VNC server...
    vmware-vmx: Disabling VNC server...
2017/10/17 10:51:59 packer: 2017/10/17 10:51:59 Writing VMX to: testdir/packer-vmware-vmx-1508251834.vmx
2017/10/17 10:51:59 packer: 2017/10/17 10:51:59 Executing: /usr/bin/vmrun [-T ws list]
2017/10/17 10:51:59 packer: 2017/10/17 10:51:59 stdout: Total running VMs: 0
2017/10/17 10:51:59 packer: 2017/10/17 10:51:59 stderr:
2017/10/17 10:51:59 [INFO] (telemetry) ending vmware-vmx
2017/10/17 10:51:59 ui: ==> vmware-vmx: Running post-processor: vsphere
2017/10/17 10:51:59 [INFO] (telemetry) Starting post-processor vsphere
==> vmware-vmx: Running post-processor: vsphere
2017/10/17 10:51:59 ui:     vmware-vmx (vsphere): Uploading testdir/packer-vmware-vmx-1508251834.vmx to vSphere
    vmware-vmx (vsphere): Uploading testdir/packer-vmware-vmx-1508251834.vmx to vSphere
2017/10/17 10:51:59 packer: 2017/10/17 10:51:59 Starting ovftool with parameters: --acceptAllEulas --name=test1 --datastore=TN2PCA016BMA167 --noSSLVerify=true --diskMode=thin --vmFolder=LYNCHD --network=TN2PMA018VL1202VST-CA testdir/packer-vmware-vmx-1508251834.vmx vi://administrator%40vsphere.local:<password>@TN2PCA012VCS001.ca01.vs-xstream.local/TN2PCA01/host/TN2PCA01MA/Resources/TN2PMA01PMALYNCH
2017/10/17 10:51:59 [INFO] (telemetry) ending vsphere
2017/10/17 10:51:59 [INFO] (telemetry) found error: Failed: exit status 1
2017/10/17 10:51:59 Deleting original artifact for build 'vmware-vmx'
Build 'vmware-vmx' errored: 1 error(s) occurred:
2017/10/17 10:52:00 ui error: Build 'vmware-vmx' errored: 1 error(s) occurred:

* Post-processor failed: Failed: exit status 1

2017/10/17 10:52:00 Builds completed. Waiting on interrupt barrier...
2017/10/17 10:52:00 machine readable: error-count []string{"1"}
2017/10/17 10:52:00 ui error: 
==> Some builds didn't complete successfully and had errors:
2017/10/17 10:52:00 machine readable: vmware-vmx,error []string{"1 error(s) occurred:\n\n* Post-processor failed: Failed: exit status 1\n"}
2017/10/17 10:52:00 ui error: --> vmware-vmx: 1 error(s) occurred:

* Post-processor failed: Failed: exit status 1
2017/10/17 10:52:00 ui: 
==> Builds finished but no artifacts were created.

* Post-processor failed: Failed: exit status 1


==> Some builds didn't complete successfully and had errors:
--> vmware-vmx: 1 error(s) occurred:

* Post-processor failed: Failed: exit status 1


==> Builds finished but no artifacts were created.
2017/10/17 10:52:00 waiting for all plugin processes to complete...
2017/10/17 10:52:00 /root/Downloads/packer: plugin process exited
2017/10/17 10:52:00 /root/Downloads/packer: plugin process exited
2017/10/17 10:52:00 /root/Downloads/packer: plugin process exited




--
Alvaro

packer_output_shutdown-removal.txt

Alvaro Miranda Aguilera

unread,
Oct 17, 2017, 11:06:13 AM10/17/17
to packe...@googlegroups.com
Hello

From here find a valid vmx file and try to run this command manually.

packer is running this for you, but if fails better try out packer to find why is failing:

dlhak...@gmail.com

unread,
Oct 17, 2017, 4:08:52 PM10/17/17
to Packer
All,

I figured out what the remaining issue was.   Turns out that there was a firewall blocking the traffic between packer and vCenter. 

Thank you all so much for your help.      
Reply all
Reply to author
Forward
0 new messages