class fabric.tasks.Task(alias=None, aliases=None, default=False, name=None, *args, **kwargs)

Abstract base class for objects wishing to be picked up as Fabric tasks.

Instances of subclasses will be treated as valid tasks when present in fabfiles loaded by the fab tool.

For details on how to implement and use Task subclasses, please see the usage documentation on new-style tasks.

New in version 1.1.


list of weak references to the object (if defined)

get_hosts_and_effective_roles(arg_hosts, arg_roles, arg_exclude_hosts, env=None)

Return a tuple containing the host list the given task should be using and the roles being used.

See How host lists are constructed for detailed documentation on how host lists are set.

Changed in version 1.9.

class fabric.tasks.WrappedCallableTask(callable, *args, **kwargs)

Wraps a given callable transparently, while marking it as a valid Task.

Generally used via task and not directly.

New in version 1.1.

See also

unwrap_tasks, task

fabric.tasks.execute(task, *args, **kwargs)

Execute task (callable or name), honoring host/role decorators, etc.

task may be an actual callable object, or it may be a registered task name, which is used to look up a callable just as if the name had been given on the command line (including namespaced tasks, e.g. "deploy.migrate".

The task will then be executed once per host in its host list, which is (again) assembled in the same manner as CLI-specified tasks: drawing from -H, env.hosts, the hosts or roles decorators, and so forth.

host, hosts, role, roles and exclude_hosts kwargs will be stripped out of the final call, and used to set the task’s host list, as if they had been specified on the command line like e.g. fab taskname:host=hostname.

Any other arguments or keyword arguments will be passed verbatim into task (the function itself – not the @task decorator wrapping your function!) when it is called, so execute(mytask, 'arg1', kwarg1='value') will (once per host) invoke mytask('arg1', kwarg1='value').

Returns:a dictionary mapping host strings to the given task’s return value for that host’s execution run. For example, execute(foo, hosts=['a', 'b']) might return {'a': None, 'b': 'bar'} if foo returned nothing on host a but returned 'bar' on host b.

In situations where a task execution fails for a given host but overall progress does not abort (such as when env.skip_bad_hosts is True) the return value for that host will be the error object or message.

See also

The execute usage docs, for an expanded explanation and some examples.

New in version 1.3.

Changed in version 1.4: Added the return value mapping; previously this function had no defined return value.


Returns True if given task should be run in parallel mode.


  • It’s been explicitly marked with @parallel, or:
  • It’s not been explicitly marked with @serial and the global parallel option (env.parallel) is set to True.