Sha256: 7b8c65890be6b5af0b3b620c36c05fb4c09a69e967811506dc08ab52786e1f60

Contents?: true

Size: 1.45 KB

Versions: 4

Compression:

Stored size: 1.45 KB

Contents

module Fezzik
  class HostTask < Rake::Task
    attr_accessor :roles

    def initialize(task_name, app)
      super
      @roles = []
      @host_actions = []
    end

    def enhance(deps = nil, &block)
      @host_actions << block if block_given?
      super(deps)
    end

    def execute(args = nil)
      return if Rake.application.options.dryrun

      if @roles.empty?
        hosts = Fezzik.get(:domain).map { |domain| "#{Fezzik.get(:user)}@#{domain}" }
        @@connection_pool ||= Weave.connect(hosts)
        @host_actions.each do |action|
          begin
            @@connection_pool.execute(:args => [self, args], &action)
          rescue Weave::Error => e
            STDERR.puts "Error running command in HostTask '#{@name}':"
            abort e.message
          end
        end
      else
        @roles.each do |role|
          Fezzik.with_role(role) do
            hosts = Fezzik.get(:domain).map { |domain| "#{Fezzik.get(:user)}@#{domain}" }
            @@role_connection_pools ||= {}
            @@role_connection_pools[role] ||= Weave.connect(hosts)
            @host_actions.each do |action|
              begin
                @@role_connection_pools[role].execute(:args => [self, args], &action)
              rescue Weave::Error => e
                STDERR.puts "Error running command in HostTask '#{@name}' with role '#{role}':"
                abort e.message
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fezzik-0.8.0 lib/fezzik/host_task.rb
fezzik-0.8.0.beta3 lib/fezzik/host_task.rb
fezzik-0.8.0.beta2 lib/fezzik/host_task.rb
fezzik-0.8.0.beta1 lib/fezzik/host_task.rb