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

Multiple provisioning scripts always runs the first script on Windows #7614

Closed
chingc opened this issue Jul 20, 2016 · 24 comments
Closed

Multiple provisioning scripts always runs the first script on Windows #7614

chingc opened this issue Jul 20, 2016 · 24 comments

Comments

@chingc
Copy link

chingc commented Jul 20, 2016

I'm running vagrant 1.8.4 on OS X El Capitan, and I'm trying to run provisioning scripts on a IE11 Windows 7 VM downloaded from Modern.IE.

I've ran into a problem where it appears that if you attempt to run multiple provisioning scripts it will just repeatedly run the first script it finds. This doesn't happen on a Linux guest.

For example...

Provisioning Scripts

provision/greet_1.bat
echo Hello
provision/greet_2.bat
echo World

Vagrantfile

# provisioning section
Dir.glob("provision/*.bat").each do |script|
  config.vm.provision "shell", path: script
end

Output

==> default: Running provisioner: shell...
    default: Running: provision/greet_1.bat as c:\tmp\vagrant-shell.bat
==> default: C:\Windows\system32>echo Hello
==> default: Hello
==> default: Running provisioner: shell...
    default: Running: provision/greet_2.bat as c:\tmp\vagrant-shell.bat
==> default: C:\Windows\system32>echo Hello
==> default: Hello

Expected behavior

greet_2.bat should have echoed World

Actual behavior

Output indicates greet_2.bat is running but clearly greet_1.bat is being re-run somehow.

This problem doesn't happen on a Linux guest.

Workaround

Combine multiple scripts into one.

Gist

Debug Output
Vagrantfile

@sethvargo
Copy link
Contributor

Hi @chingc

Thank you for opening an issue. This seems rather odd. Can you please share the debug output?

@chingc
Copy link
Author

chingc commented Jul 21, 2016

Thanks for getting back to me so quickly @sethvargo

Here's the debug output.

@sethvargo
Copy link
Contributor

And can you please supply your complete Vagrantfile?

@chingc
Copy link
Author

chingc commented Jul 21, 2016

Here you go: Vagrantfile

@bl4ckcontact
Copy link

I'm seeing this same thing. If I manage to delete the C:\tmp\vagrant-shell.ps1 before any of the succeeding scripts can run, it will run the correct script. It appears to have something to do with overwriting the existing vagrant-shell.ps1 file.

@dragon788
Copy link
Contributor

Your loop is what is causing the issue, there is a warning in the documentation about the evaluation order. You will probably want to simply upload a directory of scripts and trigger a "scheduler" script to run them if you need a specific order.

@chingc
Copy link
Author

chingc commented Aug 10, 2016

I'm not concerned about the order. The problem is it's running the same script repeatedly even though the stdout status messages are indicating otherwise.

@bl4ckcontact
Copy link

Ching, I'm seeing this same thing, but I noticed that it's only occurring
on my 2008R2 box, and not on 2012R2. What version of Windows are you
testing this on?

On Wed, Aug 10, 2016 at 12:04 PM, Ching Chow notifications@github.com
wrote:

I'm not concerned about the order. The problem is it's running the same
script repeatedly even though the stdout status messages are indicating
otherwise.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#7614 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AG6z2li7lBU6VHRTfjoOwgrULRqup2Mmks5qeiCkgaJpZM4JQ6Qf
.

@chingc
Copy link
Author

chingc commented Aug 10, 2016

@bl4ckcontact I was using the Windows 7 IE 11 Vagrant image from modern.ie.

@jbarnett-r7
Copy link

I'm hitting the same issue on Vagrant 1.8.5 on OSX El Capitan while provisioning a Windows 2008 R2 box using VirtualBox. I'm not using any loops, just simple shell calls running a script.

My VagrantFile:

Vagrant.configure("2") do |config|
  config.vm.box = "metasploitable3"
  config.vm.hostname = "metasploitable3"
  config.vm.communicator = "winrm"

  config.vm.provision :shell, path: "scripts/main.cmd"

  config.vm.provision :reload

  config.vm.provision :shell, path: "scripts/install_boxstarter.bat"

  config.vm.provision :shell, path: "scripts/chocolatey_installs/java.bat"
  config.vm.provision :shell, path: "scripts/chocolatey_installs/tomcat.bat"
end

My output:

==> default: Running provisioner: shell...
    default: Running: scripts/install_boxstarter.bat as c:\tmp\vagrant-shell.bat
