How to execute a task on another host without changing the deploy host [Deployer]?

996 Views Asked by At

I want to write a script that connects to a 2nd host to execute commands there.

with dep deploy stage it should executes task on host: live too

  1. It connects to host: live

    makes a db-dump

    and downloads is to the deploy-computer

  2. It connects to host: stage

    uploads the db-dump

    and integrates it there

The basic parts of mysql-dump end mysl-import I know, but how to execute a task on another host?

Thanks for pointing to the right direction!

1

There are 1 best solutions below

2
On BEST ANSWER

Inside each task you can run the "on" function. For this you can supply a host (in your example during a "live" task you would supply "stage"):

        on(host('stage'), function () {
            // do something
        });

If you need to supply some variables (e.g. dynamically created filenames) you can hand them to the new function like with use. So if your task saved your dump to the filename $mysqlDumpFilename, e.g.:

        on(host('stage'), function () use ($mysqlDumpFilename) {
            // do something
        });

Docs: https://deployer.org/docs/api#on