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

packer failing to upload script (lxc) #13296

Open
Dialgatrainer02 opened this issue Feb 10, 2025 · 0 comments
Open

packer failing to upload script (lxc) #13296

Dialgatrainer02 opened this issue Feb 10, 2025 · 0 comments
Labels

Comments

@Dialgatrainer02
Copy link

Dialgatrainer02 commented Feb 10, 2025

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

When filing a bug, please include the following headings if possible. Any
example text in this template can be deleted.

Overview of the Issue

packer infinitly hangs when trying to use the shell provisioner repeating the log lines

2025/02/10 20:58:13 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 20:58:13 Running copy command: /tmp/script_4904.sh
2025/02/10 20:58:13 packer-provisioner-shell plugin: Retryable error: Error uploading script: exit status 1

this is similar to #4500 however im using lxc and this one seemed related to the docker plugin

Reproduction Steps

install almalinux
install packer an other depenacies
attempt to build template after running packer init
see error

(i have the vm image with the error if you cant reproduce locally)

Packer version

packer version
Packer v1.12.0

Simplified Packer Template

main.pkr.hcl

packer {
  required_plugins {
    ansible = {
      source  = "github.com/hashicorp/ansible"
      version = "~> 1"
    }
    lxc = {
      source = "github.com/hashicorp/lxc"
      version = "~> 1"
    }
  }
}


source "lxc" "base" {
  config_file         = "/etc/lxc/default.conf"
  template_name       = "download"
  template_parameters = ["-d", "almalinux", "-a", "amd64", "-r", 9 ]

}

build {
    name = "default"
    sources = ["lxc.base"]


    provisioner "shell" {
        script = "./scripts/ssh.sh"
    }
}

ssh.sh

#!/bin/bash

check_dns() {
    echo "Testing DNS connectivity..."
    while ! ping -c 1 -W 2 cloudflare.com >/dev/null 2>&1; do
        # echo "DNS test failed. Retrying in 5 seconds..."
        sleep 5
    done
    echo "DNS connectivity is functional."
}

# Function to detect the package manager
detect_package_manager() {
    if command -v apt-get >/dev/null 2>&1; then
        echo "apt-get"
    elif command -v dnf >/dev/null 2>&1; then
        echo "dnf"
    elif command -v pacman >/dev/null 2>&1; then
        echo "pacman"
    elif command -v zypper >/dev/null 2>&1; then
        echo "zypper"
    else
        echo "unsupported"
    fi
}

# Function to install and enable SSH silently
install_and_enable_ssh() {
    package_manager=$(detect_package_manager)
    
    case "$package_manager" in
        apt-get)
            # echo "Detected apt-get. Installing SSH..."
            DEBIAN_FRONTEND=noninteractive sudo apt-get update -y >/dev/null 2>&1
            DEBIAN_FRONTEND=noninteractive sudo apt-get install -y openssh-server >/dev/null 2>&1
            sudo systemctl enable ssh >/dev/null 2>&1
            sudo systemctl start ssh >/dev/null 2>&1
            ;;
        dnf)
            # echo "Detected dnf. Installing SSH..."
            sudo dnf install -y openssh-server >/dev/null 2>&1
            sudo systemctl enable sshd >/dev/null 2>&1
            sudo systemctl start sshd >/dev/null 2>&1
            ;;
        pacman)
            # echo "Detected pacman. Installing SSH..."
            sudo pacman -Sy --noconfirm openssh >/dev/null 2>&1
            sudo systemctl enable sshd >/dev/null 2>&1
            sudo systemctl start sshd >/dev/null 2>&1
            ;;
        zypper)
            # echo "Detected zypper. Installing SSH..."
            sudo zypper refresh >/dev/null 2>&1
            sudo zypper --non-interactive install openssh >/dev/null 2>&1
            sudo systemctl enable sshd >/dev/null 2>&1
            sudo systemctl start sshd >/dev/null 2>&1
            ;;
        *)
            echo "Unsupported package manager: $package_manager" >&2
            exit 1
            ;;
    esac

    # echo "SSH installed and enabled successfully using $package_manager."
}

