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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.inventory.Type == db.InventoryStatic {
|
|
|
|
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
|
|
|
|
|
|
|
// create inventory file
|
|
|
|
return ioutil.WriteFile(util.Config.TmpPath+"/inventory_"+strconv.Itoa(t.task.ID), []byte(t.inventory.Inventory), 0664)
|
|
|
|
}
|