mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-21 08:51:05 +01:00
chore: simplify code
This commit is contained in:
parent
a1fa8d91bc
commit
ee27ef3410
@ -6,10 +6,10 @@ import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/creack/pty"
|
||||
"github.com/semaphoreui/semaphore/db"
|
||||
"github.com/semaphoreui/semaphore/pkg/task_logger"
|
||||
"github.com/semaphoreui/semaphore/util"
|
||||
"github.com/creack/pty"
|
||||
)
|
||||
|
||||
type AnsiblePlaybook struct {
|
||||
@ -24,6 +24,7 @@ func (p AnsiblePlaybook) makeCmd(command string, args []string, environmentVars
|
||||
|
||||
cmd.Env = append(cmd.Env, "PYTHONUNBUFFERED=1")
|
||||
cmd.Env = append(cmd.Env, "ANSIBLE_FORCE_COLOR=True")
|
||||
cmd.Env = append(cmd.Env, "ANSIBLE_HOST_KEY_CHECKING=False")
|
||||
cmd.Env = append(cmd.Env, getEnvironmentVars()...)
|
||||
cmd.Env = append(cmd.Env, fmt.Sprintf("HOME=%s", util.Config.TmpPath))
|
||||
cmd.Env = append(cmd.Env, fmt.Sprintf("PWD=%s", cmd.Dir))
|
||||
|
@ -13,29 +13,15 @@ func getEnvironmentVars() []string {
|
||||
fmt.Sprintf("PATH=%s", os.Getenv("PATH")),
|
||||
}
|
||||
|
||||
hasHostKeyCheckingFlag := false
|
||||
|
||||
for _, e := range util.Config.ForwardedEnvVars {
|
||||
v := os.Getenv(e)
|
||||
if v != "" {
|
||||
res = append(res, fmt.Sprintf("%s=%s", e, v))
|
||||
}
|
||||
|
||||
if e == "ANSIBLE_HOST_KEY_CHECKING" {
|
||||
hasHostKeyCheckingFlag = true
|
||||
}
|
||||
}
|
||||
|
||||
for k, v := range util.Config.EnvVars {
|
||||
res = append(res, fmt.Sprintf("%s=%s", k, v))
|
||||
|
||||
if k == "ANSIBLE_HOST_KEY_CHECKING" {
|
||||
hasHostKeyCheckingFlag = true
|
||||
}
|
||||
}
|
||||
|
||||
if !hasHostKeyCheckingFlag {
|
||||
res = append(res, "ANSIBLE_HOST_KEY_CHECKING=False")
|
||||
}
|
||||
|
||||
return res
|
||||
|
@ -36,7 +36,6 @@ func TestGetEnvironmentVars(t *testing.T) {
|
||||
expected := []string{
|
||||
"SEMAPHORE_TEST=test123",
|
||||
"ANSIBLE_FORCE_COLOR=False",
|
||||
"ANSIBLE_HOST_KEY_CHECKING=False",
|
||||
"PATH=",
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user