hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.04k stars 3.32k forks source link

Packer build with Ansible fails inside of a container #11786

Closed sc250024 closed 2 years ago

sc250024 commented 2 years ago

Community Note

Overview of the Issue

Packer has some interesting behavior when using the combo of Packer with an Ansible provisioner inside of a Docker container. Basically, a very simple build of an Ubuntu 22.04 AMI with a very simple ansible provisioner fails consistently. However, when this same build is performed outside of a container (using tools installed on my local shell), it works fine.

This could be related to Ansible itself, but I am starting this issue here.

Reproduction Steps

Start by placing the following 4 files in a directory:

Dockerfile ```dockerfile ######## # Base # ######## FROM docker.io/library/alpine:latest AS tools ARG PACKER_VERSION=1.8.0 RUN apk add --no-cache ca-certificates curl jq zip RUN curl -fsSL -O "https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip" \ && unzip "packer_${PACKER_VERSION}_linux_amd64.zip" -d /usr/bin \ && chown root:root /usr/bin/packer \ && chmod 0755 /usr/bin/packer ############ # Main App # ############ FROM docker.io/library/python:3-slim AS app # Change working dir ENV BUILD_DIR /build WORKDIR ${BUILD_DIR} # Install SSH RUN apt-get -qy update \ && apt-get -qy install --no-install-recommends openssh-client # Install Ansible RUN pip3 install --no-cache-dir ansible # Copy tools from tools stage COPY --from=tools /usr/bin/packer /usr/bin/packer RUN packer version COPY . . # Initialize Packer plugins RUN packer init . ```
docker-compose.yaml ```yaml ```

Packer version

From packer version

Simplified Packer Template

If the file is longer than a few dozen lines, please include the URL to the gist of the log or use the Github detailed format instead of posting it directly in the issue.

Operating system and Environment details

OS, Architecture, and any other information you can provide about the environment.

Log Fragments and crash.log files

Include appropriate log fragments. If the log is longer than a few dozen lines, please include the URL to the gist of the log or use the Github detailed format instead of posting it directly in the issue.

Set the env var PACKER_LOG=1 for maximum log detail.

github-actions[bot] commented 2 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.