hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.31k stars 4.43k forks source link

Windows host not respecting Unix file format #8333

Closed lordgordon closed 7 years ago

lordgordon commented 7 years ago

Hi there,

I have a Windows 10 host and I'm unable to provision my FreeBSD guest using shell script (bash format). The script is not executed due to invalid syntax. Yet, everything is working fine on my macOS host.

In fact the shell script loaded with Windows as host is different from the original one I have with macOS as host (different shasum --binary). With an hex editor I see different line termination characters.

Shared folder in Windows is done with rsync.

Vagrant version

Vagrant 1.9.1

Host operating system

Windows 10 home (fully updated) Rsync (cwRsync) version 3.1.2 protocol version 31.

Capabilities:
   64-bit files, 64-bit inums, 32-bit timestamps, 64-bit long ints,
   socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
   append, ACLs, no xattrs, iconv, symtimes, prealloc

Guest operating system

FreeBSD 11.0-STABLE

Vagrantfile

 -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version ">= 1.9"

Vagrant.configure(2) do |config|
  config.vm.define "win", autostart: false do |win|
    win.vm.box = "freebsd/FreeBSD-11.0-STABLE"
  end

  config.ssh.shell = "sh"
  config.ssh.insert_key = true

  # specific for FreeBSD
  config.vm.guest = :freebsd
  config.vm.base_mac = "080027D14C66"
  config.vm.hostname = "main"
  config.vm.box_check_update = false
  config.vm.boot_timeout = 1200

  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "private_network", ip: "192.168.1.42"

  config.vm.synced_folder "../", "/vagrant", type: "rsync", id:"vagrant-rsync",
    rsync__exclude: [".git/", ".idea/", "output/", "doc/build/"]

  config.vm.provider "virtualbox" do |vb|
      vb.customize ["modifyvm", :id, "--memory", "512"]
      vb.customize ["modifyvm", :id, "--cpus", "1"]
      vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
      vb.customize ["modifyvm", :id, "--audio", "none"]
      vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
      vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
  end

  # PROVISIONING (ALWAYS)
  config.vm.provision "shell", inline: "/usr/local/bin/bash /vagrant/provisioning_local/scripts/always/system_update.sh", privileged: false, run: "always"
end

Vagrant output

Bringing machine 'win' up with 'virtualbox' provider...
==> win: Clearing any previously set forwarded ports...
==> win: Clearing any previously set network interfaces...
==> win: Preparing network interfaces based on configuration...
    win: Adapter 1: nat
    win: Adapter 2: hostonly
==> win: Forwarding ports...
    win: 80 (guest) => 8080 (host) (adapter 1)
    win: 22 (guest) => 2222 (host) (adapter 1)
==> win: Running 'pre-boot' VM customizations...
==> win: Booting VM...
==> win: Waiting for machine to boot. This may take a few minutes...
    win: SSH address: 127.0.0.1:2222
    win: SSH username: vagrant
    win: SSH auth method: private key
==> win: Machine booted and ready!
Sorry, don't know how to check guest version of Virtualbox Guest Additions on this platform. Stopping installation.
==> win: Checking for guest additions in VM...
==> win: Setting hostname...
==> win: Configuring and enabling network interfaces...
==> win: Rsyncing folder: /cygdrive/e/.../repository-root/ => /vagrant
==> win:   - Exclude: [".vagrant/", ".git/", ".idea/", "output/", "doc/build/"]
==> win: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> win: flag to force provisioning. Provisioners marked to run always will still run.
==> win: Running provisioner: shell...
    win: Running: inline script
==> win: /vagrant/provisioning_local/scripts/always/system_update.sh: line 2: $'\r': command not found
==> win: /vagrant/provisioning_local/scripts/always/system_update.sh: line 13: $'\r': command not found
==> win: /vagrant/provisioning_local/scripts/always/system_update.sh: line 15: $'\r': command not found
==> win: /vagrant/provisioning_local/scripts/always/system_update.sh: line 16: $'\r': command not found
==> win: /vagrant/provisioning_local/scripts/always/system_update.sh: line 20: $'\r': command not found
==> win: /vagrant/provisioning_local/scripts/always/system_update.sh: line 21: syntax error near unexpected token `$'{\r''
'=> win: /vagrant/provisioning_local/scripts/always/system_update.sh: line 21: `update_configs() {
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

Expected behavior

The shell provisioning should be executed without issues.

Actual behavior

The shell provisioning fails due to improper file format.

Steps to reproduce

  1. set up Vagrant with the provided configuration file;
  2. vagrant up;

References

chrisroberts commented 7 years ago

Hi there. The issue stems from the newline characters used within the shell script being executed (which is different depending on the host system). If you use the path option instead of inline, Vagrant can automatically convert these for you. For more information see:

https://www.vagrantup.com/docs/provisioning/shell.html#binary

Cheers!

lordgordon commented 7 years ago

@chrisbaldauf

Hi Chris,

thank for your suggestion. I tried it yet I still have the bug. I also tried to add the option to the "file" provisioning, yet the binary option is not supported.

Vagrant version: 1.9.1 Host: Windows 10

Vagrantfile (interesting line):

config.vm.provision "shell", inline: "/usr/local/bin/bash /vagrant/provisioning_local/scripts/always/system_update.sh", privileged: false, run: "always", binary: true

I'm now going to upgrade to Vagrant 1.9.3 and I let you know if the issue persists.

Regards,

Nicholas

ghost commented 4 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.