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.cmd
andansible-playbook.cmd
to yourPATH
- Either set
USER
environment variable in command line or configureansible_user
in 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"]
}
]
I am trying to get this to work, but on Packer 1.7.4 it passes an argument wrapped with single quotes. This breaks when WSL tries to hand over the %args% which is also wrapped in single quotes. Any ideas on how to escape the single quotes? I tried: call set args=%%args:'=\'%%
The error in Ansible is:
main.yml: -c: line 0: unexpected EOF while looking for matching `"'
The parameter Packer is now automatically including is this: --ssh-extra-args '-o IdentitiesOnly=yes'