Repeated entries
Some machines need several copies of the same setup: one CI runner per slot, one site per customer, one worker per CPU. [bootstrap.repeat.<name>] declares the entries once, and for_each says how many copies to make. Each copy's keys and strings are templates that can read {{ repeat.item }} and {{ repeat.index }}, so every copy gets its own name, path, and values.
Here one Mac mini runs three GitHub Actions runners and another runs two. The count lives in each host's inventory vars, and each runner gets a working directory and a LaunchDaemon:
[bootstrap.remote.hosts.mini-1]
host = "mini-1.lan"
vars = { runners = 3 }
[bootstrap.remote.hosts.mini-2]
host = "mini-2.lan"
vars = { runners = 2 }
[bootstrap.repeat.runners]
for_each = "{{ bootstrap.host.vars.runners | default(value=1) }}"
[bootstrap.repeat.runners.directories."/opt/mise-ci/actions-runner{% if repeat.index > 0 %}-{{ repeat.item }}{% endif %}"]
owner = "mise-ci"
group = "mise-ci"
mode = "0755"
[bootstrap.repeat.runners.macos.launchd.daemons."ci.actions-runner{% if repeat.index > 0 %}-{{ repeat.item }}{% endif %}"]
user = "mise-ci"
group = "mise-ci"
program = "/opt/mise-ci/actions-runner{% if repeat.index > 0 %}-{{ repeat.item }}{% endif %}/run.sh"
working_directory = "/opt/mise-ci/actions-runner{% if repeat.index > 0 %}-{{ repeat.item }}{% endif %}"
environment = { HOME = "/opt/mise-ci/home{% if repeat.index > 0 %}-{{ repeat.item }}{% endif %}" }
run_at_load = true
keep_alive = true
requires_paths = ["/opt/mise-ci/actions-runner{% if repeat.index > 0 %}-{{ repeat.item }}{% endif %}/.runner"]mise bootstrap remote mini-1 declares the directories /opt/mise-ci/actions-runner, actions-runner-2, and actions-runner-3, and the daemons dev.mise.ci.actions-runner, -2, and -3. mini-2 gets the first two of each. A local mise bootstrap has no inventory vars, so the default gives it one runner.
for_each
| Value | Items |
|---|---|
| A number N | 1 to N; 0 declares nothing |
| An array | Each element, which can be a string, a number, or a table |
| A template string | What it renders to: a whole number, or a JSON array |
A template that reads a list renders it with json_encode(), so mise can read the items back:
[bootstrap.remote.hosts.web-1]
host = "web-1.lan"
vars = { sites = [{ name = "shop", port = 8001 }, { name = "blog", port = 8002 }] }
[bootstrap.repeat.sites]
for_each = "{{ bootstrap.host.vars.sites | default(value=[]) | json_encode() }}"
[bootstrap.repeat.sites.files."/etc/nginx/sites-enabled/{{ repeat.item.name }}.conf"]
owner = "root"
mode = "0644"
template = true
content = """
server {
listen {{ repeat.item.port }};
server_name {{ repeat.item.name }}.example.com;
}
"""for_each is required. To declare no copies, make it render 0 or []; a template that renders nothing at all is an error. A block expands to at most 1000 copies.
What a copy can use
| Value | What it is |
|---|---|
{{ repeat.item }} | This copy's item: 1, 2, ... for a count, or the array element |
{{ repeat.index }} | The copy's position, starting at 0 |
{{ repeat.name }} | The block's name, such as runners |
The rest of the bootstrap template context is there too, including {{ bootstrap.host }}, vars, env, and {{ config_root }}. exec() is not: like unit and agent values, a copy renders the same way for status, plan, and --dry-run without running anything.
mise renders every key and string of a copy, including keys and values that the section would otherwise use as written, such as a directory's path or a user's name. A file's content and block are the exception: they keep the template = true rule, so literal {{ ... }} in them stays as written unless you turn templates on. With template = true they render when the file is applied, with repeat, target, and secret() available. A value that must be a number or a boolean, such as a user's uid, cannot come from a template.
Sections a block can hold
A block can declare entries of these sections, written under the block with the same keys as the section itself:
| In the block | Expands into |
|---|---|
files, directories | [bootstrap.files], [bootstrap.directories] |
users, groups | [bootstrap.users], [bootstrap.groups] |
tools | [bootstrap.tools] |
services | [bootstrap.services] |
compose | [bootstrap.compose] |
repos | [bootstrap.repos] |
macos.launchd.agents, .daemons | [bootstrap.macos.launchd] |
linux.systemd.units | [bootstrap.linux.systemd.units] |
How copies behave
mise expands a block into ordinary entries of the file that declares it before anything else reads the configuration. status, plan, apply, the last-applied record, and merging across config files treat a copy exactly like an entry you wrote out by hand:
- A more local config file replaces a copy the same way it replaces any entry with the same key.
- An entry written outside the block wins over a copy with the same key, and mise warns about the copy.
- A block in an included config with the same name as one in the including file is not replaced: both expand, and the included block's copies fill in only the keys the including file does not declare.
- Every copy needs its own key. A key that does not change between items, such as a log directory every runner shares, is an error; declare it outside the block.
- Lowering the count is the same as deleting the copies that are gone from the file. mise stops managing them, and, as for any deleted entry, leaves what they created in place. Remove those yourself, or declare them absent before lowering the count where the section supports
state = "absent". - A block that cannot be expanded, for example because
for_eachis missing or does not render to a number or a list, warns and declares nothing, like any other invalid entry.
See also
- Remote hosts for inventory
vars. - Templates for what bootstrap renders and the context it uses.