Information Technology Reference
In-Depth Information
Now add the notifies attribute as follows. The notifies attribute takes three parameters:
an action, the name of the resource to notify, and a timer indicating when the action should
be performed. As shown in the following example, we want to perform the :run action on
the execute[reconfigure-chef-server] resource, and we want the action performed
:immediately . For more information on notifies parameters, refer to the Chef documenta-
tion :
package package_name ddo
source package_local_path
provider Chef : :Provider :: Package : :Rpm
notifies :run , 'execute[reconfigure-chef-server]' , :immediately
end
end
Example A-4 shows what the final version of our idempotent code looks like.
Example A-4. chef-server/chefdk/chef-repo/cookbooks/chef-server/recipes/default.rb
# Cookbook Name:: chef-server
# Recipe:: default
#
# Copyright (C) 2014
#
#
#
package_url = node [ 'chef-server' ][ 'url' ]
package_name = :: File . basename ( package_url )
package_local_path = " #{ Chef : :Config [ :file_cache_path ] } / #{ package_name } "
# omnibus_package is remote (i.e., a URL) let's download it
remote_file package_local_path ddo
source package_url
end
end
package package_name ddo
source package_local_path
provider Chef : :Provider :: Package : :Rpm
notifies :run , 'execute[reconfigure-chef-server]'
end
end
# reconfigure the installation
execute 'reconfigure-chef-server' ddo
command 'chef-server-ctl reconfigure'
Search WWH ::




Custom Search