[chef] Re: RE: Re: Methods call inside of "ruby_block" during chef-client's compilation phase.


Chronological Thread 
  • From: Taras Klym < >
  • To:
  • Subject: [chef] Re: RE: Re: Methods call inside of "ruby_block" during chef-client's compilation phase.
  • Date: Thu, 18 Jun 2015 11:01:03 +0300

Hi guys,

The issue is that I have two methods.
1 is for backup and another for delete.

Delete is dependent on backup. If there is not backups created yet it should not delete the folders. 

Recipe flow is as follow:

1) Check if no backups. If there is no - create. 
2) If there are backups already created - delete folders. If no - nothing. 

But issue is that during compile phase, check for backup says that there is no backups yet. And this is true. And marks "delete" block for not to run.
But during run(converge) phase, backups are created and delete folders will not happen. As it was marked not to run. Cuz at compile phase there were backups...

That is why I need somehow force "windows_zip" resource from windows cookbook to run before any other stuff will take place. 
So that delete folders deleted one they find that backups are there already...

Regards,
Taras.


17 червня 2015, 23:41:54, від "Fouts, Chris" < " target="_blank"> >:

I believe Tensibai is saying you can simple do

 

backup *app

 

in your recipe and that will run at compile time since it’s straight ruby code.

 

Chris

 

From: Tensibai Zhaoying [mailto:
Sent: Wednesday, June 17, 2015 4:29 PM
To: " target="_blank">
Subject: [chef] Re: Methods call inside of "ruby_block" during chef-client's compilation phase.

 

You can get rid of the ruby_block as running a ruby_block at compile time is near the same as running ruby code in the recipe itself.

I'm sure people with more knowledge will explain better than me the slight differences in term.of context between the ruby_block resource context and the recipe context in term.of DSL,helpers and so on

Le 17 juin 2015 21:38, " target="_blank"> a écrit :

Hi guys,

I have met an issue and can't overcome it so far.
Will be grateful to you for any advises...

Here what I have in my recipe:

ruby_block "Backing up old application folders" do

  block do

    backup *apps

 end

  action :nothing

end.run_action(:run)

 

This is needed to run that block not during convergence phase but during compilation phase. So that it's done before other resources start its run...

 

 

“backup” method is called from library.rb file in …/libraries/ folder within my cookbook:

def backup *apps

     apps.each do |app|

          windows_zipfile archive_path(app) do

                source "#{zilliant_folder}\\#{app}"

                action :zip

                only_if { !::File.exists?(archive_path(app)) }

          end

     end

end

 

So what I expect is to do folders backup during compilation phase... But...

 

During run (compilation phase) it finds “backup” method but it fails with finding “windows_zipfile” method.

 

Even though  I have put dependency on "windows" cookbook in my "metadata.rb" file of my cookbook.

 

If I call that method “backup” out of “ruby_block” it works fine.

But I need to call it during compile phase (so that it done its job before any other resources).

 

Why ruby_block doesn’t work for finding “windows_zipfile” method?

 

How can I implement what I am looking for?

 

I tried to use "windows_zipfile" by itself outside of ruby_block. But it doesn't have possibility to be run during compile phase. Or I have not figured it out at least. :(

 

Here is chef-client run-example:

At the very beginning chef-client loads all needed cookbooks dependencies and then fails with that resource from windows cookbook:

PS C:\Users\tklym> chef-client

Starting Chef Client, version 12.3.0

resolving cookbooks for run list: ["zFilesUpdate::Spring15-5_UP_mx"]

Synchronizing Cookbooks:

  - artifact

  - windows

  - chef_handler

  - zFilesUpdate

Compiling Cookbooks...

Recipe: zFilesUpdate::Spring15-5_UP_mx

  * directory[c:\chef\cache\artifact_file] action delete

    - delete existing directory c:\chef\cache\artifact_file

  * ruby_block[Backing up old application folders] action run

 

    ================================================================================

    Error executing action `run` on resource 'ruby_block[Backing up old application folders]'

    ================================================================================

 

    NoMethodError

    -------------

    undefined method `windows_zipfile' for Chef::Resource::RubyBlock

 

Thank you in advance for any of your help or advises.

 

Regards,

Taras.





Archive powered by MHonArc 2.6.16.

§