From 912fc9c2af5b5e7b587322e1dc5556641ee21cab Mon Sep 17 00:00:00 2001 From: Ian Ellis Date: Sun, 4 Jun 2017 00:11:42 +0100 Subject: [PATCH] Added grains_file config item to copy file to /etc/salt/grains --- provisioner/salt-masterless/provisioner.go | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/provisioner/salt-masterless/provisioner.go b/provisioner/salt-masterless/provisioner.go index 41d1e261b..9f4dc9b68 100644 --- a/provisioner/salt-masterless/provisioner.go +++ b/provisioner/salt-masterless/provisioner.go @@ -34,6 +34,9 @@ type Config struct { // Local path to the minion config MinionConfig string `mapstructure:"minion_config"` + // Local path to the minion grains + GrainsFile string `mapstructure:"grains_file"` + // Local path to the salt state tree LocalStateTree string `mapstructure:"local_state_tree"` @@ -107,6 +110,11 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { errors.New("remote_state_tree and remote_pillar_roots only apply when minion_config is not used")) } + err = validateFileConfig(p.config.GrainsFile, "grains_file", false) + if err != nil { + errs = packer.MultiErrorAppend(errs, err) + } + // build the command line args to pass onto salt var cmd_args bytes.Buffer @@ -208,6 +216,26 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { } } + if p.config.GrainsFile != "" { + ui.Message(fmt.Sprintf("Uploading grains file: %s", p.config.GrainsFile)) + src = p.config.GrainsFile + dst = filepath.ToSlash(filepath.Join(p.config.TempConfigDir, "grains")) + if err = p.uploadFile(ui, comm, dst, src); err != nil { + return fmt.Errorf("Error uploading local grains file to remote: %s", err) + } + + // move grains file into /etc/salt + ui.Message(fmt.Sprintf("Make sure directory %s exists", "/etc/salt")) + if err := p.createDir(ui, comm, "/etc/salt"); err != nil { + return fmt.Errorf("Error creating remote salt configuration directory: %s", err) + } + src = filepath.ToSlash(filepath.Join(p.config.TempConfigDir, "grains")) + dst = "/etc/salt/grains" + if err = p.moveFile(ui, comm, dst, src); err != nil { + return fmt.Errorf("Unable to move %s/grains to /etc/salt/grains: %s", p.config.TempConfigDir, err) + } + } + ui.Message(fmt.Sprintf("Uploading local state tree: %s", p.config.LocalStateTree)) src = p.config.LocalStateTree dst = filepath.ToSlash(filepath.Join(p.config.TempConfigDir, "states"))