Semaphore/services/tasks/LobalJob_inventory.go

61 lines
1.4 KiB
Go
Raw Normal View History

package tasks
import (
"github.com/ansible-semaphore/semaphore/db"
"io/ioutil"
"strconv"
"github.com/ansible-semaphore/semaphore/util"
)
func (t *LocalJob) installInventory() (err error) {
if t.Inventory.SSHKeyID != nil {
2023-09-23 17:47:27 +02:00
t.sshKeyInstallation, err = t.Inventory.SSHKey.Install(db.AccessKeyRoleAnsibleUser, t.Logger)
if err != nil {
return
}
}
if t.Inventory.BecomeKeyID != nil {
2023-09-23 17:47:27 +02:00
t.becomeKeyInstallation, err = t.Inventory.BecomeKey.Install(db.AccessKeyRoleAnsibleBecomeUser, t.Logger)
if err != nil {
return
}
}
if t.Inventory.Type == db.InventoryStatic || t.Inventory.Type == db.InventoryStaticYaml {
err = t.installStaticInventory()
}
return
}
func (t *LocalJob) installStaticInventory() error {
t.Log("installing static inventory")
path := util.Config.TmpPath + "/inventory_" + strconv.Itoa(t.Task.ID)
if t.Inventory.Type == db.InventoryStaticYaml {
2022-05-24 17:54:33 +02:00
path += ".yml"
}
// create inventory file
return ioutil.WriteFile(path, []byte(t.Inventory.Inventory), 0664)
}
2023-09-23 17:47:27 +02:00
func (t *LocalJob) destroyKeys() {
err := t.sshKeyInstallation.Destroy()
if err != nil {
t.Log("Can't destroy inventory user key, error: " + err.Error())
}
err = t.becomeKeyInstallation.Destroy()
if err != nil {
t.Log("Can't destroy inventory become user key, error: " + err.Error())
}
err = t.vaultFileInstallation.Destroy()
if err != nil {
t.Log("Can't destroy inventory vault password file, error: " + err.Error())
}
}