Overview

A task contains activities or steps you want to do for a specific remote. When a task is executed against a remote, it introduce a context.

Single Task

In the deploy.py file, you can define a task using the app.task decorator.

from hapi import Context
from hapi.cli import app

@app.task(name='whoami', desc="Run whoami command")
def whoami(c: Context):
    c.run('whoami')

When you run hapi whoami, it will run whoami command on each remote defined remote in the inventory.yml file.

Group Task

You can also group some tasks into one. Let's see the example below. I define some "deploy:*" tasks before grouping them into one called "deploy".

from hapi.cli import app

app.group(
    name="deploy",
    desc="Deploy your project",
    do=[
        "deploy:start",
        "deploy:setup",
        "deploy:lock",
        # ...
    ]
)

name and desc parameters are required. They are displayed on the console when a task is being executed or for help or for logging.

When you hapi deploy, it will run "deploy:start", "deploy:setup" and "deploy:lock" on each remote defined in the inventory.yml file.

Previous
Remotes