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

ansible provisioner fails with "failed to transfer file" #11783

Closed
stefangweichinger opened this issue May 17, 2022 · 9 comments
Closed

ansible provisioner fails with "failed to transfer file" #11783

stefangweichinger opened this issue May 17, 2022 · 9 comments

Comments

@stefangweichinger
Copy link

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

I have a packer config using the virtualbox-iso builder for building Debian VMs.
This config uses the ansible provisioner and worked fine before.

Recently I see failed builds because the provisioning step fails:

2022/05/17 07:51:59 ui:     debian.virtualbox-iso.bullseye: failed to transfer file to /home/sgw/.ansible/tmp/ansible-local-45402qjbtzya8/tmpeyxtinre /home/vagrant/.ansible/tmp/ansible-tmp-1652766718.7643352-45407-8201740687254/AnsiballZ_setup.py:

Reproduction Steps

Run "packer build" with a packer build using the ansible provisioner.

Packer version

1.8.0

Simplified Packer Template

the part with the provisioner:

  provisioner "ansible" {
    playbook_file = "ansible/vagrant-debian-11-guest-additions.yml"
    user          = "${var.ssh_username}"
    ansible_env_vars = [
      "ANSIBLE_STDOUT_CALLBACK=debug",
      "ANSIBLE_HOST_KEY_CHECKING=False",
      "ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s'",
      "ANSIBLE_NOCOLOR=True"
      ]
    ansible_ssh_extra_args = [
      "-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa"
    ]
  }

These extra_args come from fixing an issue with ssh not able to log into the created VM.
If I comment these vars it fails as well, but with another issue around "host key type" (yes, I found the related issue, that's where my extra_vars come from).

Operating system and Environment details

Fedora 36 Workstation, VirtualBox 6.1.34

 ansible --version
ansible [core 2.12.3]
  config file = None
  configured module search path = ['/home/sgw/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/sgw/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/sgw/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/sgw/.local/bin/ansible
  python version = 3.10.4 (main, Mar 25 2022, 00:00:00) [GCC 12.0.1 20220308 (Red Hat 12.0.1-0)]
  jinja version = 3.0.3
  libyaml = True
@dklement-unity
Copy link

I've got the exact same problem on Arch Linux and it's regardless to Ansible version (tried to go back many versions installing Ansible using pip). Since Arch, just like Fedora, has more recent packages, I suspect it has something to do with other components, maybe ssh client.

local/libssh2 1.10.0-1
    A library implementing the SSH2 protocol as defined by Internet Drafts
local/openssh 9.0p1-1

I worked around the issue for now by using Debian in a Docker container.

@stefangweichinger
Copy link
Author

stefangweichinger commented May 18, 2022

@dklement-unity Thanks! You mean you run packer from the Docker container?
edit: I wonder how packer in docker might be able to talk to VirtualBox on the docker host.

@iglooom
Copy link

iglooom commented May 25, 2022

@dklement-unity yep, it is definitely openssh package. I downgraded to 8.9p1-1 and now it works fine.
For Arch it could be done by
pacman -U https://archive.archlinux.org/repos/2022/04/06/core/os/x86_64/openssh-8.9p1-1-x86_64.pkg.tar.zst

@iglooom
Copy link

iglooom commented May 25, 2022

Or you can specify --scp-extra-args '-O' for ansible like this
extra_arguments = [ "--scp-extra-args", "'-O'" ]
This option activates some sort of compatibility mode in scp since openssh >=9

@stefangweichinger
Copy link
Author

Or you can specify --scp-extra-args '-O' for ansible like this extra_arguments = [ "--scp-extra-args", "'-O'" ] This option activates some sort of compatibility mode in scp since openssh >=9

Yes, I can confirm, this works for me! Thanks a lot.

@stefangweichinger
Copy link
Author

Just tested: packer-1.8.1 does not yet fix this for me

@invidian
Copy link

I think hashicorp/packer-plugin-ansible#100 could be the root cause.

yankcrime added a commit to eschercloudai/image-builder that referenced this issue Jul 14, 2022
scp in OpenSSH 9 now uses SFTP by default, which breaks the Packer /
Ansible / SSH Proxy interaction

See hashicorp/packer-plugin-ansible#100
And hashicorp/packer#11783

Adding the `-O` flag to  the `scp` command forces the old protocol to be
used.
yankcrime added a commit to eschercloudai/image-builder that referenced this issue Jul 28, 2022
scp in OpenSSH 9 now uses SFTP by default, which breaks the Packer /
Ansible / SSH Proxy interaction

See hashicorp/packer-plugin-ansible#100
And hashicorp/packer#11783

Adding the `-O` flag to  the `scp` command forces the old protocol to be
used.
@github-actions
Copy link

This issue has been migrated to hashicorp/packer-plugin-ansible#110 due to the Packer Plugin split.

Please follow the new issue for updates.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2022
JosBritton referenced this issue in JosBritton/img-ac Oct 8, 2023
- Inject environment variables through list instead of using a script.
- Already in the .venv context from the makefile, so don't need to activate it again.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants