Packer 瞄准了错误的主机 IP

Packer is targeting the wrong host's IP

我使用 packer 在 AWS 上创建图像。 当 Packer 运行此 Ansible 部分时:

   - name: Wait for reboot to finish
     local_action: wait_for host={{ ansible_host }} port=22 state=started

我得到"Timeout when waiting for 127.0.0.1:22"

为什么 "ansible_host" 设置为“127.0.0.1”而不是配置主机的 IP?

如何告诉Packer使用正确的"ansible_host"?

Packer version: 1.2.4
Ansible version: 2.5.4

documentation的入口处有模糊的描述:

It dynamically creates an Ansible inventory file configured to use SSH, runs an SSH server, executes ansible-playbook, and marshals Ansible plays through the SSH server to the machine being provisioned by Packer.

这意味着 ansible 目标 (ansible_host) 是本地主机但具有不同的端口,然后将其转发到正确的主机。

基本上,当 运行 Packer 时,您不能在您的剧本中重新启动(或重新启动 sshd),因为 ssh 会话将断开连接。有关详细信息,请参阅 Handeling Reboots - Shell Provisioner