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"
|
|
|
|
)
|
|
|
|
|
2021-09-12 00:18:26 +02:00
|
|
|
func (t *task) installInventory() (err error) {
|
2018-03-27 22:12:47 +02:00
|
|
|
if t.inventory.SSHKeyID != nil {
|
2021-09-12 00:18:26 +02:00
|
|
|
err = t.inventory.SSHKey.Install(db.AccessKeyUsageAnsibleUser)
|
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 {
|
|
|
|
err = t.inventory.BecomeKey.Install(db.AccessKeyUsageAnsibleBecomeUser)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func (t *task) installStaticInventory() error {
|
|
|
|
t.log("installing static inventory")
|
|
|
|
|
|
|
|
// create inventory file
|
|
|
|
return ioutil.WriteFile(util.Config.TmpPath+"/inventory_"+strconv.Itoa(t.task.ID), []byte(t.inventory.Inventory), 0664)
|
|
|
|
}
|