alternatives
Manages Debian/Ubuntu update-alternatives entries. Installs and sets the active alternative for a given name.
Parameters
| Parameter | Required | Default | Description |
|---|---|---|---|
name |
Yes | -- | Alternatives name (e.g., editor, java). |
path |
Yes | -- | Path to the actual binary (e.g., /usr/bin/vim). |
state |
Yes | -- | Desired state: present or absent. |
link |
No | /usr/bin/<name> |
Symlink location. Defaults to /usr/bin/<name>. |
priority |
No | 50 |
Priority for this alternative. |
States
present-- Install the alternative and set it as active. Usesupdate-alternatives --installfollowed byupdate-alternatives --set.absent-- Remove the alternative withupdate-alternatives --remove.
Idempotency
Queries the current alternative value using update-alternatives --query. If the current value matches the desired path, no action is taken. Falls back to reading the /etc/alternatives/<name> symlink.
Examples
Basic
resources:
- name: Set editor to vim
type: alternatives
name: editor
path: /usr/bin/vim
priority: "100"
Java alternative
resources:
- name: Set java to openjdk-17
type: alternatives
name: java
path: /usr/lib/jvm/java-17-openjdk-amd64/bin/java
link: /usr/bin/java
priority: "200"
Remove an alternative
resources:
- name: Remove nano as editor
type: alternatives
name: editor
path: /usr/bin/nano
state: absent
Platform
Linux only (requires update-alternatives).
Notes
- The
linkparameter defaults to/usr/bin/<name>, which is the standard location for most alternatives. - When
state: present, both--installand--setare called to ensure the specified path is the active alternative. - Priority is used by the automatic mode of update-alternatives when no manual selection is made.