From 6420fbb4693c2335afa4ca9576c05de2f9227250 Mon Sep 17 00:00:00 2001 From: Ryan Burrows Date: Tue, 18 Mar 2014 11:11:34 -0700 Subject: [PATCH] Fix ansible paths when provisioning Linux from Windows Since the paths are generated on the host machine but the commands are executed on the VM being provisioned the paths generated will use path separators from the host. In the case of provisioning a Linux VM from Windows this path will not work. Convert the path to use a '/' separator which should work for both platforms in Go --- provisioner/ansible-local/provisioner.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/provisioner/ansible-local/provisioner.go b/provisioner/ansible-local/provisioner.go index f08c2985f..ca6574335 100644 --- a/provisioner/ansible-local/provisioner.go +++ b/provisioner/ansible-local/provisioner.go @@ -153,7 +153,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { ui.Message("Uploading main Playbook file...") src := p.config.PlaybookFile - dst := filepath.Join(p.config.StagingDir, filepath.Base(src)) + dst := filepath.ToSlash(filepath.Join(p.config.StagingDir, filepath.Base(src))) if err := p.uploadFile(ui, comm, dst, src); err != nil { return fmt.Errorf("Error uploading main playbook: %s", err) } @@ -161,7 +161,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { if len(p.config.GroupVars) > 0 { ui.Message("Uploading group_vars directory...") src := p.config.GroupVars - dst := filepath.Join(p.config.StagingDir, "group_vars") + dst := filepath.ToSlash(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) } @@ -170,7 +170,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { if len(p.config.HostVars) > 0 { ui.Message("Uploading host_vars directory...") src := p.config.HostVars - dst := filepath.Join(p.config.StagingDir, "host_vars") + dst := filepath.ToSlash(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) } @@ -179,7 +179,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { if len(p.config.RolePaths) > 0 { ui.Message("Uploading role directories...") for _, src := range p.config.RolePaths { - dst := filepath.Join(p.config.StagingDir, "roles", filepath.Base(src)) + dst := filepath.ToSlash(filepath.Join(p.config.StagingDir, "roles", filepath.Base(src))) if err := p.uploadDir(ui, comm, dst, src); err != nil { return fmt.Errorf("Error uploading roles: %s", err) } @@ -188,11 +188,12 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { if len(p.config.PlaybookPaths) > 0 { ui.Message("Uploading additional Playbooks...") - if err := p.createDir(ui, comm, filepath.Join(p.config.StagingDir, "playbooks")); err != nil { + playbookDir := filepath.ToSlash(filepath.Join(p.config.StagingDir, "playbooks")) + if err := p.createDir(ui, comm, playbookDir); err != nil { return fmt.Errorf("Error creating playbooks directory: %s", err) } for _, src := range p.config.PlaybookPaths { - dst := filepath.Join(p.config.StagingDir, "playbooks", filepath.Base(src)) + dst := filepath.ToSlash(filepath.Join(playbookDir, filepath.Base(src))) if err := p.uploadDir(ui, comm, dst, src); err != nil { return fmt.Errorf("Error uploading playbooks: %s", err) } @@ -212,7 +213,7 @@ func (p *Provisioner) Cancel() { } func (p *Provisioner) executeAnsible(ui packer.Ui, comm packer.Communicator) error { - playbook := filepath.Join(p.config.StagingDir, filepath.Base(p.config.PlaybookFile)) + playbook := filepath.ToSlash(filepath.Join(p.config.StagingDir, filepath.Base(p.config.PlaybookFile))) // The inventory must be set to "127.0.0.1,". The comma is important // as its the only way to override the ansible inventory when dealing