MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / writeTempInventoryResult

Function writeTempInventoryResult

internal/plugins/ansible/runner.go:360–398  ·  view source on GitHub ↗
(inventory InventoryResult)

Source from the content-addressed store, hash-verified

358}
359
360func writeTempInventoryResult(inventory InventoryResult) (path string, cleanup func(), err error) {
361 ext := ".ini"
362 if NormalizeInventorySource(inventory.Source) == InventorySourceProxmox {
363 ext = ".proxmox.yml"
364 } else if NormalizeInventoryFormat(inventory.Format) == InventoryFormatYAML {
365 ext = ".yml"
366 }
367
368 tmpFile, err := os.CreateTemp("", "pvetui-ansible-inventory-*"+ext)
369 if err != nil {
370 return "", nil, err
371 }
372
373 defer func() {
374 if err != nil {
375 _ = tmpFile.Close()
376 // #nosec G703 -- tmpFile path is created by os.CreateTemp in system temp dir.
377 _ = os.Remove(tmpFile.Name())
378 }
379 }()
380
381 if _, err = tmpFile.WriteString(inventory.Text); err != nil {
382 return "", nil, err
383 }
384 if err = tmpFile.Close(); err != nil {
385 return "", nil, err
386 }
387 // #nosec G703 -- tmpFile path is created by os.CreateTemp in system temp dir.
388 if err = os.Chmod(tmpFile.Name(), 0o600); err != nil {
389 return "", nil, err
390 }
391
392 cleanup = func() {
393 // #nosec G703 -- tmpFile path is created by os.CreateTemp in system temp dir.
394 _ = os.Remove(tmpFile.Name())
395 }
396
397 return tmpFile.Name(), cleanup, nil
398}
399
400func mergeEnvMap(base []string, extra map[string]string) []string {
401 if len(extra) == 0 {

Calls 4

NormalizeInventorySourceFunction · 0.85
NormalizeInventoryFormatFunction · 0.85
CloseMethod · 0.65
NameMethod · 0.65