通过Windows 2008 R2服务器上的远程执行预配程序执行Windows系统FIND.exe命令时,其行为不正确

时间:2019-07-11 01:53:23

标签: windows terraform windows-server-2008

通过远程执行预配程序运行时,在Windows 2008 R2上观察到Windows FIND.EXE命令的奇怪问题。 FIND.EXE命令不会返回预期的输出,但是在Windows 2008 R2服务器中手动运行时,一切正常。

尝试了FIND.exe语法的多种变体,还尝试作为批处理脚本运行。.但是它们都没有在stdout中提供任何输出,并且总是导致ERRORLEVEL为1。

我用FINDSTR.EXE替换了FIND.EXE(回声你好| FINDSTR / I / C:“ hello”),并注意到FINDSTR.EXE可以正常工作。

环境: + Terraform v0.12.3 + provider.vsphere v1.12.0 + Windows 2008 R2 SP1

provider "vsphere" {
    allow_unverified_ssl = true
    ...
}

resource "vsphere_virtual_machine" "vm_1" {
  name             = "..."

  ...

  connection {
    type = "winrm"
    user = "Administrator"
    password = "..."
    host = "..."
    ...
  }

  provisioner "remote-exec" {
    inline = [ 
        "echo hello | FIND /I /C \"hello\"",
        "echo %ERRORLEVEL%"
    ]
  } 
}

内联脚本中的第一个命令应返回“ 1”(作为找到的模式的计数),并且ERRORLEVEL应将“ 0”指示为成功执行。

实际结果:

vsphere_virtual_machine.vm_1 (remote-exec): C:\Users\Administrator>echo "hello"   | FIND /I /C "hello"

vsphere_virtual_machine.vm_1 (remote-exec): C:\Users\Administrator>echo 1
vsphere_virtual_machine.vm_1 (remote-exec): 1
vsphere_virtual_machine.vm_1 (remote-exec): C:\Users\Administrator>echo "hello"   | FINDSTR /I /C:"hello"
vsphere_virtual_machine.vm_1 (remote-exec): "hello"

vsphere_virtual_machine.vm_1 (remote-exec): C:\Users\Administrator>echo 0
vsphere_virtual_machine.vm_1 (remote-exec): 0

0 个答案:

没有答案