Class: Gaptool::ChefrunCommand

Inherits:
Clamp::Command
  • Object
show all
Defined in:
lib/gaptool-client.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/gaptool-client.rb', line 274

def execute
  attrs = split_attrs(attribute_list)
  if !instance.nil?
    nodes = [$api.getonenode(instance)]
  else
    nodes = $api.getenvroles(role, environment)
  end
  nodes.peach do |node|
    if node['chef_runlist'].nil?
      runlist = ['recipe[main]']
    elsif node['chef_runlist'].is_a? Array
      runlist = node['chef_runlist']
    else
      runlist = eval(node['chef_runlist'])
    end
    json = {
      'this_server' => "#{role}-#{environment}-#{node['instance']}",
      'role' => role,
      'environment' => environment,
      'app_user' => node['appuser'],
      'run_list' => runlist,
      'hostname' => node['hostname'],
      'instance' => node['instance'],
      'zone' => node['zone'],
      'itype' => node['itype'],
      'apps' => eval(node['apps'] || '[]'),
    }.merge(attrs)
    git="git fetch --all; git reset --hard origin/`git rev-parse --abbrev-ref HEAD`"

    unless chef_branch.nil?
      json['chefbranch'] = chef_branch
      git = "git checkout -f #{chef_branch}; git fetch --all; git reset --hard origin/#{chef_branch}"
    end
    commands = [
      "cd ~admin/ops; #{git} ",
      "echo '#{json.to_json}' > ~admin/solo.json",
      "sudo chef-solo -c ~admin/ops/cookbooks/solo.rb -j ~admin/solo.json -E #{environment}"
    ]
    sshcmd(node, commands)
  end
end