Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default recipe unzip is not idempotent and always runs #25

Closed
axelrtgs opened this issue Jul 26, 2017 · 3 comments
Closed

Default recipe unzip is not idempotent and always runs #25

axelrtgs opened this issue Jul 26, 2017 · 3 comments

Comments

@axelrtgs
Copy link
Contributor

The windows_zipfile resource doesn't look like its idempotent so it always runs with every chef run triggering the notifications associated with the nssm resource on every run even if the file hasn't changed.

I am not too familiar with windows_zipfile so am unsure if theres a way to make it idempotent. if not perhaps consider Poise Zip which iirc is idempotent although im not too keen on adding another dependency to nssm cookbook.

output from chef run

  Recipe: nssm::default
    * windows_zipfile[download nssm] action unzip[2017-07-26T09:54:18-04:00] INFO: Processing windows_zipfile[download n
ssm] action unzip (nssm::default line 9)

      - unzip https://nssm.cc/ci/nssm-2.24-94-g9c88bc1.zip
      * remote_file[c:/chef/cache/nssm-2.24-94-g9c88bc1.zip] action create[2017-07-26T09:54:18-04:00] INFO: Processing r
emote_file[c:/chef/cache/nssm-2.24-94-g9c88bc1.zip] action create (c:/chef/cache/cookbooks/windows/resources/zipfile.rb
line 40)
 (up to date)
      * ruby_block[Unzipping] action run[2017-07-26T09:54:18-04:00] INFO: Processing ruby_block[Unzipping] action run (c
:/chef/cache/cookbooks/windows/resources/zipfile.rb line 54)
[2017-07-26T09:54:18-04:00] INFO: ruby_block[Unzipping] called

        - execute the ruby block Unzipping

[2017-07-26T09:54:18-04:00] INFO: windows_zipfile[download nssm] sending create action to remote_file[install nssm] (imm
ediate)
    * remote_file[install nssm] action create[2017-07-26T09:54:18-04:00] INFO: Processing remote_file[install nssm] acti
on create (nssm::default line 18)
 (up to date)
    * remote_file[install nssm] action create[2017-07-26T09:54:18-04:00] INFO: Processing remote_file[install nssm] acti
on create (nssm::default line 18)
 (up to date)
    - evaluate block and run any associated actions
@axelrtgs
Copy link
Contributor Author

axelrtgs commented Jul 26, 2017

EDIT: checked code and checksum is set so likely the below edit is the only way to ensure idempotence. i will test out something and see to submit a PR

P.S. this was tried on 3.0.2 and the latest pull from master with the same result.

EDIT: missed this part in the readme:

Be sure to use the not_if or only_if meta parameters to guard the resource for idempotence or action will be taken every Chef run.

looks like well have to add a not if the unzipped binary already exists or something like that to ensure idempotence of the zip resource

@axelrtgs
Copy link
Contributor Author

ok so adding this after line 15 in the default recipe fixed the unzip happening on every run but I'm certain this wont work in all cases and will probably break everything and is not the right way to solve it so i wont submit a PR for it yet but here is the working line:

not_if { Digest::SHA256.file("#{Chef::Config[:file_cache_path]}/#{basename}.zip").hexdigest == node['nssm']['sha256'] }

@axelrtgs
Copy link
Contributor Author

ok so i managed to fix chef_spec errors but it looks like my fix above doesnt work when the file doesnt yet exist. will have to revisit that perhaps after some feedback from you guys or some more learning.

@axelrtgs axelrtgs closed this as completed Aug 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant