Semaphore/services/tasks/inventory.go

44 lines
949 B
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 *TaskRunner) installInventory() (err error) {
if t.inventory.SSHKeyID != nil {
err = t.inventory.SSHKey.Install(db.AccessKeyRoleAnsibleUser)
if err != nil {
return
}
}
if t.inventory.BecomeKeyID != nil {
err = t.inventory.BecomeKey.Install(db.AccessKeyRoleAnsibleBecomeUser)
if err != nil {
return
}
}
2022-05-24 17:54:33 +02:00
if t.inventory.Type == db.InventoryStatic || t.inventory.Type == db.InventoryStaticYaml {
err = t.installStaticInventory()
}
return
}
func (t *TaskRunner) installStaticInventory() error {
t.Log("installing static inventory")
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"
}
// create inventory file
2022-05-24 17:54:33 +02:00
return ioutil.WriteFile(path, []byte(t.inventory.Inventory), 0664)
}