From 9aec33297d47e10b4d9780a8bae46846d05838a5 Mon Sep 17 00:00:00 2001 From: Alexandre Pagliaro Date: Thu, 7 Sep 2023 12:58:48 +0200 Subject: [PATCH 1/2] Test fix collection installation --- services/tasks/LocalJob.go | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/services/tasks/LocalJob.go b/services/tasks/LocalJob.go index 860b4098d..9b815dcd9 100644 --- a/services/tasks/LocalJob.go +++ b/services/tasks/LocalJob.go @@ -86,6 +86,7 @@ func (t *LocalJob) getEnvironmentExtraVars(username string, incomingVersion *str func (t *LocalJob) getEnvironmentENV() (arr []string, err error) { environmentVars := make(map[string]string) + if t.Environment.ENV != nil { err = json.Unmarshal([]byte(*t.Environment.ENV), &environmentVars) if err != nil { @@ -93,6 +94,9 @@ func (t *LocalJob) getEnvironmentENV() (arr []string, err error) { } } + environmentVars["ANSIBLE_COLLECTIONS_PATHS"] = fmt.Sprintf("%s/collections,%s/.ansible/collections", + t.getPlaybookDir(), os.UserHomeDir()) + for key, val := range environmentVars { arr = append(arr, fmt.Sprintf("%s=%s", key, val)) } @@ -414,6 +418,8 @@ func (t *LocalJob) installRolesRequirements() error { "install", "-r", requirementsFilePath, + "-p", + t.getRepoPath(), "--force", }); err != nil { return err @@ -435,29 +441,24 @@ func (t *LocalJob) getPlaybookDir() string { } func (t *LocalJob) installCollectionsRequirements() error { - requirementsFilePath := path.Join(t.getPlaybookDir(), "collections", "requirements.yml") - requirementsHashFilePath := fmt.Sprintf("%s.md5", requirementsFilePath) + collectionsDirPath := path.Join(t.getPlaybookDir(), "collections") + requirementsFilePath := path.Join(collectionsDirPath, "requirements.yml") if _, err := os.Stat(requirementsFilePath); err != nil { t.Log("No collections/requirements.yml file found. Skip galaxy install process.\n") return nil } - if hasRequirementsChanges(requirementsFilePath, requirementsHashFilePath) { - if err := t.runGalaxy([]string{ - "collection", - "install", - "-r", - requirementsFilePath, - "--force", - }); err != nil { - return err - } - if err := writeMD5Hash(requirementsFilePath, requirementsHashFilePath); err != nil { - return err - } - } else { - t.Log("collections/requirements.yml has no changes. Skip galaxy install process.\n") + if err := t.runGalaxy([]string{ + "collection", + "install", + "-r", + requirementsFilePath, + "-p", + collectionsDirPath, + "--force", + }); err != nil { + return err } return nil From 83bae04d130e73ca9605dc0f37e15b7fecc6c0c2 Mon Sep 17 00:00:00 2001 From: Alexandre Pagliaro Date: Thu, 7 Sep 2023 13:01:49 +0200 Subject: [PATCH 2/2] Test fix collection installation --- services/tasks/LocalJob.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/services/tasks/LocalJob.go b/services/tasks/LocalJob.go index 9b815dcd9..9e7761b0e 100644 --- a/services/tasks/LocalJob.go +++ b/services/tasks/LocalJob.go @@ -86,7 +86,6 @@ func (t *LocalJob) getEnvironmentExtraVars(username string, incomingVersion *str func (t *LocalJob) getEnvironmentENV() (arr []string, err error) { environmentVars := make(map[string]string) - if t.Environment.ENV != nil { err = json.Unmarshal([]byte(*t.Environment.ENV), &environmentVars) if err != nil { @@ -418,8 +417,6 @@ func (t *LocalJob) installRolesRequirements() error { "install", "-r", requirementsFilePath, - "-p", - t.getRepoPath(), "--force", }); err != nil { return err