带有SSH的Windows上的Terraform远程执行



我已经设置了Windows Server并使用巧克力安装了SSH。如果我手动运行此此操作,我在连接和运行命令时没有问题。当我尝试使用Terraform运行我的命令时,它会成功连接但不运行任何命令。

我从使用WinRM开始,然后可以运行命令,但是由于在WinRM上创建服务面料群集的问题,我决定尝试使用SSH,而在手动运行的过程中,它可以正常运行,并且群集上升了。这似乎是前进的道路。

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

能够手动通过SSH运行命令并仅使用Terraform Connect但没有运行命令的原因是什么?我正在使用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)

这是IM用于运行命令的脚本:

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"
    ]
  }
}

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"
  ]
}

相关内容

  • 没有找到相关文章

最新更新