Rake task documentation up to date
This commit is contained in:
parent
3d85edd41e
commit
e2fe34c583
39
docs/rake.md
39
docs/rake.md
|
@ -66,18 +66,29 @@ around it:
|
||||||
task :up do
|
task :up do
|
||||||
puts "About to run vagrant-up..."
|
puts "About to run vagrant-up..."
|
||||||
env = Vagrant::Environment.load!
|
env = Vagrant::Environment.load!
|
||||||
env.commands.up
|
env.commands.subcommand("up")
|
||||||
puts "Finished running vagrant-up"
|
puts "Finished running vagrant-up"
|
||||||
end
|
end
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
|
The arguments to `subcommand` are simply an array of parameters
|
||||||
|
that you'd typically sent to the command line client, ignoring the `vagrant`
|
||||||
|
part. This allows you to do more complex things easily:
|
||||||
|
|
||||||
|
{% highlight ruby %}
|
||||||
|
desc "Package my environment with a custom file"
|
||||||
|
task :package do
|
||||||
|
env = Vagrant::Environment.load!
|
||||||
|
env.commands.subcommand("package", "--include", "MyCustomFile")
|
||||||
|
end
|
||||||
|
{% endhighlight %}
|
||||||
|
|
||||||
## SSH Commands
|
## SSH Commands
|
||||||
|
|
||||||
Perhaps you want to write a rake task that does some commands within the
|
Perhaps you want to write a rake task that does some commands within the
|
||||||
virtual server setup? This can be done through the `ssh` accessor of the
|
virtual server setup? This can be done through the `ssh` accessor of any
|
||||||
environment, which is an instance of `Vagrant::SSH`. `Vagrant::SSH`
|
VM within the environment, which is an instance of `Vagrant::SSH`. `Vagrant::SSH`
|
||||||
is simply a wrapper around `Net::SSH` and the objects returned are typically
|
is simply a wrapper around `Net::SSH`.
|
||||||
`Net::SSH` objects.
|
|
||||||
|
|
||||||
The following example is a useful example showing how to create a graceful
|
The following example is a useful example showing how to create a graceful
|
||||||
shutdown command:
|
shutdown command:
|
||||||
|
@ -86,11 +97,25 @@ shutdown command:
|
||||||
task :graceful_down do
|
task :graceful_down do
|
||||||
env = Vagrant::Environment.load!
|
env = Vagrant::Environment.load!
|
||||||
env.require_persisted_vm
|
env.require_persisted_vm
|
||||||
env.ssh.execute do |ssh|
|
env.primary_vm.ssh.execute do |ssh|
|
||||||
ssh.exec!("sudo halt")
|
ssh.exec!("sudo halt")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
This example also shows `env.require_persisted_vm` which simply errors and
|
This example also shows `env.require_persisted_vm` which simply errors and
|
||||||
exits if there is no Vagrant VM created yet.
|
exits if there is no Vagrant VM created yet.
|
||||||
|
|
||||||
|
Additionally, if you're in a [multi-VM environment](/docs/multivm.html), you can
|
||||||
|
access the VMs through the `vms` array on the environment:
|
||||||
|
|
||||||
|
{% highlight ruby %}
|
||||||
|
task :graceful_down do
|
||||||
|
env = Vagrant::Environment.load!
|
||||||
|
env.vms.each do |vm|
|
||||||
|
vm.ssh.execute do |ssh|
|
||||||
|
ssh.exec!("sudo halt")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
{% endhighlight %}
|
||||||
|
|
Loading…
Reference in New Issue