Vagrant trigger desktop alerts after upgrading from 1.x to 2.2
0 reputation · 26 Jul 2020, 21:40 UTC
0 reputation · 26 Jul 2020, 21:40 UTC
Goal: configure a host-side desktop notification that fires when Vagrant provisioning completes, after upgrading a project from Vagrant 1.x to Vagrant 2.2 or later.
Constraint: Vagrant 2.2 and later honor config.trigger blocks, while Vagrant 1.x ignores them. Vagrant provides no native notification channel, severity level, deduplication, or rate limiting. Trigger output goes to stdout and stderr, so repeated up, reload, or provision runs can duplicate alert messages. Trigger timing relative to provider-specific steps such as shared-folder mounting is not strictly guaranteed, so alert ordering depends on the provider.
Questions:
35275 reputation · 27 Jul 2020, 08:09 UTC
Yes — on Vagrant 2.2 or later, attach the desktop alert to config.trigger.after :provision inside a Vagrant.configure("2") block. That hook means "provisioning finished," whereas after :up is broader and also fires for plain vagrant up runs that provisioned nothing or were no-ops. This assumes a version "2" Vagrantfile on Vagrant ≥ 2.2; Vagrant 1.x does not implement triggers at all, so there the block is silently ignored and no alert is sent.
Established: Vagrant 2.2+ honors config.trigger.before/after blocks; Vagrant provides no native notification channel, severity level, deduplication, or rate limiting; trigger stdout/stderr only appears in Vagrant's own output. The likely explanation for the duplicate alerts after upgrading is that each separate vagrant up, reload, or provision process re-runs the trigger and the host notifier emits again — there is no dedup layer in between.
Use the trigger's host-side run step (not run_remote, which executes inside the guest) with your OS notifier:
Vagrant.configure("2") do |config|
config.trigger.after :provision do |trigger|
trigger.info = "Provisioning finished"
trigger.run = { inline: "notify-send 'Vagrant' 'Provisioning finished'" } # Linux
# macOS: osascript -e 'display notification \"Provisioning finished\" with title \"Vagrant\"'
# Windows: a PowerShell notifier module or msg equivalent
end
end
after :provision when the alert must mean "provisioning finished." after :up fires even when no provisioning ran.Vagrant 2.2 is old and trigger/provider behavior is version-sensitive, so confirm on your actual release before relying on it:
vagrant --version and note your provider plugin version (VirtualBox, VMware, etc.).vagrant validate, then use a minimal Vagrantfile whose after :provision trigger echoes a marker; run vagrant up --provision, vagrant provision, plain vagrant up, and vagrant reload --provision, recording which commands emit the marker.after :provision still runs, and whether a non-zero trigger exit status fails the whole command on your version. Only after that result, wrap the notifier so a notification failure cannot break provisioning.vagrant provision twice and compare a notifier replacement ID against a state-file guard; check your notifier's own documentation for replace/group semantics before relying on them.One diagnostic detail would pin down the exact recommendation: your host OS and notifier, plus the exact vagrant --version and provider versions, since those determine the notifier command and the trigger exit-status behavior.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.