It doesn't really contradict what I say. But maybe I can explain better than the docs.
Packer has an abstraction called communicator which all provisioners uses to upload, download, and execute commands on the guest. This doesn't fit very well with Ansible since it self handles the connection.
The somewhat complex solution to this is that Packer starts a SSH proxy which Ansible connects to, the proxy in turn uses the connector.
Host | Guest
.---------------. .-----------------------. .---------.
Ansible --> | SSH Proxy |===| Connector (LXD) | ----> | Guest |
`---------------´ `----------------------´ `--------´
Unfortunately this doesn't seems to work very well with the Ansible LXD connector. But this is a work around:
Ensure that you have a recent version of Ansible (I used 2.4.3.0) which have the LXD connector plugin (check with: ansible-doc -t connection lxd).
I used Packer 1.1.3, but I think anything since 1.0 should probably work.
template.json
{
"builders": [
{
"type": "lxd",
"name": "lxd-xenial",
"image": "ubuntu-daily:xenial",
"output_image": "ubuntu-xenial",
"publish_properties": {
"description": "Trivial repackage with Packer"
}
}
],
"provisioners": [
{
"type": "shell",
"inline": [ "apt-get update && apt-get install -y python-minimal" ]
},
{
"type": "ansible",
"playbook_file": "./playbook.yml",
"extra_arguments": [ "-c", "lxd", "-i", "packer-lxd-xenial,", "-l", "packer-lxd-xenial" ]
}
]
}
playbook.yml
---
- hosts: all
tasks:
- name: Shelling
shell: echo "Hello world"