class Exos::Commands::Keys::Bastions

Attributes

role[RW]

Public Class Methods

all() click to toggle source
# File lib/exos/commands/keys.rb, line 249
def all
  @all ||= begin
    bastions = ec2.servers.all("tag:Role" => role).map do |bastion|
      bastion.username = "deploy"
      bastion
    end

    abort "No bastions found with role '#{ options.role }'." unless bastions.any?
    bastions
  end
end
ec2() click to toggle source
# File lib/exos/commands/keys.rb, line 279
def ec2
  @ec2 ||= ::Fog::Compute::AWS.new
end
exec(*cmds) click to toggle source
# File lib/exos/commands/keys.rb, line 261
def exec(*cmds)
  results = []

  all.each do |bastion|
    if bastion.ssh("ls #{ LOCKFILE_NAME }").first.status == 0
      abort "Another `exos keys` operation is in progress."
    end

    commands = ["touch #{ LOCKFILE_NAME }", *cmds, "rm #{ LOCKFILE_NAME }"]
    results << bastion.ssh(commands)
  end

  results.last[-2]
# Ensure to handle Fog::SSH raising on SSH connection errors.
ensure
  all.each { |b| b.ssh("rm #{ LOCKFILE_NAME }") }
end