snap
A snap, installed through snapd and kept on a channel.
Use snap for what Ubuntu ships as snaps: lxd, microk8s, certbot, code. It installs a snap that’s missing, moves one onto the channel you name, and tells you on every plan whether the host still matches, which a command step running snap install can’t.
Example usage
Section titled “Example usage”Install LXD:
step "lxd" { snap { name = "lxd" }}Keep MicroK8s on a release track, so a refresh never jumps a minor version:
step "microk8s" { snap { name = "microk8s" channel = "1.28/stable" classic = true }}Take a snap off a host, and remove it again if the step goes:
step "no-chromium" { snap { name = "chromium" state = "absent" on_remove = "delete" }}Arguments
Section titled “Arguments”| Name | Type | Required | Description |
|---|---|---|---|
channel |
string | No | Channel to track, such as stable, 5.21/stable or latest/edge. Without it, a snap that’s installed keeps its channel, and a new one gets the store’s default, stable. |
classic |
bool | No | true allows classic confinement, as snap install –classic does, which snaps such as code and go need. A snap that is already classic stays so when this is false. |
name |
string | Yes | Snap name, such as lxd or microk8s. |
on_remove |
string | No | “forget” (default) leaves the snap, “delete” removes it. |
state |
string | No | “present” (default) or “absent”. |
Read-only attributes
Section titled “Read-only attributes”Conn3x sets these; reference them as conn3x_snap.<circuit>__<step>["<host>"].<name>.
| Name | Type | Description |
|---|---|---|
in_sync |
bool | Whether the snap is installed on channel with the confinement asked for, or absent when state is “absent”. |
revision |
string | Changes each time Conn3x changes this on the host. Handlers watch it. |
A step lowers to the conn3x_snap resource, one instance per host, and connects with its circuit’s ssh block.
How it works
Section titled “How it works”Reading. On every plan, Conn3x runs snap list name and reads the Tracking and Notes columns. in_sync is true when the snap is installed, tracks channel when one is set, and is classic when classic is true. With state = "absent", it’s true when the snap isn’t there. snapd prints no machine-readable listing, so Conn3x asks for plain text with --unicode=never --color=never and reads the columns, which never hold spaces.
Channels. A channel is track/risk, with an optional /branch. stable means latest/stable, and a track alone, such as 5.21, means 5.21/stable, the same as snap install reads them. Without channel, a snap that’s already installed keeps whatever it tracks, and a new one gets the store’s default.
Applying. A missing snap is installed with snap install, with --channel and --classic as set. An installed one that tracks another channel, or needs classic confinement, is moved with snap refresh --channel. A snap that’s already classic stays classic when classic is false, since snapd has no refresh back to strict confinement; remove it first if that’s what you need. snap exits 0 on a refresh that changed nothing, so Conn3x reads the host back and fails the step if it still differs.
Without snapd. A host with no snap command fails the step with an error that names the snapd package to install. A host where snapd is installed but not running fails with snap’s own message.
Changes. Changing channel, classic or state updates the snap in place. Changing name replaces the step, and the old snap is handled by its on_remove.
Removal
Section titled “Removal”on_remove = "forget", the default, leaves the snap installed. on_remove = "delete" runs snap remove name, which keeps snapd’s snapshot of its data, as snap remove does by hand.
From Ansible
Section titled “From Ansible”conn3x convert ansible turns community.general.snap tasks with state: present or absent into snap steps, keeping name, channel and classic. state: enabled and disabled, options and dangerous stay for review, since the step has no equivalent.