|
| 1 | + |
| 2 | +# Roles |
| 3 | + |
| 4 | +Actions in Bootleg are paired with roles, which are simply a collection of hosts that are responsible for the same function, for example building a release, archiving a release, or executing commands against a running application. |
| 5 | + |
| 6 | +Hosts can be grouped into one or more roles. Roles can be declared repeatedly to provide options to different sets of hosts. |
| 7 | + |
| 8 | + |
| 9 | +## Roles provided by Bootleg |
| 10 | + |
| 11 | +| Role | Description | |
| 12 | +|:---|:---| |
| 13 | +| `#!elixir :build` | Takes only one host. If a list is given, only the first host is used. | |
| 14 | +| `#!elixir :app` | Takes a list of hosts, or a string with one host. | |
| 15 | + |
| 16 | +## Defining your own roles |
| 17 | + |
| 18 | +By defining roles, you are defining responsibility groups to cross cut your host infrastructure. The `build` and |
| 19 | +`app` roles have inherent meaning to the default behavior of Bootleg, but you may also define more that you can later filter on when running commands inside a Bootleg hook. |
| 20 | + |
| 21 | +Certain functionality or extensions may require additional roles, for example if your |
| 22 | +release needs to run Ecto migrations, you could assign a `#!elixir primary: true` |
| 23 | +option to one host and then filter on it. |
| 24 | + |
| 25 | +### Syntax |
| 26 | + |
| 27 | +The `role` macro requires both a name, specified as an atom, and a host or list of hosts. Any options you want to apply to those hosts can also be supplied. |
| 28 | + |
| 29 | +### Examples |
| 30 | + |
| 31 | +!!! example "Setting a different SSH option on a single host" |
| 32 | + ```elixir |
| 33 | + role :app, ["host1", "host2"], user: "deploy", identity: "/home/deploy/.ssh/deploy_key.priv" |
| 34 | + role :app, "host2", port: 2222 |
| 35 | + ``` |
| 36 | + Two hosts are declared for the `app` role. Both will use a username of `deploy` and the same public key identity file. Only **host2** will use the non-standard port of *2222*. |
| 37 | + |
| 38 | +!!! example "Setting environment variables for the remote commands" |
| 39 | + ```elixir |
| 40 | + role :app, ["host1", "host2"], env: %{FOO: "bar", BIZ: "baz"} |
| 41 | + ``` |
| 42 | + Two hosts are declared for the `app` role, both using environment variables set for any commands run remotely, `FOO=bar` and `BIZ=baz`. |
| 43 | + |
| 44 | +!!! example "Setting your own host options" |
| 45 | + ```elixir |
| 46 | + role :db, ["db.example.com", "db2.example.com"], user: "datadog" |
| 47 | + role :db, "db.example.com", primary: true |
| 48 | + ``` |
| 49 | + Two hosts are declared for the `db` role. Only `db.example.com` will receive an additional host-specific option for being the primary. Host options can be arbitrarily named and targeted by tasks. |
| 50 | + |
| 51 | +!!! example "Using an internal role option to change behavior" |
| 52 | + Some host options are defined in Bootleg and have special meaning. `release_workspace` can be used when a single remote server is used to both build and run the application. |
| 53 | + ```elixir |
| 54 | + role :build, "example.com", workspace: "/home/deployer/builds", release_workspace: "/home/deployer" |
| 55 | + role :app, "example.com", release_workspace: "/home/deployer" |
| 56 | + ``` |
| 57 | + By specifying a `release_workspace` on the `:build` role, a release is placed in `/home/deployer` after it is built. By specifying a `release_workspace` on the `:app` role, that same release is copied from the `/home/deployer` directory to the app workspace. |
| 58 | + |
| 59 | +### Additional behaviors |
| 60 | + |
| 61 | +There is another built-in role `:all` which includes all hosts assigned to any role. `:all` is only available via `remote/2`. |
0 commit comments