chore: simplify code

This commit is contained in:
Denis Gukov 2024-11-13 22:31:20 +05:00
parent a1fa8d91bc
commit ee27ef3410
3 changed files with 2 additions and 16 deletions

View File

@ -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))

View File

@ -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

View File

@ -36,7 +36,6 @@ func TestGetEnvironmentVars(t *testing.T) {
expected := []string{
"SEMAPHORE_TEST=test123",
"ANSIBLE_FORCE_COLOR=False",
"ANSIBLE_HOST_KEY_CHECKING=False",
"PATH=",
}