commit
bc16c13b50
|
@ -34,6 +34,9 @@ type Config struct {
|
||||||
// Local path to the minion config
|
// Local path to the minion config
|
||||||
MinionConfig string `mapstructure:"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
|
// Local path to the salt state tree
|
||||||
LocalStateTree string `mapstructure:"local_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"))
|
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
|
// build the command line args to pass onto salt
|
||||||
var cmd_args bytes.Buffer
|
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))
|
ui.Message(fmt.Sprintf("Uploading local state tree: %s", p.config.LocalStateTree))
|
||||||
src = p.config.LocalStateTree
|
src = p.config.LocalStateTree
|
||||||
dst = filepath.ToSlash(filepath.Join(p.config.TempConfigDir, "states"))
|
dst = filepath.ToSlash(filepath.Join(p.config.TempConfigDir, "states"))
|
||||||
|
|
|
@ -119,6 +119,29 @@ func TestProvisionerPrepare_MinionConfig_RemotePillarRoots(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProvisionerPrepare_GrainsFile(t *testing.T) {
|
||||||
|
var p Provisioner
|
||||||
|
config := testConfig()
|
||||||
|
|
||||||
|
config["grains_file"] = "/i/dont/exist/i/think"
|
||||||
|
err := p.Prepare(config)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("should have error")
|
||||||
|
}
|
||||||
|
|
||||||
|
tf, err := ioutil.TempFile("", "grains")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error tempfile: %s", err)
|
||||||
|
}
|
||||||
|
defer os.Remove(tf.Name())
|
||||||
|
|
||||||
|
config["grains_file"] = tf.Name()
|
||||||
|
err = p.Prepare(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestProvisionerPrepare_LocalStateTree(t *testing.T) {
|
func TestProvisionerPrepare_LocalStateTree(t *testing.T) {
|
||||||
var p Provisioner
|
var p Provisioner
|
||||||
config := testConfig()
|
config := testConfig()
|
||||||
|
|
|
@ -66,6 +66,10 @@ Optional:
|
||||||
uploaded to the `/etc/salt` on the remote. This option overrides the
|
uploaded to the `/etc/salt` on the remote. This option overrides the
|
||||||
`remote_state_tree` or `remote_pillar_roots` options.
|
`remote_state_tree` or `remote_pillar_roots` options.
|
||||||
|
|
||||||
|
- `grains_file` (string) - The path to your local [grains file](
|
||||||
|
https://docs.saltstack.com/en/latest/topics/grains). This will be
|
||||||
|
uploaded to `/etc/salt/grains` on the remote.
|
||||||
|
|
||||||
- `skip_bootstrap` (boolean) - By default the salt provisioner runs [salt
|
- `skip_bootstrap` (boolean) - By default the salt provisioner runs [salt
|
||||||
bootstrap](https://github.com/saltstack/salt-bootstrap) to install salt. Set
|
bootstrap](https://github.com/saltstack/salt-bootstrap) to install salt. Set
|
||||||
this to true to skip this step.
|
this to true to skip this step.
|
||||||
|
|
Loading…
Reference in New Issue