check_dns
install_and_enable_ssh

Operating system and Environment details

almalinux 9 vm on proxmox

/home/olivia/.config/packer/plugins/github.com/hashicorp/ansible/packer-plugin-ansible_v1.1.2_x5.0_linux_amd64
/home/olivia/.config/packer/plugins/github.com/hashicorp/lxc/packer-plugin-lxc_v1.0.2_x5.0_linux_amd64

Log Fragments and crash.log files

 PACKER_LOG=1 PATH=./bin/:$PATH packer build server.pkr.hcl 
2025/02/10 21:10:36 [INFO] Packer version: 1.12.0 [go1.22.9 linux amd64]
2025/02/10 21:10:36 [INFO] PACKER_CONFIG env var not set; checking the default config file path
2025/02/10 21:10:36 [INFO] PACKER_CONFIG env var set; attempting to open config file: /home/olivia/.packerconfig
2025/02/10 21:10:36 [WARN] Config file doesn't exist: /home/olivia/.packerconfig
2025/02/10 21:10:36 [INFO] Setting cache directory: /home/olivia/.cache/packer
2025/02/10 21:10:36 [TRACE] listing potential installations for "github.com/hashicorp/lxc" that match "~> 1". plugingetter.ListInstallationsOptions{PluginDirectory:"/home/olivia/.config/packer/plugins", BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"linux", ARCH:"amd64", Ext:"", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc00075a000)}}, ReleasesOnly:false}}
2025/02/10 21:10:36 [TRACE] Found the following "github.com/hashicorp/lxc" installations: [{/home/olivia/.config/packer/plugins/github.com/hashicorp/lxc/packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 v1.0.2 x5.0}]
2025/02/10 21:10:36 [INFO] found external [-packer-default-plugin-name-] builders from lxc plugin
2025/02/10 21:10:36 plugin "/home/olivia/.config/packer/plugins/github.com/hashicorp/lxc/packer-plugin-lxc_v1.0.2_x5.0_linux_amd64" does not support Protobuf, forcing use of Gob
2025/02/10 21:10:36 [TRACE] listing potential installations for "github.com/hashicorp/ansible" that match "~> 1". plugingetter.ListInstallationsOptions{PluginDirectory:"/home/olivia/.config/packer/plugins", BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"linux", ARCH:"amd64", Ext:"", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc00075a000)}}, ReleasesOnly:false}}
2025/02/10 21:10:36 [TRACE] Found the following "github.com/hashicorp/ansible" installations: [{/home/olivia/.config/packer/plugins/github.com/hashicorp/ansible/packer-plugin-ansible_v1.1.2_x5.0_linux_amd64 v1.1.2 x5.0}]
2025/02/10 21:10:36 found external [-packer-default-plugin-name- local] provisioner from ansible plugin
2025/02/10 21:10:36 [TRACE] listing potential installations for <nil> that match "". plugingetter.ListInstallationsOptions{PluginDirectory:"/home/olivia/.config/packer/plugins", BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"linux", ARCH:"amd64", Ext:"", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc00075a080)}}, ReleasesOnly:false}}
2025/02/10 21:10:36 found external [-packer-default-plugin-name- local] provisioner from ansible plugin
2025/02/10 21:10:36 [INFO] found external [-packer-default-plugin-name-] builders from lxc plugin
2025/02/10 21:10:36 [INFO] Starting external plugin /home/olivia/.config/packer/plugins/github.com/hashicorp/lxc/packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 start builder -packer-default-plugin-name-
2025/02/10 21:10:36 Starting plugin: /home/olivia/.config/packer/plugins/github.com/hashicorp/lxc/packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 []string{"/home/olivia/.config/packer/plugins/github.com/hashicorp/lxc/packer-plugin-lxc_v1.0.2_x5.0_linux_amd64", "start", "builder", "-packer-default-plugin-name-"}
2025/02/10 21:10:36 Waiting for RPC address for: /home/olivia/.config/packer/plugins/github.com/hashicorp/lxc/packer-plugin-lxc_v1.0.2_x5.0_linux_amd64
2025/02/10 21:10:36 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:36 Plugin address: unix /tmp/packer-plugin1826006976
2025/02/10 21:10:36 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:36 Waiting for connection...
2025/02/10 21:10:36 Received unix RPC address for /home/olivia/.config/packer/plugins/github.com/hashicorp/lxc/packer-plugin-lxc_v1.0.2_x5.0_linux_amd64: addr is /tmp/packer-plugin1826006976
2025/02/10 21:10:36 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:36 Serving a plugin connection...
2025/02/10 21:10:36 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:36 [TRACE] starting builder -packer-default-plugin-name-
2025/02/10 21:10:36 [DEBUG] - common: receiving ConfigSpec as gob
2025/02/10 21:10:36 [DEBUG] - common: receiving ConfigSpec as gob
2025/02/10 21:10:36 [INFO] Starting external plugin /usr/bin/packer execute packer-provisioner-shell
2025/02/10 21:10:36 Starting plugin: /usr/bin/packer []string{"/usr/bin/packer", "execute", "packer-provisioner-shell"}
2025/02/10 21:10:36 Waiting for RPC address for: /usr/bin/packer
2025/02/10 21:10:36 packer-provisioner-shell plugin: [INFO] Packer version: 1.12.0 [go1.22.9 linux amd64]
2025/02/10 21:10:36 packer-provisioner-shell plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2025/02/10 21:10:36 packer-provisioner-shell plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /home/olivia/.packerconfig
2025/02/10 21:10:36 packer-provisioner-shell plugin: [WARN] Config file doesn't exist: /home/olivia/.packerconfig
2025/02/10 21:10:36 packer-provisioner-shell plugin: [INFO] Setting cache directory: /home/olivia/.cache/packer
2025/02/10 21:10:36 Received unix RPC address for /usr/bin/packer: addr is /tmp/packer-plugin3341849075
2025/02/10 21:10:36 packer-provisioner-shell plugin: Plugin address: unix /tmp/packer-plugin3341849075
2025/02/10 21:10:36 packer-provisioner-shell plugin: Waiting for connection...
2025/02/10 21:10:36 packer-provisioner-shell plugin: Serving a plugin connection...
2025/02/10 21:10:36 packer-provisioner-shell plugin: [DEBUG] - common: sending ConfigSpec as gob
2025/02/10 21:10:36 [DEBUG] - common: receiving ConfigSpec as gob
2025/02/10 21:10:36 packer-provisioner-shell plugin: [DEBUG] - common: sending ConfigSpec as gob
2025/02/10 21:10:36 [DEBUG] - common: receiving ConfigSpec as gob
2025/02/10 21:10:36 Build debug mode: false
2025/02/10 21:10:36 Force build: false
2025/02/10 21:10:36 On error: 
default.lxc.base: output will be in this color.

