Module: Phase::DSL

Defined in:
lib/phase/dsl.rb

Instance Method Summary collapse

Instance Method Details

#on(destination_ips, options = {}, &block) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/phase/dsl.rb', line 14

def on(destination_ips, options = {}, &block)
  server = ::Phase.servers.where(role: ::Phase.config.bastion_role).first
  raise ArgumentError, "no servers found" unless server

  # TODO: identify the CORRECT bastion host per subnet/network
  bastion_host = "#{ ::Phase.config.bastion_user }@#{ server.resource.dns_name }"
  coordinator  = ::SSHKit::Coordinator.new(bastion_host)

  # TODO: clean up this logic. this should be done within a coordinator
  # (or elsewhere) so we can ID networks on a per-adapter basis
  results = Array(destination_ips).map do |ip|
    coordinator.each(options) do
      on_remote_host(ip) { instance_exec(&block) }
    end
  end

  results.flatten
end

#on_role(role_name, environment = "staging", options = {}, &block) ⇒ void

This method returns an undefined value.

Parameters:

  • role_name (String)

    The value of the ‘Role’ tag

  • environment (String) (defaults to: "staging")

    The value of the ‘Environment’ tag

  • options (Hash) (defaults to: {})

    SSHKit concurrency options

See Also:

  • for concurrency options


9
10
11
12
# File 'lib/phase/dsl.rb', line 9

def on_role(role_name, environment = "staging", options = {}, &block)
  servers = ::Phase.servers.where(role: role_name, environment: environment)
  on(servers.map {|s| s.resource.private_ip_address }, options, &block)
end

#run_locally(&block) ⇒ Object



33
34
35
# File 'lib/phase/dsl.rb', line 33

def run_locally(&block)
  ::SSHKit::Backend::Local.new(&block).run
end