From 136f062c27eedf31cbd784d1c238b90491bc8fe1 Mon Sep 17 00:00:00 2001 From: Alex Genco Date: Sat, 30 Jul 2022 12:59:30 -0700 Subject: [PATCH] Allow inventory commands to recognize top-level env vars --- cmd/sup/main.go | 2 +- supfile.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/sup/main.go b/cmd/sup/main.go index e1f35ee..1eafffb 100644 --- a/cmd/sup/main.go +++ b/cmd/sup/main.go @@ -137,7 +137,7 @@ func parseArgs(conf *sup.Supfile) (*sup.Network, []*sup.Command, error) { network.Env.Set(env[:i], env[i+1:]) } - hosts, err := network.ParseInventory() + hosts, err := network.ParseInventory(conf) if err != nil { return nil, nil, err } diff --git a/supfile.go b/supfile.go index 2cf88b5..2a51572 100644 --- a/supfile.go +++ b/supfile.go @@ -329,13 +329,14 @@ func NewSupfile(data []byte) (*Supfile, error) { // ParseInventory runs the inventory command, if provided, and appends // the command's output lines to the manually defined list of hosts. -func (n Network) ParseInventory() ([]string, error) { +func (n Network) ParseInventory(conf *Supfile) ([]string, error) { if n.Inventory == "" { return nil, nil } cmd := exec.Command("/bin/sh", "-c", n.Inventory) cmd.Env = os.Environ() + cmd.Env = append(cmd.Env, conf.Env.Slice()...) cmd.Env = append(cmd.Env, n.Env.Slice()...) cmd.Stderr = os.Stderr output, err := cmd.Output()