Install agents with your configuration management
When your machines are managed by Salt (for example through Uyuni) or by
Ansible, install the agent with them: the tool lays down the same files on
every machine, and an upgrade is a change of one value. The agent runs as
the image with the closed core, ghcr.io/fistron-io/fistron-core, a
container that systemd keeps running, as in
install-hybrid.md.
The tool never holds the agent’s secrets (its registration token, its platform tokens, its model’s key): they are entered once on each machine, and the agent starts only when they are there.
Before you start
- For each agent, a registration token from Agents, with the projects it serves (admin-agent.md). A token registers one agent once.
- The agent’s
fistron.toml. Withcontrol_plane_config = trueunder[agent]it holds nothing else: the repositories, CI and clusters it may read, its model endpoints and its data class are then set in the control plane’s GUI, and the state is applied again only for a new version of Fistron, never for a setting (Set an agent’s configuration in the control plane). Without the consent the file holds them: the repositories, CI and clusters with the names of the variables that hold their tokens (Connect GitHub and GitLab, Connect Jenkins), and its model endpoints (Configure models (LLM endpoints)). - Read access to Fistron’s images (a token with
read:packages, given with your pilot or licence) and the image’s version: the one your control plane names (onapp.fistron.io, its release notes). - Docker (or Podman 4.4 or later) from the machine’s software channels. Where a distribution ships it in a separate module or repository, enable that first (in Uyuni: add the product, synchronise it and assign its channels to the machines).
- Outbound HTTPS from the machine to the control plane,
ghcr.io, and the platforms and model endpoints the configuration names.
What is installed
| Path | What |
|---|---|
/etc/fistron-agent/<name>/fistron.toml |
the agent’s configuration (no secret) |
/etc/fistron-agent/<name>/unit.env |
the image, the control plane’s URL, the user’s uid and gid |
/etc/fistron-agent/<name>/agent.env |
the secrets, root’s only (0600), written on the machine |
/etc/fistron-agent/<name>/ca/ |
a private CA’s ca.pem, if a platform needs one |
/var/lib/fistron-agent/<name>/ |
its credential and workspace, the user fistron-agent’s only |
/etc/systemd/system/fistron-agent@.service |
the unit, one instance per agent: fistron-agent@<name> |
/usr/local/sbin/fistron-agent-secrets |
asks for the secrets once and starts the agent |
<name> is the agent’s name, lower-case letters, digits and -, for
example ci-runner.
The unit
fistron-agent@.service (Docker; for Podman see below):
[Unit]
Description=Fistron agent %i
Wants=network-online.target
After=network-online.target docker.service
Requires=docker.service
[Service]
EnvironmentFile=/etc/fistron-agent/%i/unit.env
ExecStartPre=-/usr/bin/docker rm -f fistron-agent-%i
ExecStartPre=/usr/bin/docker pull -q ${IMAGE}
# registers once with the token of agent.env; later starts keep the credential
ExecStartPre=/usr/bin/docker run --rm --name fistron-agent-%i-register \
--user ${AGENT_UID}:${AGENT_GID} --read-only --tmpfs /tmp \
--cap-drop ALL --security-opt no-new-privileges \
--env-file /etc/fistron-agent/%i/agent.env \
-v /var/lib/fistron-agent/%i/credentials:/credentials \
${IMAGE} fistron agent register --url ${URL} --credentials /credentials/agent.json --if-missing
ExecStart=/usr/bin/docker run --rm --name fistron-agent-%i \
--user ${AGENT_UID}:${AGENT_GID} --read-only --tmpfs /tmp \
--cap-drop ALL --security-opt no-new-privileges \
--env-file /etc/fistron-agent/%i/agent.env \
-v /var/lib/fistron-agent/%i/credentials:/credentials \
-v /var/lib/fistron-agent/%i/workspace:/workspace \
-v /etc/fistron-agent/%i/fistron.toml:/config/fistron.toml:ro \
-v /etc/fistron-agent/%i/ca:/config/ca:ro \
${IMAGE} fistron agent run --workspace /workspace --config /config/fistron.toml \
--credentials /credentials/agent.json --create-workspace
# SIGTERM: the agent finishes the work in hand first
ExecStop=/usr/bin/docker stop -t 300 fistron-agent-%i
TimeoutStopSec=330
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target
A private CA is ca_file = "/config/ca/ca.pem" in the section that needs
it. A proxy is HTTPS_PROXY= and NO_PROXY= lines in agent.env.
The secrets
fistron-agent-secrets, run once as root on each machine
(sudo fistron-agent-secrets <name>) after the tool laid the files down.
A variable the agent’s configuration in the control plane names (a work
warns of one the agent lacks) is given after the name:
sudo fistron-agent-secrets <name> FISTRON_QWEN_API_KEY.
#!/usr/bin/env bash
# The secrets of a Fistron agent, entered on its machine, never through the
# configuration management: the registration token while the agent has no
# credential, and every variable its fistron.toml names (or given after the
# name) that agent.env lacks; then the agent starts. Running it again asks only
# for what is missing.
set -euo pipefail
NAME=${1:?usage: $0 <name> [variable ...]}
shift
for variable in "$@"; do
[[ "$variable" =~ ^[A-Z_][A-Z0-9_]{0,99}$ ]] || { echo "$variable: not a variable's name" >&2; exit 1; }
done
[[ "$NAME" =~ ^[a-z0-9][a-z0-9-]{0,40}$ ]] || { echo "name: lower-case letters, digits, -" >&2; exit 1; }
[ "$(id -u)" = 0 ] || { echo "run it as root (sudo)" >&2; exit 1; }
dir=/etc/fistron-agent/$NAME
config=$dir/fistron.toml
env_file=$dir/agent.env
credentials=/var/lib/fistron-agent/$NAME/credentials/agent.json
[ -f "$config" ] || { echo "no $config: install the agent's files first" >&2; exit 1; }
umask 077
touch "$env_file"
chmod 0600 "$env_file"
ask() {
local value
read -r -s -p "$2: " value < /dev/tty
echo
printf '%s=%s\n' "$1" "$value" >> "$env_file"
}
if [ ! -s "$credentials" ] && ! grep -q '^FISTRON_AGENT_REGISTRATION_TOKEN=' "$env_file"; then
ask FISTRON_AGENT_REGISTRATION_TOKEN "FISTRON_AGENT_REGISTRATION_TOKEN (fcr_..., from Agents)"
fi
while read -r variable; do
grep -q "^$variable=" "$env_file" || ask "$variable" "$variable (named in the configuration)"
done < <({ sed -n 's/^[[:space:]]*[a-z_]*_env[[:space:]]*=[[:space:]]*"\([A-Z0-9_]*\)".*/\1/p' "$config"
printf '%s\n' "$@"; } | grep . | sort -u)
systemctl enable fistron-agent@"$NAME"
systemctl restart fistron-agent@"$NAME"
echo "logs: journalctl -u fistron-agent@$NAME -f"
echo "once registered, remove the spent token: sed -i '/^FISTRON_AGENT_REGISTRATION_TOKEN=/d' $env_file"
With Salt
Put the state and its files in one directory of your file roots, for
example salt://fistron-agent/: init.sls below, fistron-agent@.service,
fistron-agent-secrets and the agent’s <name>.fistron.toml. Set name
and image at its top (or read them from pillar: they are no secrets).
{%- set name = "ci-runner" %}
{%- set url = "https://app.fistron.io" %}
{%- set image = "ghcr.io/fistron-io/fistron-core:<version>" %}
{%- set here = "salt://" ~ slspath %}
{%- set etc = "/etc/fistron-agent/" ~ name %}
{%- set var = "/var/lib/fistron-agent/" ~ name %}
fistron-docker:
pkg.installed:
- name: docker
service.running:
- name: docker
- enable: true
- require:
- pkg: fistron-docker
fistron-agent-user:
group.present:
- name: fistron-agent
- system: true
user.present:
- name: fistron-agent
- system: true
- gid: fistron-agent
- home: /var/lib/fistron-agent
- createhome: false
- shell: /sbin/nologin
- require:
- group: fistron-agent-user
{%- for directory, mode in (("/etc/fistron-agent", "0755"), (etc, "0700"), (etc ~ "/ca", "0755")) %}
{{ directory }}:
file.directory:
- user: root
- group: root
- mode: "{{ mode }}"
{%- endfor %}
{%- for directory in ("/var/lib/fistron-agent", var, var ~ "/credentials", var ~ "/workspace") %}
{{ directory }}:
file.directory:
- user: fistron-agent
- group: fistron-agent
- mode: "0700"
- require:
- user: fistron-agent-user
{%- endfor %}
{{ etc }}/fistron.toml:
file.managed:
- source: {{ here }}/{{ name }}.fistron.toml
- mode: "0644"
- require:
- file: {{ etc }}
fistron-agent-unit-env:
cmd.run:
- name: >-
printf 'IMAGE=%s\nURL=%s\nAGENT_UID=%s\nAGENT_GID=%s\n'
'{{ image }}' '{{ url }}' "$(id -u fistron-agent)" "$(id -g fistron-agent)"
> {{ etc }}/unit.env && chmod 0644 {{ etc }}/unit.env
- unless: >-
test "$(cat {{ etc }}/unit.env 2>/dev/null)" = "$(printf 'IMAGE=%s\nURL=%s\nAGENT_UID=%s\nAGENT_GID=%s'
'{{ image }}' '{{ url }}' "$(id -u fistron-agent)" "$(id -g fistron-agent)")"
- require:
- user: fistron-agent-user
- file: {{ etc }}
/etc/systemd/system/fistron-agent@.service:
file.managed:
- source: {{ here }}/fistron-agent@.service
- mode: "0644"
/usr/local/sbin/fistron-agent-secrets:
file.managed:
- source: {{ here }}/fistron-agent-secrets
- mode: "0755"
fistron-agent-daemon-reload:
cmd.run:
- name: systemctl daemon-reload
- onchanges:
- file: /etc/systemd/system/fistron-agent@.service
fistron-agent@{{ name }}:
service.running:
- enable: true
- onlyif: test -f {{ etc }}/agent.env
- require:
- service: fistron-docker
- cmd: fistron-agent-daemon-reload
- watch:
- file: {{ etc }}/fistron.toml
- cmd: fistron-agent-unit-env
- file: /etc/systemd/system/fistron-agent@.service
Apply it (salt '<machine>' state.apply fistron-agent), then on the
machine, once:
sudo docker login ghcr.io -u <user> # the read:packages token
sudo fistron-agent-secrets ci-runner
As an Uyuni state channel
With Uyuni the state is a state channel, assigned to the machines in its web UI; nothing is installed on the Uyuni server.
- Make Docker installable on the machines: in Uyuni, add the product or repository that ships it, synchronise it and assign its channels to the machines (and to their activation key).
- Under Configuration, Channels, create a state channel, for example with
the label
fistron-agent, and pasteinit.slsabove as its SLS contents. - In that channel, upload three files, each under its own name:
fistron-agent@.service,fistron-agent-secretsand<name>.fistron.toml. The state reads them beside itself (slspath). - On each machine’s page, under States, Configuration Channels, subscribe it to the channel and apply its highstate. Docker runs; the agent does not start yet.
- On each machine, once:
sudo docker login ghcr.io -u <user>andsudo fistron-agent-secrets <name>.
With Ansible
The same files from a playbook; files/ beside it holds the unit, the
secrets script and <name>.fistron.toml.
- name: Fistron agent
hosts: fistron_agents
become: true
vars:
agent_name: ci-runner
control_plane: https://app.fistron.io
image: ghcr.io/fistron-io/fistron-core:<version>
etc: "/etc/fistron-agent/{{ agent_name }}"
var: "/var/lib/fistron-agent/{{ agent_name }}"
tasks:
- name: Docker
ansible.builtin.package: {name: docker, state: present}
- name: Docker runs
ansible.builtin.service: {name: docker, state: started, enabled: true}
- name: The user fistron-agent
ansible.builtin.user:
name: fistron-agent
system: true
home: /var/lib/fistron-agent
create_home: false
shell: /sbin/nologin
- name: Root's directories
ansible.builtin.file: {path: "{{ item.path }}", state: directory, owner: root, group: root, mode: "{{ item.mode }}"}
loop:
- {path: /etc/fistron-agent, mode: "0755"}
- {path: "{{ etc }}", mode: "0700"}
- {path: "{{ etc }}/ca", mode: "0755"}
- name: The agent's directories
ansible.builtin.file: {path: "{{ item }}", state: directory, owner: fistron-agent, group: fistron-agent, mode: "0700"}
loop: [/var/lib/fistron-agent, "{{ var }}", "{{ var }}/credentials", "{{ var }}/workspace"]
- name: The user's ids
ansible.builtin.getent: {database: passwd, key: fistron-agent}
- name: The configuration
ansible.builtin.copy: {src: "files/{{ agent_name }}.fistron.toml", dest: "{{ etc }}/fistron.toml", mode: "0644"}
notify: Restart the agent
- name: The unit's settings
ansible.builtin.copy:
dest: "{{ etc }}/unit.env"
mode: "0644"
content: |
IMAGE={{ image }}
URL={{ control_plane }}
AGENT_UID={{ getent_passwd['fistron-agent'][1] }}
AGENT_GID={{ getent_passwd['fistron-agent'][2] }}
notify: Restart the agent
- name: The unit
ansible.builtin.copy: {src: files/fistron-agent@.service, dest: /etc/systemd/system/fistron-agent@.service, mode: "0644"}
notify: Restart the agent
- name: The secrets script
ansible.builtin.copy: {src: files/fistron-agent-secrets, dest: /usr/local/sbin/fistron-agent-secrets, mode: "0755"}
- name: Are the secrets entered?
ansible.builtin.stat: {path: "{{ etc }}/agent.env"}
register: secrets
- name: The agent runs once they are
ansible.builtin.systemd_service: {name: "fistron-agent@{{ agent_name }}", state: started, enabled: true, daemon_reload: true}
when: secrets.stat.exists
handlers:
- name: Restart the agent
ansible.builtin.systemd_service: {name: "fistron-agent@{{ agent_name }}", state: restarted, daemon_reload: true}
when: secrets.stat.exists
Then on each machine, once, sudo docker login ghcr.io -u <user> and
sudo fistron-agent-secrets <name>.
Podman instead of Docker
Podman runs the same unit as root: replace /usr/bin/docker by
/usr/bin/podman in it, remove docker.service from After= and the
line Requires=docker.service, install the package podman instead of
docker and log in with sudo podman login ghcr.io. For a rootless agent
under its own user, lay down the Quadlet file of
install-hybrid.md
instead.
Upgrade and change
- A new version: change
imageand apply again. The agent restarts with it; its credential and secrets stay. Keep it within one minor version of the control plane. - A new
fistron.toml: apply again; the agent restarts. When it names a variableagent.envlacks, runsudo fistron-agent-secrets <name>on the machine: it asks only for that one. - Another agent on the same machine: another
<name>with its own configuration and registration token; the unit is shared.
Check
- On the machine:
systemctl status fistron-agent@<name>andjournalctl -u fistron-agent@<name> -fshow the registration and the agent waiting for work. - Open Agents: the agent answers, with its version and what it reaches.
Troubleshooting
| You see | Cause and fix |
|---|---|
| The agent does not start after applying | Its secrets are not entered yet: run sudo fistron-agent-secrets <name> on the machine. |
docker pull is denied |
The machine is not logged in to ghcr.io, or the token lacks read:packages: sudo docker login ghcr.io. |
The package docker is not found |
Its module or repository is not enabled on the machine (in Uyuni: its channels are not assigned). |
| The agent stops with exit code 1 | Its registration token was spent or expired before it registered, or its credential was revoked: create a new token, delete its line from agent.env, run fistron-agent-secrets again. |
| State silent | The machine cannot reach the control plane: check its egress and the proxy lines of agent.env. |