Skip to content

Provision action trigger ordering with provision action #13690

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion website/content/docs/triggers/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ running either `vagrant destroy` or `vagrant halt` would stop tinyproxy.

Triggers can also be defined to run Ruby, rather than bash or PowerShell. An
example of this might be using a Ruby option to get more information from the `VBoxManage`
tool. In this case, we are printing the `ostype` defined for thte guest after
tool. In this case, we are printing the `ostype` defined for the guest after
it has been brought up.

```ruby
Expand Down Expand Up @@ -196,3 +196,46 @@ config.trigger.before :"Vagrant::Action::Builtin::GracefulHalt", type: :action d
t.warn = "Vagrant is halting your guest..."
end
```

#### Provision action

The provision stack works little different than the other action stacks. The Vagrant
stack is made up of middlewares that are run in a specific order. generally it tend to
to perform their operation and call to the next item but in some cases will continue to
do things once the next item completes. In the Provision action, the next item in the
stack is executed [here](https://github.com/hashicorp/vagrant/blob/main/lib/vagrant/action/builtin/provision.rb#L82-L83).but the actual provisioning happens at the end [here](https://github.com/hashicorp/vagrant/blob/main/lib/vagrant/action/builtin/provision.rb#L129-L133), after the rest of the stack
has executed and exited.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated for grammar and clarity as it's mixing terms.

The provision action behaves slightly different than other actions. When Vagrant executes its stack, each action performs some function and then calls the next action in the stack. In some cases (like the provision action), the action will perform some function, call the next action, and wait for the it to return to perform some extra functionality or cleanup. This behavior can result in seemingly unexpected results for after triggers since the targeted action will complete after the rest of the actions in the stack have executed.



```
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu"

# Provisioners:
config.vm.provision "PROVISIONER1", type: :shell, inline: "echo executing first provisioner"
config.vm.provision "PROVISIONER2", type: :shell, inline: "echo executing second provisioner"

# Triggers:

config.trigger.before :machine_action_provision, type: :hook,
name: "HOOK TRIGGER BEFORE machine_action_provision",
info: "INSIDE BEFORE machine_action_provision HOOK TRIGGER"

config.trigger.before Vagrant::Action::Builtin::Provision, type: :action,
name: "ACTION TRIGGER BEFORE Vagrant::Action::Builtin::Provision",
info: "INSIDE BEFORE Vagrant::Action::Builtin::Provision TRIGGER"

config.trigger.after Vagrant::Action::Builtin::Provision, type: :action,
name: "ACTION TRIGGER AFTER Vagrant::Action::Builtin::Provision",
info: "INSIDE AFTER Vagrant::Action::Builtin::Provision TRIGGER"

config.trigger.after :machine_action_provision, type: :hook,
name: "HOOK TRIGGER AFTER machine_action_provision",
info: "INSIDE AFTER machine_action_provision HOOK TRIGGER"

end
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output of this should be included to display the behavior.


When running `vagrant provision` or `vagrant up`, the before and after triggers
will run before the provisioning of the box happens.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this true?