[chef] idempotent lwrp behaviour


Chronological Thread 
  • From: Peter Wilcsinszky < >
  • To:
  • Subject: [chef] idempotent lwrp behaviour
  • Date: Tue, 9 Sep 2014 14:31:22 +0200

Hi all!

I've run into a problem, when I was trying to implement an lwrp, that does something like the artifact_package resource in https://github.com/RiotGames/artifact-cookbook

The simplified base of the lwrp looks like:

use_inline_resources

action :install
    custom_artifact_download_lwrp ...
    package ...
end

I wanted to test its idempotency, to make sure no notification will be propagated when the package is already installed. If any of the inner resources inside the custom_artifact_download_lwrp resource was modified (the file has been removed from the cache - we want to do periodic cleanup there) the notification was sent out even if the package was already installed. I wanted to force "mute" it somehow, because I want to avoid restarting services needlessly. I've naively tried:

c = custom_artifact_download_lwrp
c.updated_by_last_action(false)

But after digging into the code I've realised I can not do this, since this code runs before the resource collection is converged. So if a resource gets modified the updated flag will be true and I cannot do anything about it. Is there a way to do this?

Anyways, after reading the lwrp docs more closely, I've realized that I should do a conditional before declaring any of my resources, so ended up in doing this:

def skip_install?(name, version)
status = `dpkg -s #{name}`
status.lines.any? { |l| /^Status: install ok installed/.match l } &&
status.lines.any? { |l| /^Version: #{version}$/.match l }
end

action :install
    unless skip_install?()
        custom_artifact_download_lwrp ...
        package ...
    end
end

I'm wondering if there is a more appropriate way of checking package availability, and wheter I've ended up doing this right or missing something?

Thanks,
pepov



Archive powered by MHonArc 2.6.16.

§