我有一个用例,我正在使用 terraform 配置 GOMaster 和 GOServer,然后使用新配置的 gomaster 注册 goserver。
以下是我正在使用的 terraform 配方。Terraform 也安装在 docker 服务器本身上,我正在从那里执行这个配方。
#Configure the Docker provider
provider "docker" {
host = "tcp://${var.dockerIP}:2376/"
}
# Create the network
resource "docker_network" "private_network" {
name = "${var.customer_name}_network"
}
resource "docker_container" "goagent" {
image = "${docker_image.goagent.latest}"
name = "${var.customer_name}_goagent"
hostname = "${var.customer_name}_goagent"
command = [ "/bin/sh", "-c", "/usr/bin/supervisord" ]
network_mode = "bridge"
networks = [ "${docker_network.private_network.name}" ]
provisioner "remote-exec" {
connection {
user = "root"
password = "example"
}
inline = [
"sed -i -e 's/GO_SERVER=go-server/GO_SERVER=${var.customer_name}_goserver' /etc/defaut/go-agent",
"sed -i -e 's/DAEMON=N/DAEMON=Y' /etc/defaut/go-agent",
"/etc/init.d/go-agent restart"
]
}
}
# Create a container
resource "docker_container" "goservertest" {
image = "${docker_image.goserver.latest}"
name = "${var.customer_name}_goserver"
hostname = "${var.customer_name}_goserver"
network_mode = "bridge"
networks = [ "${docker_network.private_network.name}" ]
ports{
internal = "8153"
external = "8003"
}
ports{
internal = "8154"
external = "8002"
}
}
resource "docker_image" "goserver" {
name = "gocd/gocd-server:latest"
}
resource "docker_image" "goagent" {
name = "gocd/gocd-agent:latest"
}
goagent 资源中的远程执行部分不起作用。我的假设是它登录到配置的 goagent 并根据指定的 sed 命令修改其中的文件。但相反,它正在对 docker 主机执行 ssh 并修改文件。我错过了什么吗?我们是否必须在远程设备的连接块中指定 IP 地址或主机名?