Capistrano :NoMethodError: 未定义的方法 'merge' for "ec2 private ip" :String



我正在尝试通过堡垒主机部署多个 EC2 实例。我将 EC2 实例放在 ELB 下,并始终通过堡垒进行访问。

require 'aws-sdk'
require 'net/ssh/proxy/command'
ec2 = Aws::EC2::Client.new(region: fetch(:aws_region))
ec2_filtered = ec2.describe_instances(
    filters:[
        {name: "tag:env", values: [fetch(:rails_env)]},
        {name: "tag:role", values: [fetch(:aws_tag_role)]},
        {name: 'instance-state-name', values: ['running']}
    ])
instances = ec2_filtered.reservations.map(&:instances)[0].map(&:private_ip_address)
instances = ec2_filtered.reservations.map(&:instances)[1].map(&:private_ip_address)
set :branch, 'master'
role :app, *instances
role :web, *instances
role :db, [instances.first]
server *instances,
  user: fetch(:deploy_user),
  ssh_options: {
    forward_agent: true,
    keys: fetch(:deploy_ssh_keys),
    proxy: Net::SSH::Proxy::Command::new('ssh bastion.mamorio -W %h:%p')
  }

上面的代码有效,但它确实是多余的,我想一次获得整个"私有 IP"。

我尝试了以下代码:

instances = ec2_filtered.reservations.map(&:instances).flatten.map(&:private_ip_address)

但我收到以下错误。

NoMethodError: undefined method `merge' for "10.0.xx.2xx":String

有什么建议吗?

我认为问题在于您传递给Capistrano role声明的值。

role :app, *instances

role 方法需要一个数组作为第二个参数,但在您的示例中,您将instances数组"拼接"为单独的参数。

试试这个:

role :app, instances

最新更新