在 vagrant 多 VM 配置期间将文件从一个 EC2 实例下载到另一个 EC2 实例

downloading a file from one EC2 instance to another EC2 instance during vagrant multi-VM provisioning

我的应用程序由两个组件组成:服务器和代理。 我正在使用 Vagrant 创建两个 EC2 实例。每个应用程序组件一个。 首先,我创建服务器实例并使用 Chef 对其进行配置。 现在,我正在尝试提供代理实例。为此,我需要将代理部署包从服务器实例下载到代理实例。

最好的方法是使用 scp 和服务器实例私有 ip。 如何与代理提供进程 (Chef) 共享服务器私有 IP 地址?

似乎 vagrant 主机管理器插件 (https://github.com/smdahlen/vagrant-hostmanager) 可以提供帮助。

来自文档

You can customize way, how host manager resolves IP address for each machine. This might be handy in case of aws provider, where host name is stored in ssh_info hash of each machine. This causes generation of invalid /etc/hosts file.

Custom IP resolver gives you oportunity to calculate IP address for each machine by yourself, giving You also access to the machine that is updating /etc/hosts. For example:

config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
  if hostname = (vm.ssh_info && vm.ssh_info[:host])
    `host #{hostname}`.split("\n").last[/(\d+\.\d+\.\d+\.\d+)/, 1]
  end
end