【问题标题】:Terraform local-exec can't run commands in backgroundTerraform local-exec 无法在后台运行命令
【发布时间】:2020-10-04 20:13:42
【问题描述】:

这篇文章有一个远程执行的解决方案:How can I start a remote service using Terraform provisioning?

我正在尝试对 local-exec 供应商做同样的事情。

我需要在远程节点上打开 ssh 隧道:

  #create remote SSH reverse tunnel
  provisioner "local-exec" {
    command = <<EOT
      ssh-keygen -f "$HOME/.ssh/known_hosts" -R "${self.ip}";
      nohup ssh -oStrictHostKeyChecking=no -N -R ${var.chef_zero_port}:localhost:${var.chef_zero_port} ${var.ssh_username}@${self.ip} -M -S /tmp/.ssh_to_${self.ip} &
      sleep 2
    EOT
    interpreter = ["/bin/bash","-c"]
  }

隧道已创建,但 Terraform 不会继续下一步。

如果我将 ssh 命令替换为:

ssh -oStrictHostKeyChecking=no -fN -R ${var.chef_zero_port}:localhost:${var.chef_zero_port} ${var.ssh_username}@${self.ip} -M -S /tmp/.ssh_to_${self.ip};

有什么想法吗?

【问题讨论】:

    标签: terraform


    【解决方案1】:

    Terraform 正在等待所有子进程退出。 nohup 正在与终端分离,但它仍然是一个子进程。尝试使用 disown 将孩子移动到 init(过程 1)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-20
      • 2020-03-22
      • 1970-01-01
      相关资源
      最近更新 更多