Class: Hazetug::Task

Inherits:
Object
  • Object
show all
Includes:
UI::Mixin
Defined in:
lib/hazetug/task.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UI::Mixin

included

Constructor Details

#initialize(path) ⇒ Task

Returns a new instance of Task.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hazetug/task.rb', line 10

def initialize(path)
  path = File.expand_path(path)
  @task = Mash.new(Psych.load_file(path))
rescue Psych::Exception
  ui.fatal "Unable to parse hazetug task file: '#{path}'"
  puts $!.inspect, $@
  exit(1)
rescue SystemCallError
  ui.fatal "Unable to read file: '#{path}'"
  exit(1)
end

Class Method Details

.[](key) ⇒ Object



44
45
46
# File 'lib/hazetug/task.rb', line 44

def [](key)
  @instance and @instance[key]
end

.load_from_file(path) ⇒ Object



40
41
42
# File 'lib/hazetug/task.rb', line 40

def load_from_file(path)
  @instance ||= self.new(path)
end

Instance Method Details

#[](key) ⇒ Object



22
23
24
# File 'lib/hazetug/task.rb', line 22

def [](key)
  @task[key]
end

#hosts_to_bootstrap(cmd_vars = {}, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/hazetug/task.rb', line 26

def hosts_to_bootstrap(cmd_vars={}, &block)
  return if block.nil?
  base_conf = Mash.new(task)
  hosts = base_conf.delete(:bootstrap)
  base_conf = Chef::Mixin::DeepMerge.merge(base_conf, cmd_vars)
  hosts.each do |conf|
    merged = Chef::Mixin::DeepMerge.merge(base_conf, conf)
    block.call(merged)
  end
end