sys.pkg
Note
This document describes sys.pkg module usage.
Synopsis
Cross-platform package management module. It inspects package state (installed version, available version, upgradable), installs, removes, updates, upgrades and searches packages across FreeBSD, OpenBSD, NetBSD, Linux and macOS.
This module follows the Sysinspect inspect-then-act philosophy: operations
like install, remove and upgrade first check the current state
and skip the action if it is already satisfied (e.g. skip install if the
package is already present). The force option bypasses this check.
Usage
The following options are available:
- check
Inspect package state. Returns structured data with
installed,installed_version,available_version,upgradableandrepofields. No changes are made to the system.- install
Install a package. The module first checks whether the package is already installed — if so, the operation is skipped with a status message. Use
forceto always run the install command.- remove
Remove a package. The module first checks whether the package is installed — if not, the operation is skipped. Use
forceto always run the remove command.- update
Update package repository metadata (e.g.
pkg updateorapt-get update). No inspection is needed.- upgrade
Upgrade one or all packages. If a package name is given, the module checks whether it is actually upgradable before proceeding. For bulk upgrades (no name argument), the module lists upgradable packages first and reports how many will be upgraded.
- search
Search for a package by name. No inspection is needed.
- dry-run
Print the command that would be run, without executing it. Useful for testing and debugging across different operating systems.
- force
Skip the pre-inspection step and execute the operation immediately, regardless of current package state.
The following keyword arguments are available:
- name (type: string)
Package name. Required for
check,install,removeandsearch. Optional forupdate(ignored) andupgrade.
Supported Package Managers
Platform |
Package Manager |
|---|---|
FreeBSD |
|
OpenBSD |
|
NetBSD |
|
Linux |
|
macOS |
|
Examples
Check if a package is installed and whether an upgrade is available
(the $ state key selects the default state):
actions:
check-nginx:
module: sys.pkg
bind:
- target-host
state:
$:
opts:
- check
args:
name:
- nginx
Install a package (only if not already present):
actions:
install-nginx:
module: sys.pkg
bind:
- target-host
state:
$:
opts:
- install
args:
name:
- nginx
Force reinstall even if the package is already there:
actions:
force-install-nginx:
module: sys.pkg
bind:
- target-host
state:
$:
opts:
- install
- force
args:
name:
- nginx
Dry-run an install to see what command would be executed:
actions:
dry-run-install:
module: sys.pkg
bind:
- target-host
state:
$:
opts:
- install
- dry-run
args:
name:
- nginx
Update repository metadata and upgrade all packages:
actions:
refresh-packages:
module: sys.pkg
bind:
- target-host
state:
$:
opts:
- update
- upgrade
Returning Data
- check
Returns structured package state suitable for CM decision-making.
{ "data": { "name": "bash", "installed": true, "installed_version": "5.2.21", "available_version": "5.2.21", "upgradable": false, "repo": "main" }, "retcode": 0, "message": "Package 'bash' is installed (v5.2.21) — up to date" }
- install / remove / update / upgrade / search
Default return for mutation operations.
{ "retcode": 0, "message": "Package operation 'install' completed" }