2025/02/10 21:10:36 Waiting on builds to complete...
2025/02/10 21:10:36 Starting build run: default.lxc.base
2025/02/10 21:10:36 Running builder: lxc
2025/02/10 21:10:36 [INFO] (telemetry) Starting builder lxc.base
==> default.lxc.base: Creating container...
2025/02/10 21:10:36 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:36 Executing args: []string{"env", "lxc-create", "-n", "packer-base", "-t", "download", "--", "-d", "almalinux", "-a", "amd64", "-r", "9"}
2025/02/10 21:10:49 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:49 stdout: Using image from local cache
2025/02/10 21:10:49 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: Unpacking the rootfs
2025/02/10 21:10:49 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 
2025/02/10 21:10:49 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: ---
2025/02/10 21:10:49 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: You just created a Almalinux 9 x86_64 (20250209_23:08) container.
2025/02/10 21:10:49 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:49 stderr:
2025/02/10 21:10:49 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:49 Executing args: []string{"touch", "/home/olivia/.local/share/lxc/packer-base/rootfs/tmp/.tmpfs"}
2025/02/10 21:10:49 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:49 stdout:
2025/02/10 21:10:49 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:49 stderr:
2025/02/10 21:10:49 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:49 Executing args: []string{"lxc-start", "-d", "--name", "packer-base"}
2025/02/10 21:10:49 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:49 stdout:
2025/02/10 21:10:49 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:49 stderr:
2025/02/10 21:10:49 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:49 Waiting for container to finish init, up to timeout: 20s
==> default.lxc.base: Waiting for container to finish init...
2025/02/10 21:10:50 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:50 Debug runlevel exec
2025/02/10 21:10:50 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:50 Executing with lxc-attach in container: packer-base /home/olivia/.local/share/lxc/packer-base/rootfs /sbin/runlevel
2025/02/10 21:10:50 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:50 Executing lxc-attach: /bin/sh []string{"/bin/sh", "-c", "lxc-attach --name packer-base -- /bin/sh -c \"/sbin/runlevel\""}
2025/02/10 21:10:50 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:50 Current runlevel in container: ''
2025/02/10 21:10:50 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:50 Expected Runlevel 3, Got Runlevel unknown, continuing
==> default.lxc.base: Container finished init!
2025/02/10 21:10:50 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:50 Unable to load communicator config from state to populate provisionHookData
2025/02/10 21:10:50 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:50 Running the provision hook
2025/02/10 21:10:50 [INFO] (telemetry) Starting provisioner shell
2025/02/10 21:10:50 packer-provisioner-shell plugin: [DEBUG] - common: sending ConfigSpec as gob
2025/02/10 21:10:50 [DEBUG] - common: receiving ConfigSpec as gob
==> default.lxc.base: Provisioning with shell script: ./scripts/ssh.sh
2025/02/10 21:10:50 packer-provisioner-shell plugin: Opening ./scripts/ssh.sh for reading
2025/02/10 21:10:50 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:50 Uploading to rootfs: /tmp/script_8406.sh
2025/02/10 21:10:50 packer-provisioner-shell plugin: [INFO] 2248 bytes written for 'uploadData'
2025/02/10 21:10:50 [INFO] 2248 bytes written for 'uploadData'
2025/02/10 21:10:50 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:50 Running copy command: /tmp/script_8406.sh
2025/02/10 21:10:50 packer-provisioner-shell plugin: Retryable error: Error uploading script: exit status 1
2025/02/10 21:10:52 packer-provisioner-shell plugin: [INFO] 2248 bytes written for 'uploadData'
2025/02/10 21:10:52 [INFO] 2248 bytes written for 'uploadData'
2025/02/10 21:10:52 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:52 Uploading to rootfs: /tmp/script_8406.sh
2025/02/10 21:10:52 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:52 Running copy command: /tmp/script_8406.sh
2025/02/10 21:10:52 packer-provisioner-shell plugin: Retryable error: Error uploading script: exit status 1
2025/02/10 21:10:54 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:54 Uploading to rootfs: /tmp/script_8406.sh
2025/02/10 21:10:54 packer-provisioner-shell plugin: [INFO] 2248 bytes written for 'uploadData'
2025/02/10 21:10:54 [INFO] 2248 bytes written for 'uploadData'
2025/02/10 21:10:54 packer-plugin-lxc_v1.0.2_x5.0_linux_amd64 plugin: 2025/02/10 21:10:54 Running copy command: /tmp/script_8406.sh
2025/02/10 21:10:54 packer-provisioner-shell plugin: Retryable error: Error uploading script: exit status 1
2025/02/10 21:10:56 packer-plugin-lxc_v1.0.2_x5.0_linux_am
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

1 participant