summaryrefslogtreecommitdiff
path: root/devdocs/vagrant/triggers%2Findex.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/vagrant/triggers%2Findex.html
new repository
Diffstat (limited to 'devdocs/vagrant/triggers%2Findex.html')
-rw-r--r--devdocs/vagrant/triggers%2Findex.html52
1 files changed, 52 insertions, 0 deletions
diff --git a/devdocs/vagrant/triggers%2Findex.html b/devdocs/vagrant/triggers%2Findex.html
new file mode 100644
index 00000000..9ec41dd2
--- /dev/null
+++ b/devdocs/vagrant/triggers%2Findex.html
@@ -0,0 +1,52 @@
+<h1 id="vagrant-triggers"> Vagrant Triggers </h1> <p>As of version 2.1.0, Vagrant is capable of executing machine triggers <em>before</em> or <em>after</em> Vagrant commands.</p> <p>Each trigger is expected to be given a command key for when it should be fired during the Vagrant command lifecycle. These could be defined as a single key or an array which acts like a <em>whitelist</em> for the defined trigger.</p> <div class="highlight"><pre class="highlight ruby" data-language="ruby"># single command trigger
+config.trigger.after :up do |trigger|
+...
+end
+
+# multiple commands for this trigger
+config.trigger.before [:up, :destroy, :halt, :package] do |trigger|
+...
+end
+
+# or defined as a splat list
+config.trigger.before :up, :destroy, :halt, :package do |trigger|
+...
+end
+</pre></div>
+<p>Alternatively, the key <code>:all</code> could be given which would run the trigger before or after every Vagrant command. If there is a command you don't want the trigger to run on, you can ignore that command with the <code>ignore</code> option.</p> <div class="highlight"><pre class="highlight ruby" data-language="ruby"># single command trigger
+config.trigger.before :all do |trigger|
+ trigger.info = "Running a before trigger!"
+ trigger.ignore = [:destroy, :halt]
+end
+</pre></div>
+<p><strong>Note:</strong> <em>If a trigger is defined on a command that does not exist, a warning will be displayed.</em></p> <p>Triggers can be defined as a block or hash in a Vagrantfile. The example below will result in the same trigger:</p> <div class="highlight"><pre class="highlight ruby" data-language="ruby">config.trigger.after :up do |trigger|
+ trigger.name = "Finished Message"
+ trigger.info = "Machine is up!"
+end
+
+config.trigger.after :up,
+ name: "Finished Message",
+ info: "Machine is up!"
+</pre></div>
+<p>Triggers can also be defined within the scope of guests in a Vagrantfile. These triggers will only run on the configured guest. An example of a guest only trigger:</p> <div class="highlight"><pre class="highlight ruby" data-language="ruby">config.vm.define "ubuntu" do |ubuntu|
+ ubuntu.vm.box = "ubuntu"
+ ubuntu.trigger.before :destroy do |trigger|
+ trigger.warn = "Dumping database to /vagrant/outfile"
+ trigger.run_remote = {inline: "pg_dump dbname &gt; /vagrant/outfile"}
+ end
+end
+</pre></div>
+<p>Global and machine-scoped triggers will execute in the order that they are defined within a Vagrantfile. Take for example an abstracted Vagrantfile:</p> <div class="highlight"><pre class="highlight plaintext">Vagrantfile
+ global trigger 1
+ global trigger 2
+ machine defined
+ machine trigger 3
+ global trigger 4
+end
+</pre></div>
+<p>In this generic case, the triggers would fire in the order: 1 -&gt; 2 -&gt; 3 -&gt; 4</p> <p>For more information about what options are available for triggers, see the <a href="configuration">configuration section</a>.</p><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2010&ndash;2018 Mitchell Hashimoto<br>Licensed under the MPL 2.0 License.<br>
+ <a href="https://www.vagrantup.com/docs/triggers/" class="_attribution-link">https://www.vagrantup.com/docs/triggers/</a>
+ </p>
+</div>