Sha256: 285229784d76355d72e18609633235dc4a400f13772b8e8928006f6ee6009cb3

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module EY
  module Metadata
    module SshAliasHelper
      # Aliases like 'my_env-app_master' or 'my_env-utilities-5' that go in .ssh/config
      #
      # For example:
      #   Host my_env-app_master
      #     Hostname ec2-111-111-111-111.compute-1.amazonaws.com
      #     User deploy
      #     StrictHostKeyChecking no
      def ssh_aliases
        counter = Hash.new 0
        %w{ app_master db_master db_slaves app_slaves utilities }.map do |role_group|
          send(role_group).map do |public_hostname|
            ssh_alias counter, role_group, public_hostname
          end
        end.flatten.join("\n")
      end
      
      # Used internally to generate a single ssh alias.
      def ssh_alias(counter, role_group, public_hostname)
        id = case role_group
        when 'db_slaves', 'app_slaves', 'utilities'
          "#{role_group}-#{counter[role_group] += 1}"
        else
          role_group
        end
        %{Host #{environment_name}-#{id}
  Hostname #{public_hostname}
  User #{ssh_username}
  StrictHostKeyChecking no
}        
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
engineyard-metadata-0.1.2 lib/engineyard-metadata/ssh_alias_helper.rb