2016-04-08 21:41:20 +02:00
|
|
|
package tasks
|
|
|
|
|
|
|
|
import (
|
2021-09-12 00:18:26 +02:00
|
|
|
"github.com/ansible-semaphore/semaphore/db"
|
2016-04-08 21:41:20 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/ansible-semaphore/semaphore/util"
|
|
|
|
)
|
|
|
|
|
2023-08-29 00:51:04 +02:00
|
|
|
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)
|
2016-04-08 21:41:20 +02:00
|
|
|
if err != nil {
|
2021-09-12 00:18:26 +02:00
|
|
|
return
|
2016-04-08 21:41:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-29 00:51:04 +02:00
|
|
|
if t.Inventory.BecomeKeyID != nil {
|
2023-09-23 17:47:27 +02:00
|
|
|
t.becomeKeyInstallation, err = t.Inventory.BecomeKey.Install(db.AccessKeyRoleAnsibleBecomeUser, t.Logger)
|
2021-09-12 00:18:26 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-29 00:51:04 +02:00
|
|
|
if t.Inventory.Type == db.InventoryStatic || t.Inventory.Type == db.InventoryStaticYaml {
|
2021-09-12 00:18:26 +02:00
|
|
|
err = t.installStaticInventory()
|
2016-04-08 21:41:20 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 00:18:26 +02:00
|
|
|
return
|
2016-04-08 21:41:20 +02:00
|
|
|
}
|
|
|
|
|
2023-08-29 00:51:04 +02:00
|
|
|
func (t *LocalJob) installStaticInventory() error {
|
2022-01-30 12:22:18 +01:00
|
|
|
t.Log("installing static inventory")
|
2016-04-08 21:41:20 +02:00
|
|
|
|
2023-08-29 00:51:04 +02:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2016-04-08 21:41:20 +02:00
|
|
|
// create inventory file
|
2023-08-29 00:51:04 +02:00
|
|
|
return ioutil.WriteFile(path, []byte(t.Inventory.Inventory), 0664)
|
2016-04-08 21:41:20 +02:00
|
|
|
}
|
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())
|
|
|
|
}
|
|
|
|
}
|