11package inventory
22
33import (
4- "errors"
54 "fmt"
65 "github.com/habakke/terraform-ansible-provider/internal/ansible/database"
76 "io/ioutil"
@@ -69,7 +68,7 @@ func (s *Inventory) GetAndLoadDatabase() (*database.Database, error) {
6968// Load loads the inventory from disk
7069func (s * Inventory ) Load () (string , error ) {
7170 if _ , err := os .Stat (s .groupVarsFile ); os .IsNotExist (err ) {
72- return "" , errors . New ("failed to load inventory because groupvars files doesn't exist" )
71+ return "" , fmt . Errorf ("failed to load inventory because groupvars files doesn't exist: %s" , err . Error () )
7372 }
7473
7574 if data , err := ioutil .ReadFile (s .groupVarsFile ); err != nil {
@@ -82,11 +81,11 @@ func (s *Inventory) Load() (string, error) {
8281// Commit saves groupVars for the inventory to disk
8382func (s * Inventory ) Commit (groupVars string ) error {
8483 if err := os .MkdirAll (fmt .Sprintf ("%s%sgroup_vars" , s .fullPath , string (os .PathSeparator )), os .ModePerm ); err != nil {
85- return errors . New ("failed to create inventory path" )
84+ return fmt . Errorf ("failed to create inventory path: %s" , err . Error () )
8685 }
8786
8887 if err := ioutil .WriteFile (s .groupVarsFile , []byte (groupVars ), os .ModePerm ); err != nil {
89- return errors . New ("failed to commit inventory to file" )
88+ return fmt . Errorf ("failed to commit inventory to file: %s" , err . Error () )
9089 }
9190
9291 return nil
0 commit comments