==> default: C:\Windows\system32>chocolatey feature enable -n=allowGlobalConfirmation 
==> default: Enabled allowGlobalConfirmation
==> default: 
==> default: 
==> default: C:\Windows\system32>choco install BoxStarter 
==> default: Installing the following packages:
==> default: 
==> default: BoxStarter
==> default: By installing you accept licenses for the packages.
==> default: BoxStarter.Common v2.8.29 [Approved]
==> default: C:\Users\vagrant\AppData\Roaming\Boxstarter
==> default: C:\Users\vagrant\AppData\Roaming\Boxstarter\BuildPackages
==> default: The Boxstarter.Common Module has been copied to C:\Users\vagrant\AppData\Roaming\Boxstarter and added to your Module path. 
==> default: 
==> default: You will need to open a new console for the path to be visible.
==> default: Use 'Get-Module Boxstarter.* -ListAvailable' to list all Boxstarter Modules.
==> default: To list all available Boxstarter Commands, use:
==> default: PS:>Import-Module Boxstarter.Common
==> default: PS:>Get-Command -Module Boxstarter.*
==> default: 
==> default: To find more info visit http://Boxstarter.org or use:
==> default: 
==> default: PS:>Import-Module Boxstarter.Common
==> default: PS:>Get-Help Boxstarter
==> default: Environment Vars (like PATH) have changed. Close/reopen your shell to
==> default: 
==> default:  see the changes (or in powershell/cmd.exe just type `refreshenv`).
==> default:  The install of boxstarter.common was successful.
==> default: 
==> default:   Software install location not explicitly set, could be in package or 
==> default:   default install location if installer.
==> default: 
==> default: BoxStarter.WinConfig v2.8.29 [Approved]
==> default: The Boxstarter.WinConfig Module has been copied to C:\Users\vagrant\AppData\Roaming\Boxstarter and added to your Module path. 
==> default: 
==> default: You will need to open a new console for the path to be visible.
==> default: Use 'Get-Module Boxstarter.* -ListAvailable' to list all Boxstarter Modules.
==> default: To list all available Boxstarter Commands, use:
==> default: PS:>Import-Module Boxstarter.WinConfig
==> default: PS:>Get-Command -Module Boxstarter.*
==> default: 
==> default: To find more info visit http://Boxstarter.org or use:
==> default: PS:>Import-Module Boxstarter.WinConfig
==> default: 
==> default: PS:>Get-Help Boxstarter
==> default: Environment Vars (like PATH) have changed. Close/reopen your shell to
==> default:  see the changes (or in powershell/cmd.exe just type `refreshenv`).
==> default:  The install of boxstarter.winconfig was successful.
==> default:   Software install location not explicitly set, could be in package or 
==> default:   default install location if installer.
==> default: 
==> default: boxstarter.bootstrapper v2.8.29 [Approved]
==> default: The Boxstarter.Bootstrapper Module has been copied to C:\Users\vagrant\AppData\Roaming\Boxstarter and added to your Module path. 
==> default: 
==> default: You will need to open a new console for the path to be visible.
==> default: Use 'Get-Module Boxstarter.* -ListAvailable' to list all Boxstarter Modules.
==> default: To list all available Boxstarter Commands, use:
==> default: PS:>Import-Module Boxstarter.Bootstrapper
==> default: PS:>Get-Command -Module Boxstarter.*
==> default: 
==> default: To find more info visit http://Boxstarter.org or use:
==> default: PS:>Import-Module Boxstarter.Bootstrapper
==> default: PS:>Get-Help Boxstarter
==> default:  The install of boxstarter.bootstrapper was successful.
==> default:   Software install location not explicitly set, could be in package or 
==> default:   default install location if installer.
==> default: 
==> default: boxstarter.chocolatey v2.8.29 [Approved]
==> default: The Boxstarter.Chocolatey Module has been copied to C:\Users\vagrant\AppData\Roaming\Boxstarter and added to your Module path. 
==> default: 
==> default: You will need to open a new console for the path to be visible.
==> default: Use 'Get-Module Boxstarter.* -ListAvailable' to list all Boxstarter Modules.
==> default: To list all available Boxstarter Commands, use:
==> default: PS:>Import-Module Boxstarter.Chocolatey
==> default: 
==> default: PS:>Get-Command -Module Boxstarter.*
==> default: 
==> default: To find more info visit http://Boxstarter.org or use:
==> default: PS:>Import-Module Boxstarter.Chocolatey
==> default: PS:>Get-Help Boxstarter
==> default: C:\Users\vagrant\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Boxstarter
==> default:  The install of boxstarter.chocolatey was successful.
==> default:   Software install location not explicitly set, could be in package or 
==> default:   default install location if installer.
==> default: 
==> default: Boxstarter.HyperV v2.8.29 [Approved]
==> default: The Boxstarter.HyperV Module has been copied to C:\Users\vagrant\AppData\Roaming\Boxstarter and added to your Module path. 
==> default: 
==> default: You will need to open a new console for the path to be visible.
==> default: Use 'Get-Module Boxstarter.* -ListAvailable' to list all Boxstarter Modules.
==> default: To list all available Boxstarter Commands, use:
==> default: PS:>Import-Module Boxstarter.HyperV
==> default: PS:>Get-Command -Module Boxstarter.*
==> default: 
==> default: To find more info visit http://Boxstarter.org or use:
==> default: PS:>Import-Module Boxstarter.HyperV
==> default: PS:>Get-Help Boxstarter
==> default:  The install of boxstarter.hyperv was successful.
==> default:   Software install location not explicitly set, could be in package or 
==> default:   default install location if installer.
==> default: 
==> default: boxstarter v2.8.29 [Approved]
==> default: To load all Boxstarter Modules immediately, just enter 'BoxstarterShell'.
==> default: 
==> default: Interested in Windows Azure VM integration? Run CINST Boxstarter.Azure to install Boxstarter's Azure integration.
==> default:  The install of boxstarter was successful.
==> default:   Software install location not explicitly set, could be in package or 
==> default:   default install location if installer.
==> default: 
==> default: Chocolatey installed 6/6 packages. 0 packages failed.
==> default: 
==> default:  See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
==> default: 
==> default: Installed:
==> default:  - boxstarter.bootstrapper v2.8.29
==> default:  - boxstarter.hyperv v2.8.29
==> default:  - boxstarter.winconfig v2.8.29
==> default:  - boxstarter v2.8.29
==> default:  - boxstarter.chocolatey v2.8.29
==> default:  - boxstarter.common v2.8.29
==> default: C:\Windows\system32>chocolatey feature disable -n=allowGlobalConfirmation 
==> default: Disabled allowGlobalConfirmation
==> default: Running provisioner: shell...
    default: Running: scripts/chocolatey_installs/java.bat as c:\tmp\vagrant-shell.bat
