There is a hack to do this without triggers in a pretty 'clean' fashion:
This approach allows you to reload the machine only the very first time and
to run a second set of provisioning. Uses Ruby's built-in at_exit trigger.
# Function to check whether VM was already provisioned (first run of
``vagrant up``)
# NOTE this would be confused by using more than one provider in the same
folder
# but that's not possible currently.
def provisioned?
Dir['.vagrant/machines/default/*/action_provision'].any?
end
Vagrant.configure("2") do |config|
# ....
unless provisioned?()
# First call of vagrant up
if ARGV[0] == 'up'
# at_exit ensures that Vagrant's lock on the VM is released before
re-exec'ing.
at_exit do
if $!.nil? || $!.is_a?(SystemExit) && $!.success?
# First time up, rexecute vagrant to reboot and continue
provisioning
exec "vagrant reload --provision"
else
# Oops, we failed during initial up, offer to delete partially
created machine
code = $!.is_a?(SystemExit) ? $!.status : 1
print "\nERROR Vagrant up failed with code #{code}\n"
exec "vagrant destroy"
end
end
end
else
# Subsequent calls of vagrant up
# Put your secondary provisioning configuration here
end
end
On Friday, April 6, 2018 at 8:28:40 AM UTC-6, Sandra Parsick wrote:
>
> Hello mailing list,
>
> I have following issue: I'd like to run after a successful 'vagrant up' a
> script on the host machine. Is there a possibility in the Vagrantfile to
> reference this script file, so that vagrant runs it automatically after a
> successful 'vagrant up'?
>
> Thanks you and best regards
>
> Sandra
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vagrant-up/a0916145-7dac-4802-b08f-cf6c439259f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.