Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a file content at execution time? Chef reads at compile time

Because I'm running into this MIXLIB-11 error that I've reported to Mixlib team, I need to find a walkaround, an alternative to Mixlib::Shellout.

Briefly about the problem:

Here is a statement which says "*No surprise -- the read is happening at compile time, but the remote_file resource is actually created at execution time.**"

Because of this feature, Mixlib::Shellout.new("ls", :cwd => '/opt/cubrid/share/webmanager') raises "No such file or directory" error even though that directory is created at execution time by a previous recipe included in this current recipe.

Is there a way to read a file/directory at execution time?

like image 817
Eye Avatar asked Mar 29 '13 01:03

Eye


1 Answers

Found an answer: wrap the code in ruby_block, and it will be executed at run time.

ruby_block "Check if CURBID Web Manager needs installation" do
  block do
    version = ""

    if File.exists?("#{CWM_HOME_DIR}/appLoader.js")
      # Read the CWM version from file.
      f = File.open("#{CWM_HOME_DIR}/appLoader.js")

      pattern = /Ext\.cwm\.prodVersion = '(\d+\.\d+\.\d+\.\d+)'/

      f.each {|line|
        if match = pattern.match(line)
          version = match[1]
          break
        end
      }

      f.close
    end
  end
end

Now the version is correctly populated from the file created in the previous recipe.

like image 108
Eye Avatar answered Oct 22 '22 19:10

Eye