Tasks

class fabric.tasks.Task(alias=None, aliases=None, default=False, *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.

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

Return the host list the given task should be using.

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

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 when it is called, so execute(mytask, 'arg1', kwarg1='value') will (once per host) invoke mytask('arg1', kwarg1='value').

See also

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

New in version 1.3.

Previous topic

Operations

Next topic

Utils

This Page