==> default: C:\Windows\system32>chocolatey feature enable -n=allowGlobalConfirmation 
==> default: Enabled allowGlobalConfirmation
==> default: 
==> default: 
==> default: C:\Windows\system32>choco install BoxStarter 
==> default: Installing the following packages:
==> default: 
==> default: BoxStarter
==> default: By installing you accept licenses for the packages.
==> default: Boxstarter v2.8.29 already installed.
==> default: 
==> default:  Use --force to reinstall, specify a version to install, or try upgrade.
==> default: Chocolatey installed 0/1 packages. 0 packages failed.
==> default:  See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
==> default: 
==> default: Warnings:
==> default:  - boxstarter - Boxstarter v2.8.29 already installed.
==> default: 
==> default:  Use --force to reinstall, specify a version to install, or try upgrade.
==> default: 
==> default: Check out Pro / Business for more features! https://chocolatey.org/compare
==> default: 
==> default: C:\Windows\system32>chocolatey feature disable -n=allowGlobalConfirmation 
==> default: Disabled allowGlobalConfirmation
==> default: Running provisioner: shell...
    default: Running: scripts/chocolatey_installs/tomcat.bat as c:\tmp\vagrant-shell.bat
==> default: C:\Windows\system32>chocolatey feature enable -n=allowGlobalConfirmation 
==> default: Enabled allowGlobalConfirmation
==> default: 
==> default: 
==> default: C:\Windows\system32>choco install BoxStarter 
==> default: Installing the following packages:
==> default: 
==> default: BoxStarter
==> default: By installing you accept licenses for the packages.
==> default: Boxstarter v2.8.29 already installed.
==> default: 
==> default:  Use --force to reinstall, specify a version to install, or try upgrade.
==> default: 
==> default: Chocolatey installed 0/1 packages. 0 packages failed.
==> default:  See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
==> default: 
==> default: Warnings:
==> default:  - boxstarter - Boxstarter v2.8.29 already installed.
==> default:  Use --force to reinstall, specify a version to install, or try upgrade.
==> default: 
==> default: C:\Windows\system32>chocolatey feature disable -n=allowGlobalConfirmation 
==> default: Disabled allowGlobalConfirmation

