package
An OS package, installed with dnf on the Red Hat family and apt on Debian and Ubuntu.
Use package to install, upgrade or remove an operating system package with the host’s own package manager: dnf on Rocky Linux, RHEL, AlmaLinux and Fedora, zypper on openSUSE and SUSE Linux Enterprise, apt on Debian and Ubuntu, and apk on Alpine.
Example usage
Section titled “Example usage”Install a package:
step "nginx" { package { name = "nginx" }}Install several packages, one instance per package and host:
step "tools" { for_each = ["git", "jq", "tree"] package { name = item.value }}Pin a version, keep a package at the newest available version, or remove one:
step "pinned" { package { name = "nginx" version = "1.26.3" }}
step "current" { package { name = "curl" state = "latest" }}
step "gone" { package { name = "telnet" state = "absent" }}Arguments
Section titled “Arguments”| Name | Type | Required | Description |
|---|---|---|---|
install_recommends |
bool | No | Whether an install also brings in what the package recommends: apt’s recommended packages, or dnf’s weak dependencies. false keeps a server lean. Unset keeps the host’s own setting. It only changes how the package is installed, never what’s already there. |
name |
string | Yes | Package name. |
on_remove |
string | No | What happens on the host when this resource is removed: “forget” (default) leaves the package, “delete” uninstalls it. |
state |
string | No | “present” (default), “latest” or “absent”. |
version |
string | No | Version to install, with state “present”. |
Read-only attributes
Section titled “Read-only attributes”Conn3x sets these; reference them as conn3x_package.<circuit>__<step>["<host>"].<name>.
| Name | Type | Description |
|---|---|---|
installed_version |
string | Version installed on the host, or null when it isn’t installed. |
latest_version |
string | Newest available version, read when state is “latest”. |
revision |
string | Changes each time Conn3x changes this on the host. Handlers watch it. |
A step lowers to the conn3x_package 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 asks the package database whether the package is installed and at which version: rpm -q on the Red Hat family and SUSE, dpkg-query on Debian and Ubuntu, and apk list -I on Alpine. On the Red Hat family it also accepts a package that provides the name, so wget matches wget2-wget on Fedora. With state = "latest", it also reads the newest available version, from dnf repoquery, zypper search, apt-cache policy or apk list.
Versions. version matches the start of the installed version, so "1.26.3" matches 1:1.26.3-2.el10. Give the epoch or the release as well when you need an exact match.
Applying. Conn3x runs dnf -y install, upgrade or remove, apt-get install or remove non-interactively, keeping existing configuration files, zypper install, update or remove, or apk add --no-cache and apk del. On SUSE, a version such as 1.7.0 installs the newest release of it, with --oldpackage, so a pin below the installed version downgrades, as Ansible’s zypper does. zypper’s exit 102, installed but a reboot is wanted, counts as success, and on 103, zypper updated itself, the command runs once more. 106, a repository that couldn’t be refreshed, and 107, a package’s install script failing, fail the step. install_recommends sets --recommends or --no-recommends, and package_hold is a zypper lock. A repository step adds a zypper repository and imports its key, so a package step after it can install from it. On Alpine, --no-cache fetches the package index each time, so a fresh host needs no apk update first. A version there is a pin such as 2.2.1 or 2.2.1-r0, which apk keeps in /etc/apk/world, and install_recommends is refused, since apk has no recommended packages. package_hold, repository and package_sources don’t manage Alpine: pin with version, and keep /etc/apk/repositories with a line step. When another apt, dnf or zypper holds the package manager’s lock, such as a step from another circuit on the same host or unattended upgrades on a host that just booted, Conn3x waits up to five minutes for it. When apt can’t find a package on a fresh host, Conn3x refreshes the package lists once and tries again. If a mirror fails that refresh, with a timeout or an error such as a 403, Conn3x runs apt-get update again up to five times in all, waiting 1, 2, 4 and then 8 seconds, as Ansible’s apt does with its update_cache_retries.
Removal
Section titled “Removal”When you delete a package step, on_remove decides what happens on the host. The default, "forget", leaves the package installed and stops managing it. "delete" uninstalls it.
From Ansible
Section titled “From Ansible”conn3x convert ansible turns ansible.builtin.package, dnf, dnf5, yum, apt, community.general.zypper and community.general.apk tasks into package steps. state: installed and removed become present and absent, and update_cache is dropped, since Conn3x refreshes the package lists itself when a package isn’t found. apt’s install_recommends and dnf’s and dnf5’s install_weak_deps all become install_recommends, which sets apt’s APT::Install-Recommends or dnf’s install_weak_deps for the install. Ansible’s zypper leaves recommended packages out unless disable_recommends: false, so a converted zypper step sets install_recommends to match. A zypper type other than package, such as a pattern or a patch, stays a TODO, and so does state: dist-upgrade.