Prerequisites:
- Windows 10 Pro
- WLS, Ubuntu 16.04 (a.k.a.: Bash on Ubuntu on Windows)
- Hyper-V
- Packer (1.0.0, added to path)
- Ansible (2.3.0, installed on WSL)
- qemu-img (2.3.0, added to path)
- Add
ansible.cmdandansible-playbook.cmdto yourPATH - Either set
USERenvironment variable in command line or configureansible_userin packer template to the default user of th WLS
I am using the Hyper-V sample template with the sample preseed
Sample playbook: ansible-bootstrap-ubuntu-16.04.yml
"provisioners": [
{
"type": "ansible",
"playbook_file": "./ansible/ansible-bootstrap-ubuntu-16.04.yml"
}This step does not work yet: hashicorp/packer#4140 As of packer 1.0.0, There is no support for cmd/powershell step inside post-processors
Convert the vhdx into qcow2 format
"post-processors": [
{
"type": "shell-local",
"inline": ["qemu-img convert \"output-hyperv-iso\\Virtual Hard Disks\\{{user `vm_name`}}.vhdx\" -O qcow2 ubuntu-xenial.qcow2"]
}
]
@coolrazor007
After some investigating the issue was how things were being escaped. For instance double quotes were being escaped with a \ such in
packer_build_name="vm"was being automatically escaped\"vm\"but that escaping \ then got clipped by the batch script to/"vm/".Also the single quotes in the line 11 needed to be changed to double quotes
I'm sure you could reorder some of the
call setlines to not need to do as much replacement and such but I wanted to leave everything intact as much as possible.