Module: SousChef::NodeTaskHelpers

Includes:
Rake::DSL
Included in:
TaskBuilder
Defined in:
lib/helpers/node_task_helpers.rb

Class Method Summary collapse

Class Method Details

.batch_tasks(name, tasks) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/helpers/node_task_helpers.rb', line 45

def batch_tasks(name, tasks)
  task_names = tasks.map(&:name)

  desc "Run knife solo prepare for all #{name} nodes"
  multitask :prepare => filter_tasks(task_names, 'prepare')

  desc "Run knife solo cook for all #{name} nodes"
  multitask :cook => filter_tasks(task_names, 'cook')

  desc "Run knife solo bootstrap for all #{name} nodes"
  multitask :bootstrap => filter_tasks(task_names, 'bootstrap')

  desc "Run knife solo clean for all #{name} nodes"
  multitask :clean => filter_tasks(task_names, 'clean')
end

.bootstrap_task(node) ⇒ Object



31
32
33
34
35
36
# File 'lib/helpers/node_task_helpers.rb', line 31

def bootstrap_task(node)
  desc "Run knife solo bootstrap for #{node.name}"
  task :bootstrap do
    run_knife 'bootstrap', node
  end
end

.build_node_task(node) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/helpers/node_task_helpers.rb', line 8

def build_node_task(node)
  namespace node.name do
    prepare_task(node)
    cook_task(node)
    bootstrap_task(node)
    clean_task(node)
  end
end

.clean_task(node) ⇒ Object



17
18
19
20
21
22
# File 'lib/helpers/node_task_helpers.rb', line 17

def clean_task(node)
  desc "Run knife solo clean for #{node.name}"
  task :clean do
    run_knife 'clean', node
  end
end

.cook_task(node) ⇒ Object



24
25
26
27
28
29
# File 'lib/helpers/node_task_helpers.rb', line 24

def cook_task(node)
  desc "Run knife solo cook for #{node.name}"
  task :cook do
    run_knife 'cook', node
  end
end

.filter_tasks(tasks_names, desired_task) ⇒ Object



61
62
63
# File 'lib/helpers/node_task_helpers.rb', line 61

def filter_tasks(tasks_names, desired_task)
  tasks_names.clone.keep_if { |task_name| task_name.include? desired_task }
end

.prepare_task(node) ⇒ Object



38
39
40
41
42
43
# File 'lib/helpers/node_task_helpers.rb', line 38

def prepare_task(node)
  desc "Run knife solo prepare for #{node.name}"
  task :prepare do
    run_knife 'prepare', node
  end
end

.run(command) ⇒ Object



65
66
67
68
69
# File 'lib/helpers/node_task_helpers.rb', line 65

def run(command)
  puts "Running: #{command}"
  system command
  raise "Failure! #{$?}" if $? != 0
end

.run_knife(command, node) ⇒ Object



71
72
73
74
75
# File 'lib/helpers/node_task_helpers.rb', line 71

def run_knife(command, node)
  options = "-F #{node.ssh_config_path} #{node.hostname}"
  options = "#{options} -N #{node.name} #{node.config}" unless %w[clean].include? command
  run "knife solo #{command} #{options}"
end