Skip to main content

LegacyNotifySyntax

All Cookstyle Cops


The department is: Chef/Deprecations

The full name of the cop is: Chef/Deprecations/LegacyNotifySyntax


Enabled by defaultSupports autocorrectionTarget Chef Version
EnabledYesAll Versions

Use the new-style notification syntax which allows you to notify resources defined later in a recipe or resource.

Examples

incorrect

template '/etc/www/configures-apache.conf' do
  notifies :restart, resources(service: 'apache')
end

template '/etc/www/configures-apache.conf' do
  notifies :restart, resources(service: 'apache'), :immediately
end

template '/etc/www/configures-apache.conf' do
  notifies :restart, resources(service: service_name_variable), :immediately
end

template '/etc/www/configures-apache.conf' do
  subscribes :restart, resources(service: service_name_variable), :immediately
end

correct

template '/etc/www/configures-apache.conf' do
  notifies :restart, 'service[apache]'
end

template '/etc/www/configures-apache.conf' do
  notifies :restart, 'service[apache]', :immediately
end

template '/etc/www/configures-apache.conf' do
  notifies :restart, "service[#{service_name_variable}]", :immediately
end

template '/etc/www/configures-apache.conf' do
  subscribes :restart, "service[#{service_name_variable}]", :immediately
end

Configurable attributes

NameDefault valueConfigurable values
Version Added5.13.0String
Exclude
  • **/metadata.rb
  • **/attributes/*.rb
  • **/Berksfile
Array

Was this page helpful?