docker builder and ansible provisioner

145 views
Skip to first unread message

Manuel Sopena Ballesteros

unread,
Jun 8, 2021, 9:46:53 AM6/8/21
to Packer

Dear hashicorp packer community,

I am learning packer and would like to understand if it is possible to have the ansible provisioner working with docker builder. I assume I will have to bring up the ssh server on the docker container myself?

thank you very much

Wilken Rivera

unread,
Jun 9, 2021, 10:41:38 AM6/9/21
to packe...@googlegroups.com
Hi there Manuel, 

I have not used the ansible (remote) provisioner with docker so I can't speak to it directly, but since the ansible provisioner relies on SSH I believe you would be responsible for setting up an SSH server on the container along with installing a version of Ansible in order for the provisioner to work.

If you are looking to provisioner a docker container with Ansible you might want to look into the ansible-local provisioner as it does not rely on SSH access to the container, but does require that the host running Packer have a local version of Ansible installed. 

Have you seen the example build templates (https://github.com/hashicorp/packer-plugin-ansible/tree/main/example) for the Ansible plugin? 

There is a docker with ansible-local example that you might find useful https://github.com/hashicorp/packer-plugin-ansible/blob/main/example/docker-ansible-local.pkr.hcl

Please let me know if this was the information you were looking for. 

--
Wilken Rivera <d...@wilkenrivera.com>

--
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.
 
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.

Megan Marsh

unread,
Jun 9, 2021, 4:51:40 PM6/9/21
to packe...@googlegroups.com
Hi Manuel -- this isn't entirely true. The Ansible provisioner has a built-in ssh proxy server that allows you to run ansible against Docker without doing too much complicated stuff locally. 

There are a couple of "gotchas" around the ansible version, since some versions of ansible that try to do pipelineing can cause issues with the proxy adapter, but assuming you're on unix distros, this should work okay. Here's a silly/simple example template that works on my machine:

```
{
  "variables": {
    "mytopping": "mushroom"
  },
  "builders": [
    {
      "type":        "docker",
      "name":        "party parrot build",
      "image":       "williamyeh/ansible:ubuntu14.04",
      "export_path": "packer_bug",
      "run_command": [ "-d", "-i", "-t", "--entrypoint=/bin/bash", "{{.Image}}" ]
    }
  ],
  "provisioners": [
    {
      "type":  "ansible",
      "playbook_file": "./playbooks/playbook_remote.yml",
      "extra_arguments": ["--extra-vars", "pizza_toppings={{ user `mytopping`}}"]
    },
    {
      "type":  "shell",
      "inline": ["ls -alh ~"]
    }
  ]
}
```

Reply all
Reply to author
Forward
0 new messages