Class: Gaptool::ChefrunCommand

Inherits:
Clamp::Command
  • Object
show all
Defined in:
lib/gaptool_client/commands.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gaptool_client/commands.rb', line 259

def execute
  attrs = Gaptool::Helpers.split_attrs(attribute_list)
  nodes = Gaptool::API.query_nodes(hidden: hidden? ? true : nil,
                                   role: role,
                                   instance: instance,
                                   environment: environment)
  nodes = nodes.map { |x| x.merge('attrs' => attrs) }
  pre_hook = proc do |node|
    upload!(StringIO.new(node['attrs'].merge(
      'run_list' => node['chef_runlist'] || ['role[base]']
    ).to_json), '/tmp/chef.json')
  end

  command = 'sudo gtrunchef -j /tmp/chef.json'
  command = "#{command} -W" if whyrun?
  command = "#{command} -B #{chef_branch}" if chef_branch
  command = "#{command} -v" if verbose?
  res = Gaptool::SSH.exec(
    nodes, [command],
    pre_hooks: [pre_hook], serial: serial?, continue_on_errors: continue_on_errors?,
    batch_size: batch_size
  )
  exit res
end