封隔器:ssh通讯器忽略“ ssh_port”

时间:2019-06-10 13:46:47

标签: ssh opensuse packer

我正在构建类型为“ virtualbox-iso”和OpenSUSE 42.3作为来宾OS的VirtualBox VM。我指定了ssh通信器在构建过程中应使用的主机和端口,但是看起来打包程序忽略了该端口规范。

我正在“构建器”部分覆盖主机和端口的默认设置。这是我的json文件的摘录:

  "builders": [
    {
      "type": "virtualbox-iso",

      "communicator": "ssh",
      "ssh_host": "192.168.1.5",
      "ssh_port": "22",
      "ssh_username": "some_user",
      "ssh_password": "some_password",
      "ssh_timeout": "20m",
      "ssh_handshake_attempts": "1000",

包装器无法连接到VM,因为包装器忽略了我通过“ ssh_port”提供的端口。 这是调试输出(已使用PACKER_LOG = 1启用):

2019/06/10 15:10:10 packer: 2019/06/10 15:10:10 [INFO] Waiting 1s
2019/06/10 15:10:11 ui: ==> opensuse-master-box: Using ssh communicator to connect: 192.168.1.5
2019/06/10 15:10:11 packer: 2019/06/10 15:10:11 [INFO] Waiting for SSH, up to timeout: 20m0s
2019/06/10 15:10:11 ui: ==> opensuse-master-box: Waiting for SSH to become available...
2019/06/10 15:10:26 packer: 2019/06/10 15:10:26 [DEBUG] TCP connection to SSH ip/port failed: dial tcp 192.168.1.5:4240: i/o timeout
2019/06/10 15:10:31 packer: 2019/06/10 15:10:31 [DEBUG] TCP connection to SSH ip/port failed: dial tcp 192.168.1.5:4240: connect: connection refused
2019/06/10 15:10:36 packer: 2019/06/10 15:10:36 [DEBUG] TCP connection to SSH ip/port failed: dial tcp 192.168.1.5:4240: connect: connection refused
2019/06/10 15:10:41 packer: 2019/06/10 15:10:41 [DEBUG] TCP connection to SSH ip/port failed: dial tcp 192.168.1.5:4240: connect: connection refused

这是预期的行为还是我做错了什么?

2 个答案:

答案 0 :(得分:0)

这是因为VirtualBox NAT网络如何工作。无法从主机直接访问来宾VM。 Packer通过设置端口转发规则来解决此问题。 ssh_host_port_minssh_host_port_max之间的随机端口被转发到来宾VM ssh_port

如果要将集合ssh_skip_nat_mapping的此项设置为true,但是必须确保您有一个Packer可以访问访客的网络设置。

答案 1 :(得分:0)

这是因为您正在执行“ 22”而不是22。配置正在寻找一个int,而不是一个字符串。