Class: NodeSpec::Provisioning::Chef

Inherits:
Object
  • Object
show all
Defined in:
lib/nodespec/provisioning/chef.rb

Constant Summary collapse

CLIENT_CONFIG_FILENAME =
'chef_client.rb'
ATTRIBUTES_FILENAME =
'chef_client_attributes.json'
NODES_DIRNAME =
'chef_nodes'

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Chef

Returns a new instance of Chef.



11
12
13
14
15
# File 'lib/nodespec/provisioning/chef.rb', line 11

def initialize(node)
  @node = node
  @custom_attributes = {}
  @configuration_entries = []
end

Instance Method Details

#chef_apply_execute(snippet, options = []) ⇒ Object



17
18
19
# File 'lib/nodespec/provisioning/chef.rb', line 17

def chef_apply_execute(snippet, options = [])
  @node.execute("chef-apply #{options.join(' ')} -e #{snippet.shellescape}")
end

#chef_apply_recipe(recipe_file, options = []) ⇒ Object



21
22
23
# File 'lib/nodespec/provisioning/chef.rb', line 21

def chef_apply_recipe(recipe_file, options = [])
  @node.execute("chef-apply #{recipe_file.shellescape} #{options.join(' ')}")
end

#chef_client_config(text) ⇒ Object



36
37
38
# File 'lib/nodespec/provisioning/chef.rb', line 36

def chef_client_config(text)
  @configuration_entries << text
end

#chef_client_runlist(*args) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/nodespec/provisioning/chef.rb', line 40

def chef_client_runlist(*args)
  run_list_items, options = [], []
  run_list_items << args.take_while {|arg| arg.is_a? String}
  options += args.last if args.last.is_a? Array
  options << configuration_option
  options << attributes_option
  @node.execute("chef-client -z #{options.compact.join(' ')} -o #{run_list_items.join(',').shellescape}")
end

#set_attributes(attributes) ⇒ Object



32
33
34
# File 'lib/nodespec/provisioning/chef.rb', line 32

def set_attributes(attributes)
  @custom_attributes = attributes
end

#set_cookbook_paths(*paths) ⇒ Object



25
26
27
28
29
30
# File 'lib/nodespec/provisioning/chef.rb', line 25

def set_cookbook_paths(*paths)
  unless paths.empty?
    paths_in_quotes = paths.map {|p| "'#{p}'"}
    @configuration_entries << %Q(cookbook_path [#{paths_in_quotes.join(",")}])
  end
end