Provisioning scripts always run twice?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Provisioning scripts always run twice?

Paul Hoffman
Greetings. I suspect I'm missing something obvious, but "vagrant up --provision" or "vagrant provision" cause my script to run twice. I write the script out each time I run either of these, but I would hope that wouldn't be the cause of the problem.

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "main"
  config.vm.provision "shell", path: "run_at_start.sh"
end


run_at_start.sh

# Instructions for unbound-1.6.2
[ -e /res_binaries/unbound-1.6.2 ] && echo "The binary for unbound-1.6.2 already exists." && exit
. . . other shell steps here . . .

Adding "#!/usr/bin/env bash" to the top of run_at_start.sh didn't help.

Clues appreciated!

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAPik8yZKfvNHPdntD3YFqa%2Bsbp3%3DC065xHgGS-9Kede5r1kV9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Provisioning scripts always run twice?

Alvaro Miranda Aguilera

On Wed, Jun 7, 2017 at 12:02 AM, Paul Hoffman <[hidden email]> wrote:
Vagrant.configure("2") do |config|
  config.vm.box = "main"
  config.vm.provision "shell", path: "run_at_start.sh"
end

Hello

It shouldn't.

So I will suggest.

1. check with a different box, ie hashicorp/precise64

2. The way Vagrant works, you have 3 Vagrantfiles (if present) and they get merge in memory.

So check if there is a Vagrantfile at:

~/.vagrant.d/Vagrantfile  < this is a global one that will be loaded into all the commands

~/.vagrant.d/boxes/<thebox>/<somepath>/Vagrantfile < this will be used in all the VMs that use this base box.

Also you can test with:

#   config.vm.provision "shell", path: "run_at_start.sh"
  config.vm.provision "shell", inline: " echo we run run_at_start.sh"

That will display how many runs will happen. 

If this display only one time, then maybe the script is calling himself?

There aren't many options.




--
Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0ezUrhwB7bQtOcdVRjP4Bu2FW2KWVdq%2BvwD3GHXqz1_%2BPg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Provisioning scripts always run twice?

Paul Hoffman
Sorry for the long delay in getting back to you on this. I've been bashing my head against the desk and just now figured it out.

The box has a Vagrantfile. That file has 'config.vm.provision "shell', path: "run_at_start.sh"" in it. The Vagrant machine *also* has the same Vagrantfile. Because of the way that Vagrant pulls in the box's Vagrantfile after parsing its own, it now has two (identical) 'config.vm.provision "shell' lines and it decides that I meant to run it twice.

I could consider this a bug, but I can also see that "having two identical shell lines means run the command twice" is logical if you squint hard.

I have a solution for my use case: remove the shell line from the machine's Vagrantfile. Hopefully this doesn't burn other people or, if it does, that they can find this thread.

--Paul Hoffman

On Wed, Jun 7, 2017 at 12:30 AM, Alvaro Miranda Aguilera <[hidden email]> wrote:

On Wed, Jun 7, 2017 at 12:02 AM, Paul Hoffman <[hidden email]> wrote:
Vagrant.configure("2") do |config|
  config.vm.box = "main"
  config.vm.provision "shell", path: "run_at_start.sh"
end

Hello

It shouldn't.

So I will suggest.

1. check with a different box, ie hashicorp/precise64

2. The way Vagrant works, you have 3 Vagrantfiles (if present) and they get merge in memory.

So check if there is a Vagrantfile at:

~/.vagrant.d/Vagrantfile  < this is a global one that will be loaded into all the commands

~/.vagrant.d/boxes/<thebox>/<somepath>/Vagrantfile < this will be used in all the VMs that use this base box.

Also you can test with:

#   config.vm.provision "shell", path: "run_at_start.sh"
  config.vm.provision "shell", inline: " echo we run run_at_start.sh"

That will display how many runs will happen. 

If this display only one time, then maybe the script is calling himself?

There aren't many options.




--
Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0ezUrhwB7bQtOcdVRjP4Bu2FW2KWVdq%2BvwD3GHXqz1_%2BPg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAPik8yYAfr%3DT_JtbK_rc4K0CDhpPOL%3D0DAfJB2QCr%3DDj2RaH0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Provisioning scripts always run twice?

Brian Cain
Hello Paul!

You are correct. Because the box has the same Vagrantfile, it gets loaded twice when you run Vagrant (see https://www.vagrantup.com/docs/vagrantfile/#load-order-and-merging)

I've been working this week to fix the bug in Vagrant, and I've put up a pull request which will be included in the next release. However, there is a workaround if you can't wait. The bug itself is due to your provision block not having a name. If you don't want them running twice, you can fix it by giving it a name like this:

`config.vm.provision "my shell script", type: "shell", ....`

Then the script should only run once. Hopefully that helps!

Cheers.
- Brian Cain

On Fri, Jun 9, 2017 at 11:11 AM, Paul Hoffman <[hidden email]> wrote:
Sorry for the long delay in getting back to you on this. I've been bashing my head against the desk and just now figured it out.

The box has a Vagrantfile. That file has 'config.vm.provision "shell', path: "run_at_start.sh"" in it. The Vagrant machine *also* has the same Vagrantfile. Because of the way that Vagrant pulls in the box's Vagrantfile after parsing its own, it now has two (identical) 'config.vm.provision "shell' lines and it decides that I meant to run it twice.

I could consider this a bug, but I can also see that "having two identical shell lines means run the command twice" is logical if you squint hard.

I have a solution for my use case: remove the shell line from the machine's Vagrantfile. Hopefully this doesn't burn other people or, if it does, that they can find this thread.

--Paul Hoffman

On Wed, Jun 7, 2017 at 12:30 AM, Alvaro Miranda Aguilera <[hidden email]> wrote:

On Wed, Jun 7, 2017 at 12:02 AM, Paul Hoffman <[hidden email]> wrote:
Vagrant.configure("2") do |config|
  config.vm.box = "main"
  config.vm.provision "shell", path: "run_at_start.sh"
end

Hello

It shouldn't.

So I will suggest.

1. check with a different box, ie hashicorp/precise64

2. The way Vagrant works, you have 3 Vagrantfiles (if present) and they get merge in memory.

So check if there is a Vagrantfile at:

~/.vagrant.d/Vagrantfile  < this is a global one that will be loaded into all the commands

~/.vagrant.d/boxes/<thebox>/<somepath>/Vagrantfile < this will be used in all the VMs that use this base box.

Also you can test with:

#   config.vm.provision "shell", path: "run_at_start.sh"
  config.vm.provision "shell", inline: " echo we run run_at_start.sh"

That will display how many runs will happen. 

If this display only one time, then maybe the script is calling himself?

There aren't many options.




--
Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0ezUrhwB7bQtOcdVRjP4Bu2FW2KWVdq%2BvwD3GHXqz1_%2BPg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAPik8yYAfr%3DT_JtbK_rc4K0CDhpPOL%3D0DAfJB2QCr%3DDj2RaH0A%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Brian Cain

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CADHESCX%2Bji%2BK9XZL6n%2BS_2o%2BVu2Z9eSAwwg7T8LwHMXKq%3DmL4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Provisioning scripts always run twice?

Paul Hoffman
Thanks for the followup. After staring at my setup a while, I realized that it was easy to have different Vagrantfiles in my box and in my images. That fixed it. :-)

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAPik8yYYJ44ACgbHF0TDc1pzsdL5CF4Fig%2Bu3%2BFVg2rMfAA6Mw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.