zester
GuidesModules

pkg.installed

Ensures that a system package is installed using the auto-detected package manager. Supports apt, yum, dnf, and brew.

Source: pkg/state/modules/pkg.go


Parameters

ParameterTypeRequiredDefaultDescription
namestringNoState IDPackage name. If omitted, the state ID is used as the package name.
versionstringNo(latest)Version constraint. Format depends on the package manager (see version pinning below).
refreshboolNofalseForce a package cache refresh before installation (apt-get update, yum makecache, etc.).

All states also accept the full set of requisite parameters and Salt-parity state attributes — see Dependencies & Requisites.


Package Manager Detection

The module detects the package manager in two phases:

Phase 1 — os.family from facts:

OS FamilyPackage ManagerNotes
debianaptDebian, Ubuntu
redhat, rhel, fedora, susednf if available, else yumRed Hat family
darwinbrewmacOS, only if brew is in PATH

Phase 2 — PATH probing (unknown OS families):

If os.family does not match any of the above, the module probes PATH for common package managers in this order: apt-get, dnf, yum, brew.

If no supported package manager is found, the state returns an error.


Version Pinning

Version constraints are formatted according to the detected package manager:

ManagerFormatExample
apt<name>=<version>nginx=1.24.0-1ubuntu1
yum/dnf<name>-<version>nginx-1.24.0
brew<name>@<version>nginx@1.24

Check Behavior

Checks whether the package is installed using the manager-specific query command:

ManagerCheck Command
aptdpkg -s <package>
yum/dnfrpm -q <package>
brewbrew list --formula <package>

Apply Behavior

  1. If refresh is true, refreshes the package cache first.
  2. Runs the install command with automatic confirmation (-y on apt/yum/dnf).
ManagerInstall Command
aptapt-get install -y <package>
yumyum install -y <package>
dnfdnf install -y <package>
brewbrew install <package>

Revert Behavior

Removes the package using the manager-specific remove command:

ManagerRemove Command
aptapt-get remove -y <package>
yumyum remove -y <package>
dnfdnf remove -y <package>
brewbrew uninstall <package>

Examples

Direct Execution

# Install a package on a single peel
zester 'web-01' pkg.installed nginx

# Install on all web peels
zester 'web*' pkg.installed curl

State File

Install with cache refresh:

install_nginx:
  pkg.installed:
    - name: nginx
    - refresh: true

Version-pinned installation:

install_specific_version:
  pkg.installed:
    - name: nginx
    - version: "1.24.0-1ubuntu1"

Multiple packages with dependencies:

install_build_tools:
  pkg.installed:
    - name: build-essential
    - refresh: true

install_git:
  pkg.installed:
    - name: git
    - require:
      - pkg.installed:install_build_tools

install_curl:
  pkg.installed:
    - name: curl
    - require:
      - pkg.installed:install_build_tools

On this page