Class: Gaptool::ChefrunCommand

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

Instance Method Summary collapse

Instance Method Details

#execute ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/gaptool-client.rb', line 215

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|
    json = {
      'this_server' => "#{role}-#{environment}-#{node['instance']}",
      'role' => role,
      'environment' => environment,
      'app_user' => node['appuser'],
      'run_list' => [ "recipe[main]" ],
      'hostname' => node['hostname'],
      'instance' => node['instance'],
      'zone' => node['zone'],
      'itype' => node['itype'],
      'apps' => eval(node['apps']),
      'chefbranch' => chef_branch
    }.merge(attrs).to_json
    commands = [
      "cd ~admin/ops; git checkout -f #{chef_branch}; git fetch --all; git reset --hard origin/#{chef_branch}",
      "echo '#{json}' > ~admin/solo.json",
      "sudo chef-solo -c ~admin/ops/cookbooks/solo.rb -j ~admin/solo.json"
    ]
    sshcmd(node, commands)
  end
end