packer-plugin-ansible icon indicating copy to clipboard operation
packer-plugin-ansible copied to clipboard

Parallel builds with provisioner only uses one build entity

Open ghost opened this issue 4 years ago • 1 comments
trafficstars

This issue was originally opened by @JKetelaar as hashicorp/packer#10477. It was migrated here as a result of the Packer plugin split. The original body of the issue is below.


Overview of the Issue

Whenever I am creating a parallel build, the Ansible provisioner uses only one build entity, in each of the tasks.

Reproduction Steps

Run Packer with an Ansible provisioner and two builders. It will run the provisioner on only one builder.

Packer version

Packer v1.6.6

Simplified Packer Buildfile

Build file

{
  "variables": {
    "hcloud_key": "{{ env `HCLOUD_KEY` }}"
  },
  "builders": [
    {
      "name": "common",
      "type": "hcloud",
      "token": "{{ user `hcloud_key` }}",
      "image": "ubuntu-20.04",
      "location": "nbg1",
      "server_type": "cpx11",
      "ssh_username": "root",
      "snapshot_name": "test-1"
    },
    {
      "name": "gocd",
      "type": "hcloud",
      "token": "{{ user `hcloud_key` }}",
      "image": "ubuntu-20.04",
      "location": "nbg1",
      "server_type": "cpx11",
      "ssh_username": "root",
      "snapshot_name": "test-2"
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "inline": [
        "/usr/bin/cloud-init status --wait"
      ]
    },
    {
      "type": "ansible",
      "playbook_file": "./playbooks/packer-debug.yml",
      "keep_inventory_file": true
    }
  ]
}

Ansible playbook (./playbooks/packer-debug.yml)

---
- hosts: all
  remote_user: root
  become: true
  tasks:
    - debug: var=ansible_all_ipv4_addresses
    - debug: var=ansible_default_ipv4.address

As you can see in the log output on line 5 and line 7 it shows two different IPs (116.203.213.239 and 116.203.51.13). If you then look on line 28, it shows that the gocd builder indeed has the right IP (116.203.213.239), though looking at line 67 it shows that also the common builder uses the gocd builder IP address.

Operating system and Environment details

Both on Ubuntu 20 and MacOS.

Log Fragments and crash.log files

https://gist.github.com/JKetelaar/6cfab554d0f24f0b4f1b653c82aadf84

ghost avatar Apr 16 '21 18:04 ghost

And this behavior is blocking parallel builds to be used with HCP Packer Registry :(

mabunixda avatar Dec 20 '23 12:12 mabunixda