1

我已经设置了一个 Windows 服务器并使用 Chocolatey 安装了 ssh。如果我手动运行它,我连接和运行我的命令没有问题。当我尝试使用 Terraform 运行我的命令时,它成功连接但不运行任何命令。

我从使用 winrm 开始,然后我可以运行命令,但由于在 winrm 上创建服务结构集群时出现一些问题,我决定尝试使用 ssh 来代替,当手动运行时,它可以工作并且集群启动了。所以这似乎是前进的方向。

我已经设置了一个 Linux VM 并使用私钥让 ssh 工作。因此,我尝试使用与 Windows 上的 Linux VM 相同的配置,但它仍然要求我使用我的密码。

能够通过 ssh 手动运行命令并仅使用 Terraform 连接但不运行命令的原因可能是什么?我正在使用 Windows 2016 在 OpenStack 上运行它

null_resource.sf_cluster_install (remote-exec): Connecting to remote host via SSH...
null_resource.sf_cluster_install (remote-exec):   Host: 1.1.1.1
null_resource.sf_cluster_install (remote-exec):   User: Administrator
null_resource.sf_cluster_install (remote-exec):   Password: true
null_resource.sf_cluster_install (remote-exec):   Private key: false
null_resource.sf_cluster_install (remote-exec):   SSH Agent: false
null_resource.sf_cluster_install (remote-exec):   Checking Host Key: false
null_resource.sf_cluster_install (remote-exec): Connected!
null_resource.sf_cluster_install: Creation complete after 4s (ID: 5017581117349235118)

这是我用来运行命令的脚本:

resource "null_resource" "sf_cluster_install" {
  # count = "${local.sf_count}"
  depends_on = ["null_resource.copy_sf_package"]

  # Changes to any instance of the cluster requires re-provisioning
  triggers = {
    cluster_instance_ids = "${openstack_compute_instance_v2.sf_servers.0.id}"
  }

  connection = {
    type = "ssh"
    host = "${openstack_networking_floatingip_v2.sf_floatIP.0.address}"
    user = "Administrator"

   # private_key = "${file("~/.ssh/id_rsa")}"

   password = "${var.admin_pass}"
 }

  provisioner "remote-exec" {
    inline = [
      "echo hello",
      "powershell.exe Write-Host hello",
      "powershell.exe New-Item C:/tmp/hello.txt -type file"
    ]
  }
}
4

1 回答 1

0

connection块放入块内provisioner

provisioner "remote-exec" {
  connection = {
    type = "ssh"
    ...
  }

  inline = [
    "echo hello",
    "powershell.exe Write-Host hello",
    "powershell.exe New-Item C:/tmp/hello.txt -type file"
  ]
}
于 2019-06-11T23:22:06.747 回答