Some things I tried:

  • Alternating the file extensions between .cmd and .bat, so that the script calls never had the same 2 file extensions in a row. RESULTS: The second .cmd script didn't seem to do anything. Checking the C:\tmp directory after provisioning was completed shows the vagrant-shell.cmd file has the same contents as the first call of the .cmd file extension.
  • Did a reload after each script ran (using this plugin https://github.com/aidanns/vagrant-reload). RESULTS: No change in behavior; the original bug persisted.
  • Added a provisioner for an inline script that removes C:\tmp\vagrant-shell.bat before running the next script. RESULTS: This resolves the issue. Subsequent script calls to a .bat file successfully run.

Based on what I've seen there is definitely an issue overwriting existing vagrant-shell.bat files. As a workaround, you can manually remove the vagrant-shell.bat file before running another script and it should run successfully.

@dragon788
Copy link
Contributor

@jbarnett-r7 I think your issue is similar to #7615 as you are rebooting and Vagrant is going to detect that the first script is there and not re-upload. I'd say try the same tactic I advised earlier, upload a folder of files and then trigger those scripts from the shell provisioner, and if you required a reboot you'll need to drop a "script done" flag so that it doesn't re-run them on the next provision.

A fix for Vagrant might be to upload all of the scripts at once to a known location and trigger them in a predictable/requested order instead of reusing the same script name for each upload and execution.

@jbarnett-r7
Copy link

@dragon788 They could be related. I do want to mention that I see the same behavior without the reboot. The reboot actually helps me move past some other failures I was seeing after running the first script.

Basically that first script installs chocolatey. The next script uses chocolatey to install a package. The second script was failing because it was saying chocolatey wasn't installed. The reload was a workaround to force me to get a new shell which had the updated PATH variable containing chocolatey.

Is it intended behavior that each config.vm.provision :shell call uses the shell that existed before? I feel like each should be run as a separate process to avoid collisions like this.

Or maybe this is a change/regression? This tutorial from a year ago addresses the same issue and specifically mentions that you need to run the chocolatey installs in a separate provision line to prevent the behavior I'm seeing: http://digitaldrummerj.me//vagrant-installing-boxstarter/

Sorry for the information dump. These issues have been plaguing me for multiple weeks now and I feel like I'm just going from workaround to workaround.

@bl4ckcontact
Copy link

Can confirm this happens to me on first boot as well. I will attempt mounting a folder with the scripts and try executing them and report back.

@dragon788
Copy link
Contributor

I think it is a Windows failing that updating the running environment is a nightmare, and the only way to really do it is to restart explorer.exe. What I found really helped was building my own base box from https://github.com/mwrock/packer-templates which includes Boxstarter/Chocolatey and makes it much easier to just bring a VM up and apply the tasty Chocolatey sauce.

I do like your idea of an inline provisioner that you could define with a script block at the top of the Vagrantfile and then just reuse in between each call to ensure that it must run the script, though you'd want to make sure your scripts are idempotent so it doesn't keep flip flopping if you vagrant provision a few times.

@zandi
Copy link

zandi commented Aug 24, 2016

I'm seeing the same behavior on Windows 7 Ultimate. When using multiple batch scripts specified by path for provisioning, whichever the first one vagrant runs is run for all of the defined shell script provisioners. Seems like C:\tmp\vagrant-shell.bat (or C:\tmp\vagrant-shell.ps1 for powershell scripts) needs to be removed once the given provisioning script has run.

1.bat

echo "one"

2.bat

echo "two"

Vagrantfile snippet

bl.vm.provision "one", type: "shell", path: "vagrant/1.bat"
bl.vm.provision "two", type: "shell", path: "vagrant/2.bat"

Output:

==> Running provisioner: one (shell)...
    bl: Running: vagrant/1.bat as c:\tmp\vagrant-shell.bat
==> bl: C:\Windows\system32>echo "one" 
==> bl: "one"
==> bl: Running provisioner: two (shell)...
    bl: Running: vagrant/2.bat as c:\tmp\vagrant-shell.bat
==> bl: C:\Windows\system32>echo "one" 
==> bl: "one"

@jbarnett-r7
Copy link

I just tested this on the recently released 1.8.6 and am still seeing the same behavior:

==> default: Running provisioner: shell...
    default: Running: scripts/installs/install_boxstarter.bat as c:\tmp\vagrant-shell.bat
==> default: C:\Windows\system32>chocolatey feature enable -n=allowGlobalConfirmation 
==> default: Chocolatey v0.10.2
==> default: Enabled allowGlobalConfirmation
==> default: C:\Windows\system32>choco install BoxStarter 
==> default: Chocolatey v0.10.2
==> default: Installing the following packages:
==> default: 
==> default: BoxStarter
==> default: By installing you accept licenses for the packages.
==> default: BoxStarter.Common v2.8.29 [Approved]
==> default: boxstarter.common package files install is complete. Performing other installation steps.
==> default: C:\Users\vagrant\AppData\Roaming\Boxstarter
==> default: 
==> default: C:\Users\vagrant\AppData\Roaming\Boxstarter\BuildPackages
==> default: The Boxstarter.Common Module has been copied to C:\Users\vagrant\AppData\Roaming\Boxstarter and added to your Module path. 
==> default: 
==> default: You will need to open a new console for the path to be visible.
==> default: Use 'Get-Module Boxstarter.* -ListAvailable' to list all Boxstarter Modules.
==> default: To list all available Boxstarter Commands, use:
==> default: 
==> default: PS:>Import-Module Boxstarter.Common
==> default: PS:>Get-Command -Module Boxstarter.*
==> default: 
==> default: To find more info visit http://Boxstarter.org or use:
==> default: PS:>Import-Module Boxstarter.Common
==> default: PS:>Get-Help Boxstarter
==> default: Environment Vars (like PATH) have changed. Close/reopen your shell to
==> default:  see the changes (or in powershell/cmd.exe just type `refreshenv`).
==> default:  The install of boxstarter.common was successful.
==> default: 
==> default:   Software install location not explicitly set, could be in package or 
==> default:   default install location if installer.
==> default: 
==> default: BoxStarter.WinConfig v2.8.29 [Approved]
==> default: boxstarter.winconfig package files install is complete. Performing other installation steps.
==> default: The Boxstarter.WinConfig Module has been copied to C:\Users\vagrant\AppData\Roaming\Boxstarter and added to your Module path. 
==> default: 
==> default: You will need to open a new console for the path to be visible.
==> default: Use 'Get-Module Boxstarter.* -ListAvailable' to list all Boxstarter Modules.
==> default: To list all available Boxstarter Commands, use:
==> default: PS:>Import-Module Boxstarter.WinConfig
==> default: PS:>Get-Command -Module Boxstarter.*
==> default: 
==> default: To find more info visit http://Boxstarter.org or use:
==> default: PS:>Import-Module Boxstarter.WinConfig
==> default: PS:>Get-Help Boxstarter
==> default: Environment Vars (like PATH) have changed. Close/reopen your shell to
==> default:  see the changes (or in powershell/cmd.exe just type `refreshenv`).
==> default:  The install of boxstarter.winconfig was successful.
==> default:   Software install location not explicitly set, could be in package or 
==> default:   default install location if installer.
==> default: 
==> default: boxstarter.bootstrapper v2.8.29 [Approved]
==> default: boxstarter.bootstrapper package files install is complete. Performing other installation steps.
==> default: The Boxstarter.Bootstrapper Module has been copied to C:\Users\vagrant\AppData\Roaming\Boxstarter and added to your Module path. 
==> default: 
==> default: You will need to open a new console for the path to be visible.
==> default: Use 'Get-Module Boxstarter.* -ListAvailable' to list all Boxstarter Modules.
==> default: To list all available Boxstarter Commands, use:
==> default: PS:>Import-Module Boxstarter.Bootstrapper
==> default: PS:>Get-Command -Module Boxstarter.*
==> default: 
==> default: To find more info visit http://Boxstarter.org or use:
==> default: 
==> default: PS:>Import-Module Boxstarter.Bootstrapper
==> default: PS:>Get-Help Boxstarter
==> default:  The install of boxstarter.bootstrapper was successful.
==> default:   Software install location not explicitly set, could be in package or 
==> default:   default install location if installer.
==> default: boxstarter.chocolatey v2.8.29 [Approved]
==> default: boxstarter.chocolatey package files install is complete. Performing other installation steps.
==> default: The Boxstarter.Chocolatey Module has been copied to C:\Users\vagrant\AppData\Roaming\Boxstarter and added to your Module path. 
==> default: 
==> default: You will need to open a new console for the path to be visible.
==> default: Use 'Get-Module Boxstarter.* -ListAvailable' to list all Boxstarter Modules.
==> default: To list all available Boxstarter Commands, use:
==> default: PS:>Import-Module Boxstarter.Chocolatey
==> default: PS:>Get-Command -Module Boxstarter.*
==> default: 
==> default: To find more info visit http://Boxstarter.org or use:
==> default: PS:>Import-Module Boxstarter.Chocolatey
==> default: PS:>Get-Help Boxstarter
==> default: C:\Users\vagrant\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Boxstarter
==> default:  The install of boxstarter.chocolatey was successful.
==> default: 
==> default:   Software install location not explicitly set, could be in package or 
==> default:   default install location if installer.
==> default: 
==> default: Boxstarter.HyperV v2.8.29 [Approved]
==> default: boxstarter.hyperv package files install is complete. Performing other installation steps.
==> default: The Boxstarter.HyperV Module has been copied to C:\Users\vagrant\AppData\Roaming\Boxstarter and added to your Module path. 
==> default: 
==> default: You will need to open a new console for the path to be visible.
==> default: Use 'Get-Module Boxstarter.* -ListAvailable' to list all Boxstarter Modules.
==> default: To list all available Boxstarter Commands, use:
==> default: 
==> default: PS:>Import-Module Boxstarter.HyperV
==> default: PS:>Get-Command -Module Boxstarter.*
==> default: 
==> default: To find more info visit http://Boxstarter.org or use:
==> default: PS:>Import-Module Boxstarter.HyperV
==> default: PS:>Get-Help Boxstarter
==> default:  The install of boxstarter.hyperv was successful.
==> default:   Software install location not explicitly set, could be in package or 
==> default:   default install location if installer.
==> default: 
==> default: boxstarter v2.8.29 [Approved]
==> default: boxstarter package files install is complete. Performing other installation steps.
==> default: To load all Boxstarter Modules immediately, just enter 'BoxstarterShell'.
==> default: 
==> default: Interested in Windows Azure VM integration? Run CINST Boxstarter.Azure to install Boxstarter's Azure integration.
==> default:  The install of boxstarter was successful.
==> default:   Software install location not explicitly set, could be in package or 
==> default:   default install location if installer.
==> default: 
==> default: Chocolatey installed 6/6 packages. 0 packages failed.
==> default: 
==> default:  See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
==> default: 
==> default: Installed:
==> default:  - boxstarter.bootstrapper v2.8.29
==> default:  - boxstarter.hyperv v2.8.29
==> default:  - boxstarter.winconfig v2.8.29
==> default:  - boxstarter v2.8.29
==> default:  - boxstarter.chocolatey v2.8.29
==> default:  - boxstarter.common v2.8.29
==> default: C:\Windows\system32>chocolatey feature disable -n=allowGlobalConfirmation 
==> default: Chocolatey v0.10.2
==> default: Disabled allowGlobalConfirmation
==> default: Running provisioner: shell...
    default: Running: scripts/chocolatey_installs/7zip.bat as c:\tmp\vagrant-shell.bat
==> default: C:\Windows\system32>chocolatey feature enable -n=allowGlobalConfirmation 
==> default: Chocolatey v0.10.2
==> default: Enabled allowGlobalConfirmation
==> default: 
==> default: 
==> default: C:\Windows\system32>choco install BoxStarter 
==> default: Chocolatey v0.10.2
==> default: Installing the following packages:
==> default: 
==> default: BoxStarter
==> default: By installing you accept licenses for the packages.
==> default: Boxstarter v2.8.29 already installed.
==> default: 
==> default:  Use --force to reinstall, specify a version to install, or try upgrade.
==> default: 
==> default: Chocolatey installed 0/1 packages. 0 packages failed.
==> default:  See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
==> default: 
==> default: Warnings:
==> default:  - boxstarter - Boxstarter v2.8.29 already installed.
==> default:  Use --force to reinstall, specify a version to install, or try upgrade.
==> default: 
==> default: C:\Windows\system32>chocolatey feature disable -n=allowGlobalConfirmation 
==> default: Chocolatey v0.10.2
==> default: Disabled allowGlobalConfirmation
==> default: Running provisioner: shell...
    default: Running: scripts/configs/apply_password_settings.bat as c:\tmp\vagrant-shell.bat
==> default: C:\Windows\system32>chocolatey feature enable -n=allowGlobalConfirmation 
==> default: Chocolatey v0.10.2
==> default: Enabled allowGlobalConfirmation
==> default: 
==> default: 
==> default: C:\Windows\system32>choco install BoxStarter 
==> default: Chocolatey v0.10.2
==> default: Installing the following packages:
==> default: 
==> default: BoxStarter
==> default: By installing you accept licenses for the packages.
==> default: Boxstarter v2.8.29 already installed.
==> default: 
==> default:  Use --force to reinstall, specify a version to install, or try upgrade.
==> default: 
==> default: Chocolatey installed 0/1 packages. 0 packages failed.
==> default:  See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
==> default: 
==> default: Warnings:
==> default:  - boxstarter - Boxstarter v2.8.29 already installed.
==> default:  Use --force to reinstall, specify a version to install, or try upgrade.
==> default: C:\Windows\system32>chocolatey feature disable -n=allowGlobalConfirmation 
==> default: Chocolatey v0.10.2
==> default: Disabled allowGlobalConfirmation
==> default: Running provisioner: shell...
    default: Running: scripts/configs/create_users.bat as c:\tmp\vagrant-shell.bat
==> default: C:\Windows\system32>chocolatey feature enable -n=allowGlobalConfirmation 
==> default: Chocolatey v0.10.2
==> default: Enabled allowGlobalConfirmation
.
.
.

I am still testing against Windows 2008 R2. I had to add the hack (manually delete the C:\tmp\vagrant-shell.bat file after each provisioning script) back in to get things to work properly.

@chrisroberts chrisroberts added this to the 1.9 milestone Oct 3, 2016
@nirix
Copy link

nirix commented Oct 19, 2016

Came across this issue myself with a Windows 2008R2 box. An easy fix was to simply supply an upload path for the scripts like so:

config.vm.provision "script_a", type: "shell" do |s|
  s.path = "scripts/script_a.bat"
  s.upload_path = "C:\\tmp\\script_a.bat"
end

config.vm.provision "script_b", type: "shell" do |s|
  s.path = "scripts/script_b.bat"
  s.upload_path = "C:\\tmp\\script_b.bat"
end

This issue plus other WinRM issues had us stuck on Vagrant 1.8.1, hopefully others with this issue can upgrade if they are able to use upload_path.

@dwickern
Copy link

dwickern commented Oct 26, 2016

I have the same issue. The first powershell provisioner works, then every other provisioner runs the first script again. Relevant debug output:

DEBUG winrmshell: creating hash for file /tmp/vagrant-shell.ps1
DEBUG winrmshell: Running check_files.ps1
DEBUG winrmshell: @{
DEBUG winrmshell:   "/tmp/vagrant-shell.ps1" = "adc768479fe09a9344be2191eeba91a6"
DEBUG winrmshell: }
DEBUG winrmshell: File /tmp/vagrant-shell.ps1 is up to date, skipping

The upload_path workaround appears to work:

config.vm.provision "shell", upload_path: "C:\\tmp\\foo", inline: ...

@dwickern
Copy link

Here's a generic workaround so you don't have to add an upload_path to all your config.vm.provision (if you have a lot of them like I do).

module UniqueUploadPath
  @@counter = 0

  def provision(name, **options, &block)
    is_shell_provisioner = options[:type] == "shell" || (!options[:type] && name == "shell")

    if (is_shell_provisioner && !options[:upload_path])
      options[:upload_path] = "C:\\tmp\\vagrant-shell-#{@@counter += 1}"
    end

    super(name, **options, &block)
  end
end

module VagrantPlugins
  module Kernel_V2
    class VMConfig < Vagrant.plugin("2", :config)
      prepend UniqueUploadPath
    end
  end
end

@dusek
Copy link

dusek commented Nov 8, 2016

I am hitting this as well, providing my info (originally reported as dupe at GH-7971):

Vagrant version

Vagrant 1.8.7

Host operating system

macOS 10.12.1 (16B2555)

Guest operating system

Windows 7 Pro x32 Czech FPP

Vagrantfile

Vagrant.configure(2) do |config|
  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = true

    # Customize the amount of memory on the VM:
    vb.memory = "2048"

    # Add sound card (for synthesized speech)
    vb.customize ["modifyvm", :id, '--audio', 'coreaudio', '--audiocontroller', 'hda']

    # Clipboard sync (copying text is often needed)
    vb.customize ["modifyvm", :id, '--clipboard', 'bidirectional']
  end

  config.vm.define "linux", autostart: false do |linux|
    ...
  end

  config.vm.define "win" do |win|
    win.vm.box = ENV['VAGRANT_BOX_WIN'] || "someusername/win7x86-pro-cz"
    win.vm.boot_timeout = 15*60 # user interaction is required on first boot

    # set up provisioning prerequisities
    win.vm.provision "shell", path: "vagrant/fixnetwork.ps1" # strangely, network gets randomly set to Public on first box boot
    win.vm.provision "file", source: "vagrant/provutils.psm1", destination: "Documents/WindowsPowerShell/Modules/provutils/provutils.psm1"
    win.vm.provision "shell", path: "vagrant/sharedfolder.cmd"

    # now for the real work:
    win.vm.provision "shell", path: "vagrant/desktop.ps1"

    win.vm.provision "shell", path: "vagrant/bash.ps1"

    win.vm.provision "shell", path: "vagrant/choco.ps1"

    win.vm.provision "shell", path: "vagrant/java.ps1"

    win.vm.provision :reload
  end
end

Debug output

https://gist.github.com/dusek/42617c076a582b2a4fed2c26e11a954f

Expected behavior

These scripts should run in sequence:

  • fixnetwork.ps1
  • sharedfolder.cmd
  • desktop.ps1
  • bash.ps1
  • choco.ps1
  • java.ps1

Actual behavior

What actually happened?
Based both on the linked "Debug output" and on the effect inside the VM afterwards, these scripts were run:

  • fixnetwork.ps1
  • sharedfolder.cmd
  • fixnetwork.ps1
  • fixnetwork.ps1
  • fixnetwork.ps1
  • fixnetwork.ps1

Steps to reproduce

  1. Run vagrant up win with the above Vagrantfile (you won't have access to the linked box though...)

Notes

  • VirtualBox 5.1.6
  • The same problem is also for .cmd files - when second provisioning .cmd shell script is specified in Vagrantfile, it instead executes the first .cmd shell script.
  • based on this, it looks like vagrant succeeds at uploading c:\tmp\vagrant-shell.ps1 or c:\tmp\vagrant-shell.cmd file for the first time (i.e. when there is no previous such file and it is thus created), but all subsequent attempts to upload a new .cmd or .ps1 file to overwrite the previous ones fail
  • I have used the same Vagrantfile previously with older vagrant and VirtualBox versions and there vagrant up win worked fine (since it is quite some time - a few months - I no longer know which exact vagrant and/or VirtualBox version that was); the base box is 100% unchanged since then
  • please disregard some wrongly encoded output of both scripts in the "Debug output", it was present already at times when things were working fine with vagrant (see previous point)

References

@jimklo
Copy link

jimklo commented Nov 16, 2016

I'm having the same issue with OS X Yosemite (host), Win 7 (guest), Vagrant (1.8.7), VirtualBox 5.1.8.

One additional thing that I didn't see mentioned is that if you repackage or box the VM and it still has a script file that was uploaded to c:\vagrant\tmp\, that file will not be overwitten during provisioning at all.

@chrisroberts
Copy link
Member

Hi there,

It looks like this has been resolved within a previously shipped version of Vagrant so I am now closing this issue. If the original issue was not fully resolved, please reopen this issue or create a new one.

Cheers!

@SquirrelAssassin
Copy link

SquirrelAssassin commented Jan 24, 2018

Same issue no clue it always runs the first $script on both nodes.

$script = <<SCRIPT
su
appleappleapple
apt-get install -y make gcc net-tools autoconf vim git nano nmap
sysctl net.bridge.bridge-nf-call-iptables=1
swapoff -a
apt-get update && apt-get upgrade
apt-get install -y docker.io
apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat </etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
systemctl enable docker && systemctl start docker
apt-get update
apt-get install -y kubelet kubeadm kubectl
sed -i 's#Environment="KUBELET_KUBECONFIG_ARGS=-.*#Environment="KUBELET_KUBECONFIG_ARGS=--kubeconfig=/etc/kubernetes/kubelet.conf --require-kubeconfig=true --cgroup-driver=cgroupfs"#g' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
systemctl daemon-reload
systemctl restart kubelet
systemctl enable kubelet && systemctl start kubelet
iptables -A INPUT -p tcp --dport 6443 -j ACCEPT
iptables -A INPUT -p tcp --dport 10250 -j ACCEPT
iptables -A INPUT -p tcp --dport 10251 -j ACCEPT
iptables -A INPUT -p tcp --dport 10252 -j ACCEPT
iptables -A INPUT -p tcp --dport 10255 -j ACCEPT
iptables -A INPUT -p tcp --dport 2379 -j ACCEPT
iptables -A INPUT -p tcp --dport 2380 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp --dport 30000:32767 -j ACCEPT
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections
apt-get install -y iptables-persistent
reboot
SCRIPT

$script1 = <<SCRIPT
su
wakawakawaka
apt-get install -y make gcc net-tools autoconf vim git nano nmap
sysctl net.bridge.bridge-nf-call-iptables=1
swapoff -a
apt-get update && apt-get upgrade
apt-get install -y docker.io
apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat </etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
systemctl enable docker && systemctl start docker
apt-get update
apt-get install -y kubelet kubeadm kubectl
sed -i 's#Environment="KUBELET_KUBECONFIG_ARGS=-.*#Environment="KUBELET_KUBECONFIG_ARGS=--kubeconfig=/etc/kubernetes/kubelet.conf --require-kubeconfig=true --cgroup-driver=cgroupfs"#g' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
systemctl daemon-reload
systemctl restart kubelet
systemctl enable kubelet && systemctl start kubelet
iptables -A INPUT -p tcp --dport 6443 -j ACCEPT
iptables -A INPUT -p tcp --dport 10250 -j ACCEPT
iptables -A INPUT -p tcp --dport 10251 -j ACCEPT
iptables -A INPUT -p tcp --dport 10252 -j ACCEPT
iptables -A INPUT -p tcp --dport 10255 -j ACCEPT
iptables -A INPUT -p tcp --dport 2379 -j ACCEPT
iptables -A INPUT -p tcp --dport 2380 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp --dport 30000:32767 -j ACCEPT
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections
apt-get install -y iptables-persistent
reboot
SCRIPT

Vagrant.configure("2") do |config|
config.vm.box_check_update = true
config.ssh.insert_key = false
config.vm.synced_folder "c:/vboxsharefolder", "/vagrant", type: "virtualbox"
config.vm.define "k8master" do |k8master|
k8master.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", :type => 'static', :name => 'VirtualBox Host-Only Ethernet Adapter #3', :adapter => 2, :ip => "10.42.0.80"
config.vm.provider "virtualbox" do |k8master|
config.vm.hostname = "k8master"
k8master.linked_clone = true
k8master.customize ["modifyvm", :id, "--memory", "2048"]
k8master.customize ["modifyvm", :id, "--clipboard","bidirectional"]
k8master.customize ["modifyvm", :id, "--draganddrop","bidirectional"]

	   end
	config.vm.provision "shell", inline: $script
end
		config.vm.define "k8client1" do |k8client1|
           k8client1.vm.box = "ubuntu/trusty64"
		   config.vm.network "private_network", :type => 'static', :name => 'VirtualBox Host-Only Ethernet Adapter #3', :adapter => 2, :ip => "10.42.0.81"
           config.vm.provider "virtualbox" do |k8client1|
		   config.vm.hostname = "k8client1"
           k8client1.linked_clone = true
           k8client1.customize ["modifyvm", :id, "--memory", "2048"]
		   k8client1.customize ["modifyvm", :id, "--clipboard","bidirectional"]
           k8client1.customize ["modifyvm", :id, "--draganddrop","bidirectional"]
		   
	   end
   config.vm.provision "shell", inline: $script1
end

end

@ghost
Copy link

ghost commented Mar 31, 2020

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.

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
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