Class: PackerFiles::Provision::ChefSolo

Inherits:
Base show all
Defined in:
lib/PackerFiles/Provision/ChefSolo.rb

Instance Attribute Summary

Attributes inherited from Base

#os

Instance Method Summary collapse

Methods inherited from Utils::HashSerializer

hash_attributes, hash_variable, #merge_hs

Constructor Details

#initialize {|_self| ... } ⇒ ChefSolo

Constructor yields self

Yields:

  • (_self)

Yield Parameters:



55
56
57
58
# File 'lib/PackerFiles/Provision/ChefSolo.rb', line 55

def initialize(&block)
	    yield self if block_given?
	    @type = 'chef-solo'
end

Instance Method Details

#convert_cookbook_pathsObject

Cookbook Path converter



40
41
42
# File 'lib/PackerFiles/Provision/ChefSolo.rb', line 40

def convert_cookbook_paths
   self.cookbook_paths.map {|p| File.absolute_path(p)}
end

#convert_skip_to_booleanObject

Boolean converter for skip_install



50
51
52
# File 'lib/PackerFiles/Provision/ChefSolo.rb', line 50

def convert_skip_to_boolean
   (self.skip_install.to_i > 0) ? true : false
end

#convert_sudo_to_booleanObject

Boolean converter for prevent_sudo



45
46
47
# File 'lib/PackerFiles/Provision/ChefSolo.rb', line 45

def convert_sudo_to_boolean
   (self.prevent_sudo.to_i > 0) ? true : false
end

#convert_to_jsonObject

JSON converter



30
31
32
33
34
35
36
37
# File 'lib/PackerFiles/Provision/ChefSolo.rb', line 30

def convert_to_json
   # Check if it is a string and if so parse it into JSON
   begin
      return JSON.parse(self.json)
   rescue JSON::ParserError => e
      return JSON.parse(File.read(self.json))
   end
end

#to_hash(*args) ⇒ Object

.tar.gz bundle.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/PackerFiles/Provision/ChefSolo.rb', line 64

def to_hash(*args)
	   
	    # The Provisioner usually passes the OS class as it's first
	    # argument
	    os   = args[0]

	    # Some cookbook paths are special in the sense, they are .tar.gz
	    # bundles. The code fragment handles that special case.
	    convert_cookbook_paths.each_with_index do |path, index|
      next if !path.end_with?('.tar.gz')
	       temp   = Dir.mktmpdir('dep', os.OutDir) 
	       helper = ChefSoloHelper.new(path)
	       local  = helper.download_files(os.OutDir)
	       helper.extract_files(temp, local)
	       @cookbook_paths.push(temp)
	    end

	    # Remove all the cookbooks that end with .tar.gz
	    @cookbook_paths.delete_if {|cb| cb.end_with?('.tar.gz')}

	    # call back the original to_hash function.
	    super
end