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

SCP in SSH proxy adapter does not handle spaces in filenames correctly #260

Open
Jackenmen opened this issue Jul 25, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@Jackenmen
Copy link

Jackenmen commented Jul 25, 2024

Overview of the Issue

It appears that SDK's SSH proxy adapter (used, for example, by the Ansible plugin) does not handle spaces in filenames correctly resulting in exit code 1 from scp during the transfer. The build runs fine if the proxy is disabled.

Reproduction Steps

  1. Create a directory with build.sh with following contents:
#!/bin/bash

# cleanup previous run output
rm -f \
  example_file_with_no_spaces \
  'example file with spaces' \
  ssh_key \
  ssh_key.pub \
  meta-data \
  user-data \
  cidata.iso \
  playbook.yaml \
  repro.pkr.hcl
rm -rf output

# create files for the build
touch example_file_with_no_spaces
touch 'example file with spaces'
ssh-keygen -t rsa -q -f ssh_key -N '' -C 'packer'
echo '{}' > meta-data
echo "#cloud-config
users:
  - name: packer
    sudo: ALL=(ALL) NOPASSWD:ALL
    shell: /bin/bash
    ssh_authorized_keys:
      - $(cat ssh_key.pub)
" > user-data
genisoimage -output cidata.iso -input-charset utf-8 -volid cidata -rational-rock -joliet user-data meta-data
echo '- hosts: all
  tasks:
    - ansible.builtin.copy:
        src: example_file_with_no_spaces
        dest: /tmp/example1
    - ansible.builtin.copy:
        src: example file with spaces
        dest: /tmp/example2
' > playbook.yaml
echo 'packer {
  required_plugins {
    qemu = {
      version = "1.1.0"
      source  = "github.com/hashicorp/qemu"
    }
    ansible = {
      version = "1.1.1"
      source  = "github.com/hashicorp/ansible"
    }
  }
}

source "qemu" "ubuntu" {
  format               = "qcow2"
  disk_image           = true
  disk_size            = "10G"
  headless             = true
  iso_checksum         = "file:https://cloud-images.ubuntu.com/jammy/current/SHA256SUMS"
  iso_url              = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
  qemuargs             = [["-cdrom", "cidata.iso"]]
  ssh_username         = "packer"
  ssh_private_key_file = "ssh_key"
  vm_name              = "build.qcow2"
  output_directory     = "output"
}

build {
  sources = ["source.qemu.ubuntu"]

  provisioner "ansible" {
    playbook_file    = "playbook.yaml"
    ansible_env_vars = ["ANSIBLE_VERBOSITY=5", "ANSIBLE_DISPLAY_ARGS_TO_STDOUT=True"]
  }
}
' > repro.pkr.hcl

# run Packer
packer init repro.pkr.hcl
packer build repro.pkr.hcl
  1. Run the following commands:
chmod +x build.sh
./build.sh
  1. See the failure.

Note that as described, adding use_proxy = false to the Ansible provisioner results in a successful build.

Packer Plugin SDK version

0.5.1 (the version that the Packer Ansible plugin uses)

Operating system and Environment details

Packer ran from OS: Ubuntu Desktop 22.04.4 LTS x86_64
OS ran in Packer: Ubuntu Server 22.04.4 LTS x86_64

Log Fragments and crash.log files

https://gist.github.com/Jackenmen/bb97795a3e69709a1d7dda6cab75e07f

@Jackenmen Jackenmen added the bug Something isn't working label Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant