Merge pull request #353 from rach/add-setting-for-pillar-folder

provisioner/salt-masterless: Add setting for pillar folder
This commit is contained in:
Mitchell Hashimoto 2013-08-27 17:36:28 -07:00
commit a8694fdda8
3 changed files with 69 additions and 9 deletions

View File

@ -27,6 +27,9 @@ type Config struct {
// 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"`
// Local path to the salt pillar roots
LocalPillarRoots string `mapstructure:"local_pillar_roots"`
// Where files will be copied before moving to the /srv/salt directory // Where files will be copied before moving to the /srv/salt directory
TempConfigDir string `mapstructure:"temp_config_dir"` TempConfigDir string `mapstructure:"temp_config_dir"`
@ -60,6 +63,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
"bootstrap_args": &p.config.BootstrapArgs, "bootstrap_args": &p.config.BootstrapArgs,
"minion_config": &p.config.MinionConfig, "minion_config": &p.config.MinionConfig,
"local_state_tree": &p.config.LocalStateTree, "local_state_tree": &p.config.LocalStateTree,
"local_pillar_roots": &p.config.LocalPillarRoots,
"temp_config_dir": &p.config.TempConfigDir, "temp_config_dir": &p.config.TempConfigDir,
} }
@ -79,6 +83,13 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
} }
} }
if p.config.LocalPillarRoots != "" {
if _, err := os.Stat(p.config.LocalPillarRoots); err != nil {
errs = packer.MultiErrorAppend(errs,
errors.New("local_pillar_roots must exist and be accessible"))
}
}
if p.config.MinionConfig != "" { if p.config.MinionConfig != "" {
if _, err := os.Stat(p.config.MinionConfig); err != nil { if _, err := os.Stat(p.config.MinionConfig); err != nil {
errs = packer.MultiErrorAppend(errs, errs = packer.MultiErrorAppend(errs,
@ -119,8 +130,8 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
return fmt.Errorf("Error uploading local state tree to remote: %s", err) return fmt.Errorf("Error uploading local state tree to remote: %s", err)
} }
ui.Message(fmt.Sprintf("Creating remote directory: %s", p.config.TempConfigDir)) ui.Message(fmt.Sprintf("Creating remote states directory: %s/states", p.config.TempConfigDir))
cmd := &packer.RemoteCmd{Command: fmt.Sprintf("mkdir -p %s", p.config.TempConfigDir)} cmd := &packer.RemoteCmd{Command: fmt.Sprintf("mkdir -p %s/states", p.config.TempConfigDir)}
if err = cmd.StartWithUi(comm, ui); err != nil || cmd.ExitStatus != 0 { if err = cmd.StartWithUi(comm, ui); err != nil || cmd.ExitStatus != 0 {
if err == nil { if err == nil {
err = fmt.Errorf("Bad exit status: %d", cmd.ExitStatus) err = fmt.Errorf("Bad exit status: %d", cmd.ExitStatus)
@ -130,18 +141,46 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
} }
ui.Message(fmt.Sprintf("Uploading local state tree: %s", p.config.LocalStateTree)) ui.Message(fmt.Sprintf("Uploading local state tree: %s", p.config.LocalStateTree))
if err = UploadLocalDirectory(p.config.LocalStateTree, p.config.TempConfigDir, comm, ui); err != nil { if err = UploadLocalDirectory(p.config.LocalStateTree, fmt.Sprintf("%s/states", p.config.TempConfigDir), comm, ui); err != nil {
return fmt.Errorf("Error uploading local state tree to remote: %s", err) return fmt.Errorf("Error uploading local state tree to remote: %s", err)
} }
ui.Message(fmt.Sprintf("Moving %s to /srv/salt", p.config.TempConfigDir)) ui.Message(fmt.Sprintf("Moving %s to /srv/salt", p.config.TempConfigDir))
cmd = &packer.RemoteCmd{Command: fmt.Sprintf("sudo mv %s /srv/salt", p.config.TempConfigDir)} cmd = &packer.RemoteCmd{Command: fmt.Sprintf("sudo mv %s/states /srv/salt/", p.config.TempConfigDir)}
if err = cmd.StartWithUi(comm, ui); err != nil || cmd.ExitStatus != 0 { if err = cmd.StartWithUi(comm, ui); err != nil || cmd.ExitStatus != 0 {
if err == nil { if err == nil {
err = fmt.Errorf("Bad exit status: %d", cmd.ExitStatus) err = fmt.Errorf("Bad exit status: %d", cmd.ExitStatus)
} }
return fmt.Errorf("Unable to move %s to /srv/salt: %d", p.config.TempConfigDir, err) return fmt.Errorf("Unable to move %s/states to /srv/salt: %d", p.config.TempConfigDir, err)
}
if p.config.LocalPillarRoots != "" {
ui.Message(fmt.Sprintf("Creating remote pillar directory: %s/pillar", p.config.TempConfigDir))
cmd := &packer.RemoteCmd{Command: fmt.Sprintf("mkdir -p %s/pillar", p.config.TempConfigDir)}
if err = cmd.StartWithUi(comm, ui); err != nil || cmd.ExitStatus != 0 {
if err == nil {
err = fmt.Errorf("Bad exit status: %d", cmd.ExitStatus)
}
return fmt.Errorf("Error creating remote pillar directory: %s", err)
}
ui.Message(fmt.Sprintf("Uploading local pillar roots: %s", p.config.LocalPillarRoots))
if err = UploadLocalDirectory(p.config.LocalPillarRoots, fmt.Sprintf("%s/pillar", p.config.TempConfigDir), comm, ui); err != nil {
return fmt.Errorf("Error uploading local pillar roots to remote: %s", err)
}
ui.Message(fmt.Sprintf("Moving %s/pillar to /srv/pillar", p.config.TempConfigDir))
cmd = &packer.RemoteCmd{Command: fmt.Sprintf("sudo mv %s/pillar /srv/pillar", p.config.TempConfigDir)}
if err = cmd.StartWithUi(comm, ui); err != nil || cmd.ExitStatus != 0 {
if err == nil {
err = fmt.Errorf("Bad exit status: %d", cmd.ExitStatus)
}
return fmt.Errorf("Unable to move %s/pillar to /srv/pillar: %d", p.config.TempConfigDir, err)
}
} }
ui.Message("Running highstate") ui.Message("Running highstate")

View File

@ -86,3 +86,20 @@ func TestProvisionerPrepare_LocalStateTree(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
} }
func TestProvisionerPrepare_LocalPillarRoots(t *testing.T) {
var p Provisioner
config := testConfig()
config["local_pillar_roots"] = "/i/dont/exist/i/think"
err := p.Prepare(config)
if err == nil {
t.Fatal("should have error")
}
config["local_pillar_roots"] = os.TempDir()
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
}

View File

@ -30,6 +30,10 @@ Optional:
[state tree](http://docs.saltstack.com/ref/states/highstate.html#the-salt-state-tree). [state tree](http://docs.saltstack.com/ref/states/highstate.html#the-salt-state-tree).
This will be uploaded to the `/srv/salt` on the remote. This will be uploaded to the `/srv/salt` on the remote.
* `local_pillar_roots` (string) - The path to your local
[pillar roots](http://docs.saltstack.com/ref/configuration/master.html#pillar-configuration).
This will be uploaded to the `/srv/pillar` on the remote.
* `skip_bootstrap` (boolean) - By default the salt provisioner runs * `skip_bootstrap` (boolean) - By default the salt provisioner runs
[salt bootstrap](https://github.com/saltstack/salt-bootstrap) to install [salt bootstrap](https://github.com/saltstack/salt-bootstrap) to install
salt. Set this to true to skip this step. salt. Set this to true to skip this step.