apt_preference resource¶
The apt_preference resource allows for the creation of APT preference files. Preference files are used to control which package versions and sources are prioritized during installation.
New in Chef Client 13.3.
Syntax¶
The apt_preference resource has the following syntax:
apt_preference 'name' do
glob String
package_name String # default value: 'name' unless specified
pin String
pin_priority String, Integer
action Symbol # defaults to :add if not specified
end
where:
apt_preferenceis the resource.nameis the name given to the resource block.actionidentifies which steps the chef-client will take to bring the node into the desired state.glob,package_name,pin, andpin_priorityare the properties available to this resource.
Actions¶
The apt_preference resource has the following actions:
add- Default action. Creates a preferences file under
/etc/apt/preferences.d. remove- Removes the preferences file, thus unpinning the package.
Properties¶
The apt_preference resource has the following properties:
globRuby Type: String
Pin by
glob()expression or with regular expressions surrounded by/.notifiesRuby Type: Symbol, ‘Chef::Resource[String]’
A resource may notify another resource to take action when its state changes. Specify a
'resource[name]', the:actionthat resource should take, and then the:timerfor that action. A resource may notify more than one resource; use anotifiesstatement for each resource to be notified.A timer specifies the point during the Chef Client run at which a notification is run. The following timers are available:
:before- Specifies that the action on a notified resource should be run before processing the resource block in which the notification is located.
:delayed- Default. Specifies that a notification should be queued up, and then executed at the end of the Chef Client run.
:immediate,:immediately- Specifies that a notification should be run immediately, per resource notified.
The syntax for
notifiesis:notifies :action, 'resource[name]', :timer
package_nameRuby Type: String
The name of the package. Default value:
name.pinRuby Type: String
The package version or repository to pin.
pin_priorityRuby Type: String, Integer
Sets the
Pin-Priorityfor a package. See the APT pinning documentation for more details.subscribesRuby Type: Symbol, ‘Chef::Resource[String]’
A resource may listen to another resource, and then take action if the state of the resource being listened to changes. Specify a
'resource[name]', the:actionto be taken, and then the:timerfor that action.Note that
subscribesdoes not apply the specified action to the resource that it listens to - for example:file '/etc/nginx/ssl/example.crt' do mode '0600' owner 'root' end service 'nginx' do subscribes :reload, 'file[/etc/nginx/ssl/example.crt]', :immediately end
In this case the
subscribesproperty reloads thenginxservice whenever its certificate file, located under/etc/nginx/ssl/example.crt, is updated.subscribesdoes not make any changes to the certificate file itself, it merely listens for a change to the file, and executes the:reloadaction for its resource (in this examplenginx) when a change is detected.A timer specifies the point during the Chef Client run at which a notification is run. The following timers are available:
:before- Specifies that the action on a notified resource should be run before processing the resource block in which the notification is located.
:delayed- Default. Specifies that a notification should be queued up, and then executed at the end of the Chef Client run.
:immediate,:immediately- Specifies that a notification should be run immediately, per resource notified.
The syntax for
subscribesis:subscribes :action, 'resource[name]', :timer
Examples¶
Pin a package to a specific version
This example pins the libmysqlclient16 package to version 5.1.49-3:
apt_preference 'libmysqlclient16' do
pin 'version 5.1.49-3'
pin_priority '700'
end
Note that the pin_priority of 700 ensures that this version will be preferred over any other available versions.
Unpin a package
This example unpins the libmysqlclient16 package, disabling all preferences for it:
apt_preference 'libmysqlclient16' do
action :remove
end
Pin all packages to prefer a specific repository
This example instructs APT to prefer the packages.dotdeb.org repository:
apt_preference 'dotdeb' do
glob '*'
pin 'origin packages.dotdeb.org'
pin_priority '700'
end