summaryrefslogtreecommitdiff
path: root/devdocs/vagrant/push%2Flocal-exec.html
blob: e9df2f6fb5a045e04828543481130720411c36ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<h1 id="vagrant-push">  Vagrant Push </h1> <h2 id="local-exec-strategy">  Local Exec Strategy </h2> <p>The Vagrant Push Local Exec strategy allows the user to invoke an arbitrary shell command or script as part of a push.</p> <blockquote class="alert alert-warning"> <p><strong>Warning:</strong> The Vagrant Push Local Exec strategy does not perform any validation on the correctness of the shell script.</p> </blockquote>
<p>The Vagrant Push Local Exec strategy supports the following configuration options:</p> <ul> <li>
<a href="#script"><code>script</code></a> - The path to a script on disk (relative to the <code>Vagrantfile</code>) to execute. Vagrant will attempt to convert this script to an executable, but an exception will be raised if that fails. </li> <li>
<a href="#inline"><code>inline</code></a> - The inline script to execute (as a string). </li> <li>
<a href="#args"><code>args</code></a> (string or array) - Optional arguments to pass to the shell script when executing it as a single string. These arguments must be written as if they were typed directly on the command line, so be sure to escape characters, quote, etc. as needed. You may also pass the arguments in using an array. In this case, Vagrant will handle quoting for you. </li> </ul> <p>Please note - only one of the <code>script</code> and <code>inline</code> options may be specified in a single push definition.</p> <h3 id="usage">  Usage </h3> <p>The Vagrant Push Local Exec strategy is defined in the <code>Vagrantfile</code> using the <code>local-exec</code> key:</p> <p>Remote path:</p> <div class="highlight"><pre class="highlight ruby" data-language="ruby">config.push.define "local-exec" do |push|
  push.inline = &lt;&lt;-SCRIPT
    scp -r . server:/var/www/website
  SCRIPT
end
</pre></div>
<p>Local path:</p> <div class="highlight"><pre class="highlight ruby" data-language="ruby">config.push.define "local-exec" do |push|
  push.inline = &lt;&lt;-SCRIPT
    cp -r . /var/www/website
  SCRIPT
end
</pre></div>
<p>For more complicated scripts, you may store them in a separate file and read them from the <code>Vagrantfile</code> like so:</p> <div class="highlight"><pre class="highlight ruby" data-language="ruby">config.push.define "local-exec" do |push|
  push.script = "my-script.sh"
end
</pre></div>
<p>And then invoke the push with Vagrant:</p> <div class="highlight"><pre class="highlight shell" data-language="shell">$ vagrant push
</pre></div>
<h3 id="script-arguments">  Script Arguments </h3> <p>Refer to <a href="../provisioning/shell">Shell Provisioner</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/push/local-exec.html" class="_attribution-link">https://www.vagrantup.com/docs/push/local-exec.html</a>
  </p>
</div>