mirror of
https://github.com/hanzozt/zt.git
synced 2026-11-03 05:01:58 +00:00
- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
package ztlib_runlevel_0_infrastructure
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hanzozt/fablab/kernel/libssh"
|
|
|
|
"github.com/hanzozt/fablab/kernel/model"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type installConsul struct {
|
|
hostSpec string
|
|
}
|
|
|
|
func InstallConsul(hostSpec string) model.Stage {
|
|
return &installConsul{
|
|
hostSpec: hostSpec,
|
|
}
|
|
}
|
|
|
|
func (imb *installConsul) Execute(run model.Run) error {
|
|
return run.GetModel().ForEachHost(imb.hostSpec, 25, func(host *model.Host) error {
|
|
ssh := host.NewSshConfigFactory()
|
|
|
|
if output, err := libssh.RemoteExec(ssh, "curl --fail --silent --show-error --location https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo dd of=/usr/share/keyrings/hashicorp-archive-keyring.gpg"); err != nil {
|
|
return fmt.Errorf("error getting hashicorp gpg key on host [%s] %s (%s)", host.PublicIp, output, err)
|
|
}
|
|
|
|
if output, err := libssh.RemoteExec(ssh, "echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main\" | sudo tee -a /etc/apt/sources.list.d/hashicorp.list"); err != nil {
|
|
return fmt.Errorf("error adding hashicorp repo to apt on host [%s] %s (%s)", host.PublicIp, output, err)
|
|
}
|
|
|
|
cmd := "sudo apt-get update && sudo apt-get install consul -y"
|
|
|
|
if output, err := libssh.RemoteExec(ssh, cmd); err != nil {
|
|
return fmt.Errorf("error installing Consul on host [%s] %s (%s)", host.PublicIp, output, err)
|
|
}
|
|
logrus.Infof("%s => %s", host.PublicIp, "installing Consul")
|
|
return nil
|
|
})
|
|
}
|