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"
|
|
|
|
)
|
|
|
|
|
2022-01-29 19:00:21 +01:00
|
|
|
func (t *TaskRunner) installInventory() (err error) {
|
2018-03-27 22:12:47 +02:00
|
|
|
if t.inventory.SSHKeyID != nil {
|
2022-02-05 19:42:09 +01:00
|
|
|
err = t.inventory.SSHKey.Install(db.AccessKeyRoleAnsibleUser)
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-12 00:18:26 +02:00
|
|
|
if t.inventory.BecomeKeyID != nil {
|
2022-02-05 19:42:09 +01:00
|
|
|
err = t.inventory.BecomeKey.Install(db.AccessKeyRoleAnsibleBecomeUser)
|
2021-09-12 00:18:26 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-24 17:54:33 +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
|
|
|
}
|
|
|
|
|
2022-01-29 19:00:21 +01:00
|
|
|
func (t *TaskRunner) installStaticInventory() error {
|
2022-01-30 12:22:18 +01:00
|
|
|
t.Log("installing static inventory")
|
2016-04-08 21:41:20 +02:00
|
|
|
|
2022-05-24 17:54:33 +02:00
|
|
|
path := util.Config.TmpPath + "/inventory_" + strconv.Itoa(t.task.ID)
|
|
|
|
if t.inventory.Type == db.InventoryStaticYaml {
|
|
|
|
path += ".yml"
|
|
|
|
}
|
|
|
|
|
2016-04-08 21:41:20 +02:00
|
|
|
// create inventory file
|
2022-05-24 17:54:33 +02:00
|
|
|
return ioutil.WriteFile(path, []byte(t.inventory.Inventory), 0664)
|
2016-04-08 21:41:20 +02:00
|
|
|
}
|