benwebber / packer-post-processor-vhd

:package: Packer post-processor plugin to produce Virtual Hard Disk (VHD) files
Mozilla Public License 2.0
24 stars 13 forks source link

Unable to get Plugin to proceed with installation with Packer v1.3.4 #5

Open virajamipara opened 5 years ago

virajamipara commented 5 years ago

Not working for me even after trying multiple ways:

Logs below:

==> virtualbox-iso: Deregistering and deleting VM...
==> virtualbox-iso: Pausing before cleanup of step 'StepSuppressMessages'. Press enter to continue. 
==> virtualbox-iso: Pausing before cleanup of step 'StepHTTPServer'. Press enter to continue. 
==> virtualbox-iso: Pausing before cleanup of step 'StepCreateFloppy'. Press enter to continue. 
==> virtualbox-iso: Pausing before cleanup of step 'StepOutputDir'. Press enter to continue. 
==> virtualbox-iso: Pausing before cleanup of step 'StepDownload'. Press enter to continue. 
==> virtualbox-iso: Pausing before cleanup of step 'StepDownloadGuestAdditions'. Press enter to continue. 
==> virtualbox-iso: Running post-processor: manifest
==> virtualbox-iso: Running post-processor: checksum

So, tried alternate way of installing plugin via Go but got the following error:

$ go get github.com/benwebber/packer-post-processor-vhd
# github.com/benwebber/packer-post-processor-vhd
go/src/github.com/benwebber/packer-post-processor-vhd/main.go:13:34: cannot use new(vhd.PostProcessor) (type *vhd.PostProcessor) as type packer.PostProcessor in argument to server.RegisterPostProcessor:
    *vhd.PostProcessor does not implement packer.PostProcessor (wrong type for PostProcess method)
        have PostProcess(packer.Ui, packer.Artifact) (packer.Artifact, bool, error)
        want PostProcess(context.Context, packer.Ui, packer.Artifact) (packer.Artifact, bool, bool, error)

So, maybe some changes in core Packer code has broken the interface contract here. So is it possible to know which is the latest stable Packer version with which the plugin works nicely.

Also, really thanks for this nice post-processor project. Hope I can make it work for me.

virajamipara commented 5 years ago

@attacktac If it helps, you can try the following post-processor:

    {
      "type": "shell-local",
      "inline": [
        "echo '****************************** Generating VHD file ******************************'",
        "VBoxManage clonehd <<input-file>>-disk001.vmdk --format VHD <<output-file-name>>.vhd"
      ]
    }

With VirtualBox installed/present, this should help you to generate a .vhd file from an existing .vmdk. Again, either of builders 'virtualbox-iso' or 'virtualbox-ovf' can help to generate .vmdk file.

Same thing should also be achievable via adding the above command equivalent in the 'vboxmanage_post' block as its a 'VBoxManage' command.

benwebber commented 5 years ago

Thanks for the bug report. It's very likely the internal Packer API changed. I will look at fixing this shortly.

If I recall correctly, the post-processor plugin works with 0.11. You can try that version as a temporary measure. You can download the older version from here:

https://releases.hashicorp.com/packer/

benwebber commented 5 years ago

Packer 1.4.0 introduced a breaking change to the plugin interface (https://github.com/hashicorp/packer/issues/7440, https://github.com/hashicorp/packer/issues/7581).

I updated the package for the new interface. Could you try running this pre-release version?

https://github.com/benwebber/packer-post-processor-vhd/releases/tag/v1.0.0-rc.1

virajamipara commented 5 years ago

I tried the darwin release but still could not see the post-processor 'vhd' running nor the .vhd file. I tried keeping the plugin file after renaming it to following places:

benwebber commented 5 years ago

If your Packer template is not confidential or sensitive, could you share it here or publish it in a Gist? I'd like to reproduce the issue.

virajamipara commented 5 years ago

If your Packer template is not confidential or sensitive, could you share it here or publish it in a Gist? I'd like to reproduce the issue.

Well, let me trim down my template so that its sharable. Will test it once again and will share you the template. Quick query though - is it ok to skip the 'provisioners' altogether and still expect the 'vhd' post-processor to generate .vhd from the 'virtualbox-iso' builder's .ovf/.vmdk file?

benwebber commented 5 years ago

Well, let me trim down my template so that its sharable. Will test it once again and will share you the template.

Thanks. A minimum working example (e.g., ISO → OVA → VHD) would be great.

Quick query though - is it ok to skip the 'provisioners' altogether and still expect the 'vhd' post-processor to generate .vhd from the 'virtualbox-iso' builder's .ovf/.vmdk file?

Yep, post-processors only need the build artefact. So the template only needs to contain the builders and post-processors configuration.

virajamipara commented 5 years ago

Hi, apologies for the delayed response. Here is the trimmed but complete JSON file that has workflow: ISO -> OVF -> post-processing to VHD file.

{
  "variables": {
    "iso": "http://repos.del.extreme-ix.org/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-Minimal-1810.iso",
    "checksum": "bd43d41e01c2a46b3cb23eb9139dce4b"
  },
  "builders": [
    {
      "type": "virtualbox-iso",
      "iso_url": "{{ user `iso` }}",
      "iso_checksum": "{{ user `checksum` }}",
      "iso_checksum_type": "md5",
      "vm_name": "MyCentOS7",
      "guest_os_type": "RedHat_64",
      "ssh_username": "root",
      "ssh_password": "packer",
      "ssh_port": 22,
      "ssh_wait_timeout": "600s",
      "vboxmanage": [
        ["modifyvm", "{{.Name}}", "--memory", "2048"],
        ["modifyvm", "{{.Name}}", "--cpus", "2"],
        ["modifyvm", "{{.Name}}", "--audio", "none"]
      ],
      "disk_size": "10240",
      "http_directory": "http",
      "boot_command": [
        "<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg<enter><wait>"
      ],
      "shutdown_command": "/sbin/halt -p"
    }
  ],
  "post-processors": [
    {
      "type": "vhd",
      "only": ["virtualbox-iso"],
      "force": true,
      "keep_input_artifact": true
    }
  ]
}

Also, the required http/ks.cfg is as follows (password hash is not valid in pasted code - but should not be a problem considering we just want to see build artifacts):

# Run the installer
install

# Use CDROM installation media - ISO based
cdrom

# System language
lang en_US.UTF-8

# Keyboard layouts
keyboard us

# Enable more hardware support
unsupported_hardware

# System timezone
timezone UTC

# Network information
network --bootproto=dhcp --hostname=my-linux
rootpw --plaintext packer

# Creating newuser with sudo capabilities
user --name=newuser --password=user@123 --group=wheel

# System authorization information
auth --enableshadow --passalgo=sha512 --kickstart
firewall --enabled

# Selinux in permissive mode (will be disabled by provisioners)
selinux --permissive

# System bootloader configuration
bootloader --location=mbr

# Run the text install
text

# Skip X config
skipx

# Overwrite the MBR, remove all existing partitions during the installation, zerombr performs installation automatically with no interaction, autopart automatically creates partitions
zerombr
clearpart --all --initlabel
autopart

# Do not run the Setup Agent on first boot
firstboot --disable

# Accept the EULA
eula --agreed

# Reboot the system when the install is complete
reboot

# Packages
%packages --instLangs=en_US.utf8 --nobase --ignoremissing --excludedocs
@core
wget
%end

%post --log=/root/ks.log
yum -y update
yum clean all
%end

After successful completion of packer build the artifacts generated are:

So, no VHD file got generated.

justinhauer commented 5 years ago

@benwebber any updates on this?