π¦ 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
nameattribute usesdefault_nameβ it automatically takes the value you pass as the resource name (e.g.,package 'nginx'setsnameto"nginx").
π How It Works
- Query β Checks if the package is installed via the system package manager
- Compare β If
versionis specified, compares against the currently installed version - Install/Remove β Runs the appropriate package manager command
- 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