provisioner/ansible: support {group,host}_vars
ansible looks for group and host vars directories as well as playbooks this revision to the provisioner uploads those as well. squashed to a single commit by strcrzy.
This commit is contained in:
parent
ec1adec029
commit
458d90c71d
|
@ -24,6 +24,12 @@ type Config struct {
|
|||
// An array of local paths of roles to upload.
|
||||
RolePaths []string `mapstructure:"role_paths"`
|
||||
|
||||
// Path to group_vars directory
|
||||
GroupVars string `mapstructure:"group_vars"`
|
||||
|
||||
// Path to host_vars directory
|
||||
HostVars string `mapstructure:"host_vars"`
|
||||
|
||||
// The directory where files will be uploaded. Packer requires write
|
||||
// permissions in this directory.
|
||||
StagingDir string `mapstructure:"staging_directory"`
|
||||
|
@ -69,6 +75,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
"playbook_file": &p.config.PlaybookFile,
|
||||
"staging_dir": &p.config.StagingDir,
|
||||
"command": &p.config.Command,
|
||||
"group_vars": &p.config.GroupVars,
|
||||
"host_vars": &p.config.HostVars,
|
||||
}
|
||||
|
||||
for n, ptr := range templates {
|
||||
|
@ -113,6 +121,20 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
errs = packer.MultiErrorAppend(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Check that the group_vars directory exists, if configured
|
||||
if len(p.config.GroupVars) > 0 {
|
||||
if err := validateDirConfig(p.config.GroupVars, "group_vars"); err != nil {
|
||||
errs = packer.MultiErrorAppend(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Check that the host_vars directory exists, if configured
|
||||
if len(p.config.HostVars) > 0 {
|
||||
if err := validateDirConfig(p.config.HostVars, "host_vars"); err != nil {
|
||||
errs = packer.MultiErrorAppend(errs, err)
|
||||
}
|
||||
}
|
||||
if errs != nil && len(errs.Errors) > 0 {
|
||||
return errs
|
||||
}
|
||||
|
@ -134,6 +156,26 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
|||
return fmt.Errorf("Error uploading main playbook: %s", err)
|
||||
}
|
||||
|
||||
// Upload group_vars
|
||||
if len(p.config.GroupVars) > 0 {
|
||||
ui.Message("Uploading group_vars directory...")
|
||||
src := p.config.GroupVars
|
||||
dst := filepath.Join(p.config.StagingDir, "group_vars")
|
||||
if err := p.uploadDir(ui, comm, dst, src); err != nil {
|
||||
return fmt.Errorf("Error uploading group_vars directory: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Upload host_vars
|
||||
if len(p.config.HostVars) > 0 {
|
||||
ui.Message("Uploading host_vars directory...")
|
||||
src := p.config.HostVars
|
||||
dst := filepath.Join(p.config.StagingDir, "host_vars")
|
||||
if err := p.uploadDir(ui, comm, dst, src); err != nil {
|
||||
return fmt.Errorf("Error uploading host_vars directory: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(p.config.RolePaths) > 0 {
|
||||
ui.Message("Uploading role directories...")
|
||||
for _, src := range p.config.RolePaths {
|
||||
|
|
|
@ -120,4 +120,28 @@ func TestProvisionerPrepare_Dirs(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
config["group_vars"] = playbook_file.Name()
|
||||
err = p.Prepare(config)
|
||||
if err == nil {
|
||||
t.Fatalf("should error if group_vars path is not a dir")
|
||||
}
|
||||
|
||||
config["group_vars"] = os.TempDir()
|
||||
err = p.Prepare(config)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
config["host_vars"] = playbook_file.Name()
|
||||
err = p.Prepare(config)
|
||||
if err == nil {
|
||||
t.Fatalf("should error if host_vars path is not a dir")
|
||||
}
|
||||
|
||||
config["host_vars"] = os.TempDir()
|
||||
err = p.Prepare(config)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue