Class: Rake::RemoteTask

Class | Rake::RemoteTask
In: | lib/rake_remote_task.rb lib/vlad_test_case.rb
Parent: | Rake::Task

Rake::RemoteTask is a subclass of Rake::Task that adds remote_actions that execute in parallel on multiple hosts via ssh.

### Methods

all_hosts current_roles default_env defined_target_hosts? enhance env execute fetch get host hosts_for new per_thread popen4 put remote_task reset role roles rsync run select set set_defaults sudo system target_hosts task tasks

### Included Modules

Open4

### Classes and Modules

Class Rake::RemoteTask::Action
Class Rake::RemoteTask::Status

### Constants

Status | = | Struct.new :exitstatus

### External Aliases

enhance | -> | original_enhance
| Add a local action to this task. This calls Rake::Task#enhance.

### Attributes

action | [RW] |
commands | [RW] |
error | [RW] |
input | [RW] |
options | [RW] | Options for execution of this task.
output | [RW] |
remote_actions | [R] | An Array of Actions this host will perform during execution. Use enhance to add new actions to a task.
target_host | [RW] | The host this task is running on during execution.

### Public Class methods

all_hosts()

Returns an Array with every host configured.

current_roles()
default_env()

The default environment values. Used for resetting (mostly for tests).

env()

The vlad environment.

fetch(name, default = nil)

Fetches environment variable `name` from the environment using default `default`.

host(host_name, *roles)

Add host `host_name` that belongs to `roles`. Extra arguments may be specified for the host as a hash as the last argument.

host is the inversion of role:

      host 'db1.example.com', :db, :master_db

Is equivalent to:

      role :db, 'db1.example.com'
      role :master_db, 'db1.example.com'

hosts_for(*roles)

Returns an Array of all hosts in `roles`.

new(task_name, app)

Create a new task named `task_name` attached to Rake::Application `app`.

per_thread()
remote_task(name, *args, &block)

Adds a remote task named `name` with options `options` that will execute `block`.

reset()

Resets vlad, restoring all roles, tasks and environment variables to the defaults.

role(role_name, host = nil, args = {}) {|| ...}

Adds role `role_name` with `host` and `args` for that host. TODO: merge: Declare a role and assign a remote host to it. Equivalent to the `host` method; provided for capistrano compatibility.

roles()

The configured roles.

set(name, value = nil, &default_block)

Set environment variable `name` to `value` or `default_block`.

If `default_block` is defined, the block will be executed the first time the variable is fetched, and the value will be used for every subsequent fetch.

set_defaults()

Sets all the default values. Should only be called once. Use reset if you need to restore values.

task()

The Rake::RemoteTask executing in this Thread.

tasks()

The configured Rake::RemoteTasks.

### Public Instance methods

defined_target_hosts?()

Similar to target_hosts, but returns true if user defined any hosts, even an empty list.

enhance(deps=nil, &block)

Add remote action `block` to this task with dependencies `deps`. See Rake::Task#enhance.

execute(args = nil)

Execute this action. Local actions will be performed first, then remote actions will be performed in parallel on each host configured for this RemoteTask.

get(local_dir, *files)

Pull `files` from the remote `host` using rsync to `local_dir`. TODO: what if role has multiple hosts & the files overlap? subdirs?

popen4(*command)
put(remote_path, base_name = File.basename(remote_path)) {|| ...}

Copy a (usually generated) file to `remote_path`. Contents of block are copied to `remote_path` and you may specify an optional base_name for the tempfile (aids in debugging).

rsync(*args)

Execute rsync with `args`. Tacks on pre-specified `rsync_cmd` and `rsync_flags`.

Favor get and put for most tasks. Old-style direct use where the target_host was implicit is now deprecated.

run(command)

Use ssh to execute `command` on target_host. If `command` uses sudo, the sudo password will be prompted for then saved for subsequent sudo commands.

select(reads, writes, errs, timeout)
sudo(command)

Execute `command` under sudo using run.

system(*command)
target_hosts()

The hosts this task will execute on. The hosts are determined from the role this task belongs to.

The target hosts may be overridden by providing a comma-separated list of commands to the HOSTS environment variable:

      rake my_task HOSTS=app1.example.com,app2.example.com

[Validate]