πŸ“¦ package

πŸ“¦ package

Install, remove, or manage system packages using the OS package manager (apt, yum, dnf, etc.).

⚑ Actions

Action Description
:install Install the package (default)
:remove Remove the package
:nothing Do nothing (use with notifications)

πŸ“‹ Attributes

Attribute Type Default Description
name String Resource name Package name (auto-set from resource name)
version String β€” Specific version to install
options String β€” Additional package manager options

πŸ’‘ The name attribute uses default_name β€” it automatically takes the value you pass as the resource name (e.g., package 'nginx' sets name to "nginx").

πŸ” How It Works

  1. Query β€” Checks if the package is installed via the system package manager
  2. Compare β€” If version is specified, compares against the currently installed version
  3. Install/Remove β€” Runs the appropriate package manager command
  4. Idempotent β€” Won’t reinstall if already at the desired version

πŸ”¬ Dry-Run Behavior

In dry-run mode, the current package state is fully queried. You see exactly which packages would be installed or removed, and version changes. No packages are actually installed or removed.

πŸ“– Examples

Install a package

package 'nginx'

Install with a specific version

package 'sl' do
  version '3.03-17'
end

Install multiple packages

%w[git curl wget vim].each do |pkg|
  package pkg
end

Install with options

package 'nginx' do
  options '--force-yes'
end

Remove a package

package 'apache2' do
  action :remove
end

Notify a service on install

package 'nginx' do
  notifies :restart, 'service[nginx]'
end