Skip to main content

Working Directory

Change Working Directory

You can change the default work_dir in the server section and the task section (nested tasks/commands included). The order of precedence is as follows:

  1. task list
  2. task
  3. referenced task
  4. server
  5. default, which is
    • the executed task directory for local clients
    • the users home directory for remote clients
servers:
localhost:
host: localhost
work_dir: "/opt" # 4
local: true

tasks:
work-ref:
name: pwd
work_dir: "/usr" # 3
cmd: pwd

work-dir:
work_dir: "/home" # 2
tasks:
- task: work-ref

- cmd: pwd
name: pwd

- cmd: pwd
name: pwd
work_dir: "/" # 1

See example:

$ sake run work-dir --output table

Server | Pwd | Pwd | Pwd
-----------+-------+-------+-----
localhost | /home | /home | /

# if we comment work_dir (# 2) then we get

Server | Pwd | Pwd | Pwd
-----------+------+------+-----
localhost | /usr | /opt | /

The complete decision tree for composing a working directory is found below.

Note:

  • Absolute directories (/opt) won't be joined.
  • The variables Task Context and Server Context are the local directories where the tasks/servers are defined.

Remote Tasks

Resolve work_dir according to Server Dir and Task Dir:

HostTaskServer DirTask Dirwork_dir
remoteremote""""/home/user
remoteremote"""task"/home/user/task
remoteremote"server"""/home/user/server
remoteremote"server""task"/home/user/server/task

Local Tasks

Resolve work_dir according to Task Context:

HostTaskServer DirTask Dirwork_dir
locallocal""""[Task Context]
localremote""""[Task Context]
remotelocal""""[Task Context]
remotelocal"server"""[Task Context]

Resolve work_dir according to Task Context and Task Dir:

HostTaskServer DirTask Dirwork_dir
locallocal"""task"[Task Context]/task
localremote"""task"[Task Context]/task
remotelocal"""task"[Task Context]/task
remotelocal"server""task"[Task Context]/task

Resolve work_dir according to Server Context and Server Dir:

HostTaskServer DirTask Dirwork_dir
localremote"server"""[Server Context]/server
locallocal"server"""[Server Context]/server

Resolve work_dir according to Server Context, Server Dir and Task Dir:

HostTaskServer DirTask Dirwork_dir
locallocal"server""task"[Server Context]/server/cmd
locallocal"server""task"[Server Context]/server/cmd