mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 20:35:24 +01:00
Pass OS environment variables to Ansible
This commit is contained in:
parent
65877535ca
commit
e0897e87c8
@ -225,12 +225,9 @@ func (t *task) updateRepository() error {
|
||||
|
||||
cmd := exec.Command("git")
|
||||
cmd.Dir = util.Config.TmpPath
|
||||
cmd.Env = []string{
|
||||
"HOME=" + util.Config.TmpPath,
|
||||
"PWD=" + util.Config.TmpPath,
|
||||
"GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=no -i " + t.repository.SshKey.GetPath(),
|
||||
// "GIT_FLUSH=1",
|
||||
}
|
||||
|
||||
gitSshCommand := "ssh -o StrictHostKeyChecking=no -i " + t.repository.SshKey.GetPath()
|
||||
cmd.Env = envVars(util.Config.TmpPath, cmd.Dir, gitSshCommand)
|
||||
|
||||
repoURL, repoTag := t.repository.GitUrl, "master"
|
||||
if split := strings.Split(repoURL, "#"); len(split) > 1 {
|
||||
@ -264,13 +261,9 @@ func (t *task) runGalaxy() error {
|
||||
|
||||
cmd := exec.Command("ansible-galaxy", args...)
|
||||
cmd.Dir = util.Config.TmpPath + "/repository_" + strconv.Itoa(t.repository.ID)
|
||||
cmd.Env = []string{
|
||||
"HOME=" + util.Config.TmpPath,
|
||||
"PWD=" + cmd.Dir,
|
||||
"PYTHONUNBUFFERED=1",
|
||||
"GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=no -i " + t.repository.SshKey.GetPath(),
|
||||
// "GIT_FLUSH=1",
|
||||
}
|
||||
|
||||
gitSshCommand := "ssh -o StrictHostKeyChecking=no -i " + t.repository.SshKey.GetPath()
|
||||
cmd.Env = envVars(util.Config.TmpPath, cmd.Dir, gitSshCommand)
|
||||
|
||||
if _, err := os.Stat(cmd.Dir + "/roles/requirements.yml"); err != nil {
|
||||
return nil
|
||||
@ -324,13 +317,22 @@ func (t *task) runPlaybook() error {
|
||||
|
||||
cmd := exec.Command("ansible-playbook", args...)
|
||||
cmd.Dir = util.Config.TmpPath + "/repository_" + strconv.Itoa(t.repository.ID)
|
||||
cmd.Env = []string{
|
||||
"HOME=" + util.Config.TmpPath,
|
||||
"PWD=" + cmd.Dir,
|
||||
"PYTHONUNBUFFERED=1",
|
||||
// "GIT_FLUSH=1",
|
||||
}
|
||||
cmd.Env = envVars(util.Config.TmpPath, cmd.Dir, nil)
|
||||
|
||||
t.logCmd(cmd)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func (t *task) envVars(home string, pwd string, gitSshCommand *string) []string {
|
||||
env := os.Environ()
|
||||
env = append(env, fmt.Sprintf("HOME=%s", util.Config.TmpPath))
|
||||
env = append(env, fmt.Sprintf("PWD=%s", cmd.Dir))
|
||||
env = append(env, fmt.Sprintln("PYTHONUNBUFFERED=1"))
|
||||
//env = append(env, fmt.Sprintln("GIT_FLUSH=1"))
|
||||
|
||||
if gitSshCommand != nil {
|
||||
env = append(env, fmt.Sprintf("GIT_SSH_COMMAND=%s", *gitSshCommand))
|
||||
}
|
||||
|
||||
return env
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user