mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 20:35:24 +01:00
Merge pull request #2037 from semaphoreui/clear_inventory
feat(be): remove old inventory files
This commit is contained in:
commit
5948f4596c
@ -2,6 +2,7 @@ package tasks
|
||||
|
||||
import (
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
@ -30,17 +31,28 @@ func (t *LocalJob) installInventory() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (t *LocalJob) installStaticInventory() error {
|
||||
t.Log("installing static inventory")
|
||||
|
||||
func (t *LocalJob) tmpInventoryFilename() string {
|
||||
path := util.Config.TmpPath + "/inventory_" + strconv.Itoa(t.Task.ID)
|
||||
if t.Inventory.Type == db.InventoryStaticYaml {
|
||||
path += ".yml"
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func (t *LocalJob) installStaticInventory() error {
|
||||
t.Log("installing static inventory")
|
||||
|
||||
path := t.tmpInventoryFilename()
|
||||
|
||||
// create inventory file
|
||||
return os.WriteFile(path, []byte(t.Inventory.Inventory), 0664)
|
||||
}
|
||||
func (t *LocalJob) destroyInventoryFile() {
|
||||
path := t.tmpInventoryFilename()
|
||||
if err := os.Remove(path); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *LocalJob) destroyKeys() {
|
||||
err := t.sshKeyInstallation.Destroy()
|
||||
|
@ -3,9 +3,9 @@ package tasks
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"maps"
|
||||
"os"
|
||||
"strconv"
|
||||
"maps"
|
||||
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/ansible-semaphore/semaphore/db_lib"
|
||||
@ -204,10 +204,7 @@ func (t *LocalJob) getPlaybookArgs(username string, incomingVersion *string) (ar
|
||||
case db.InventoryFile:
|
||||
inventory = t.Inventory.Inventory
|
||||
case db.InventoryStatic, db.InventoryStaticYaml:
|
||||
inventory = util.Config.TmpPath + "/inventory_" + strconv.Itoa(t.Task.ID)
|
||||
if t.Inventory.Type == db.InventoryStaticYaml {
|
||||
inventory += ".yml"
|
||||
}
|
||||
inventory = t.tmpInventoryFilename()
|
||||
default:
|
||||
err = fmt.Errorf("invalid inventory type")
|
||||
return
|
||||
@ -333,6 +330,7 @@ func (t *LocalJob) Run(username string, incomingVersion *string) (err error) {
|
||||
|
||||
defer func() {
|
||||
t.destroyKeys()
|
||||
t.destroyInventoryFile()
|
||||
}()
|
||||
|
||||
var args []string
|
||||
|
Loading…
Reference in New Issue
Block a user