Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
flixman opened this issue Sep 7, 2021 · 2 comments
Labels

Comments

@flixman
Copy link

flixman commented Sep 7, 2021

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://<proxy_url>' >> /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://<proxy_url>'",
      "-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

@flixman flixman added the bug label Sep 7, 2021
@flixman
Copy link
Author

flixman commented Sep 7, 2021

@azr Excuse me for naming you explicitly here. I had posted a similar bug in the packer-plugin-ansible, but my following findings have made me think I should be reporting this question about how to reference the instance_id from the packer file. This is really blocking me to continue with my work, and.... I do not know who else can I turn to. Can you/somebody give me a hand?

@andrey-rjeutski-tfs
Copy link

@flixman Does build.ID work for you? It should output container id.

  provisioner "powershell" {
    inline = ["Write-Output '${build.ID}'"]
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants