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"




On 3 February 2018 at 03:21, Peter Goodall <pjgood...@gmail.com> wrote:

> Hi Rickard,
>
> The documentation for LXD Ansible provisioner
> <https://www.packer.io/docs/provisioners/ansible.html> seems to
> contradict what you are saying about communication to the container being
> provisioned:
>
> "The ansible Packer provisioner runs Ansible playbooks. It dynamically
> creates an Ansible inventory file configured to use SSH, runs an SSH
> server, executes ansible-playbook, and marshals Ansible plays through the
> SSH server to the machine being provisioned by Packer. "
>
>
> I tried using the LXD communicator, but was unable to work-out what to
> call the host in the ansible playbook.
>
> As I say there are no fully worked examples I can find.  My concern is
> that the LXD gets ignored by developers because there are few reliable
> tutorials, and the tutorials don't get written because there are no users.
>
> On Saturday, January 6, 2018 at 6:27:36 PM UTC+11, Rickard von Essen wrote:
>>
>> Packer doesn't assume the LXD container is running with SSH and thus
>> doesn't know anything about a potential SSH setup. Packer uses the lxc
>> command to upload, download, and exec commands in the container. To get
>> that working with Ansible you have to use a special connection plugin, see
>> https://github.com/ansible/ansible/blob/devel/lib/ansible/
>> plugins/connection/lxd.py.
>>
>> Also see https://groups.google.com/d/msg/packer-tool/sJqMu8DgjZM/szji
>> WtXFBAAJ
>>
>> If that doesn't solve please provide your template and the output of
>> running: PACKER_LOG=1 packer build template.json
>>
>> On Saturday, January 6, 2018 at 4:22:18 AM UTC+1, Peter Goodall wrote:
>>>
>>> Thanks Rickard,
>>>
>>> "extra_arguments": ["-vvvvv"]
>>>
>>> --Peter G
>>>
>>> On Saturday, January 6, 2018 at 10:07:49 AM UTC+11, Rickard von Essen
>>> wrote:
>>>>
>>>> I think I have that somewhere, let me get back with it tomorrow.
>>>>
>>>> What's your extra_arguments to ansible?
>>>>
>>>> On Jan 5, 2018 09:09, "Peter Goodall" <pjgo...@gmail.com> wrote:
>>>>
>>>>>  also... the lxd builder runs shell commands fine remotely on the
>>>>> guest.
>>>>>
>>>>> --
>>>>> 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...@googlegroups.com.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/packer-tool/2befac29-9098-
>>>>> 4318-a03d-571664e502d9%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/packer-tool/2befac29-9098-4318-a03d-571664e502d9%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/packer-tool/dfbecf2c-fed6-4885-8e6d-d006e5314bd2%40googlegroups.com
> <https://groups.google.com/d/msgid/packer-tool/dfbecf2c-fed6-4885-8e6d-d006e5314bd2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/packer-tool/CALz9Rt9-KOPUWnLf_9CxTd9Kf60DLDHpT6ABqDvRxjBhZsjjgQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to