Information Technology Reference
In-Depth Information
There are some issues with the
package
and
execute
resources, however, as on the second
kitchen converge
run Chef:
1. Reinstalled the rpm package, unnecessarily
2. Executed
chef-server-ctl reconfigure
a second time
Let's fix these idempotency issues in our code now.
Example 9-4
has the final idempotent
version of the code.
The first issue is a common one that Chef developers encounter with the
package
resource
when they try to install from a downloaded
rpm
instead of using a package repository. In-
stead of using a
package
one-liner for a downloaded
rpm
, you need to tell the
package
re-
source to explicitly use the
Chef::Provider::Package::Rpm
provider using the
provider
attribute. You also need to specify the string representing the package name using the
source
attribute, like so:
package package_name
ddo
source package_local_path
provider
Chef
:
:Provider
::
Package
:
:Rpm
end
end
NOTE
You can use the
rpm_package
short name to specify
Chef::Provider::Package::Rpm
to the
package
resource, if you prefer. The following code is equivalent to the preceding
code:
rpm_package package_name do
source package_local_path
end
Fixing the second issue with the
execute
resource is a little more involved. That's why you
should prefer built-in Chef resources over using the
execute
resource, because it's up to you
to make the execute resources idempotent.