hashicorp / hashicorp/packer-plugin-docker

When provisioning a docker container, it is not clear how to use the instance_id parameter in the provisioner(s)

Open
#68 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
40
Forks
29
PR merge metrics
No merged PRs in 30d

Description

#### Overview of the Issue

I have a packer file containing the following:
```
[....]
source "docker" "Test" {
image = "centos:7"
export_path = "test.tar"
}
[....]
build {
sources = ["source.docker.Test"]
provisioner "shell" {
inline = ["echo 'proxy=http://' >> /etc/yum.conf", "rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7", "yum install -y python3"]
}

provisioner "ansible" {
extra_arguments = [
"-e", "proxy_url='http://'",
"-e", "ansible_connection=docker"
]
playbook_file = "playbooks/GoldenImage.yml"
user = "root"
}
}
```

Ansible fails the first time that tries to connect to the docker container (when doing the initial host scan, called "facts gathering" in Ansible). And I suspect is because the contents of the inventory file are like
```
default ansible_host=127.0.0.1 ansible_user=root ansible_port=42779
```

By setting the host_alias parameter in ansible provisioner I can work around this situation. However, I do not get to see how can I reference the builder.instance_id variable from the config file.

### Plugin and Packer version

packer version: 1.7.4
I do not know how to get the plugin versions

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.