diff --git a/builtin/provisioners/chef/linux_provisioner.go b/builtin/provisioners/chef/linux_provisioner.go index 2a1e92eab..b7a3b2813 100644 --- a/builtin/provisioners/chef/linux_provisioner.go +++ b/builtin/provisioners/chef/linux_provisioner.go @@ -71,12 +71,29 @@ func (p *Provisioner) linuxCreateConfigFiles( return err } + // Make sure we have enough rights to upload the hints if using sudo + if p.useSudo { + if err := p.runCommand(o, comm, "chmod 777 "+hintsDir); err != nil { + return err + } + } + if err := p.deployOhaiHints(o, comm, hintsDir); err != nil { return err } + + // When done copying the hints restore the rights and make sure root is owner + if p.useSudo { + if err := p.runCommand(o, comm, "chmod 755 "+hintsDir); err != nil { + return err + } + if err := p.runCommand(o, comm, "chown -R root.root "+hintsDir); err != nil { + return err + } + } } - // When done copying the files restore the rights and make sure root is owner + // When done copying all files restore the rights and make sure root is owner if p.useSudo { if err := p.runCommand(o, comm, "chmod 755 "+linuxConfDir); err != nil { return err diff --git a/builtin/provisioners/chef/linux_provisioner_test.go b/builtin/provisioners/chef/linux_provisioner_test.go index 2d509f3cb..27a1dbba0 100644 --- a/builtin/provisioners/chef/linux_provisioner_test.go +++ b/builtin/provisioners/chef/linux_provisioner_test.go @@ -163,11 +163,14 @@ func TestResourceProvider_linuxCreateConfigFiles(t *testing.T) { }), Commands: map[string]bool{ - "sudo mkdir -p " + linuxConfDir: true, - "sudo chmod 777 " + linuxConfDir: true, - "sudo mkdir -p " + path.Join(linuxConfDir, "ohai/hints"): true, - "sudo chmod 755 " + linuxConfDir: true, - "sudo chown -R root.root " + linuxConfDir: true, + "sudo mkdir -p " + linuxConfDir: true, + "sudo chmod 777 " + linuxConfDir: true, + "sudo mkdir -p " + path.Join(linuxConfDir, "ohai/hints"): true, + "sudo chmod 777 " + path.Join(linuxConfDir, "ohai/hints"): true, + "sudo chmod 755 " + path.Join(linuxConfDir, "ohai/hints"): true, + "sudo chown -R root.root " + path.Join(linuxConfDir, "ohai/hints"): true, + "sudo chmod 755 " + linuxConfDir: true, + "sudo chown -R root.root " + linuxConfDir: true, }, Uploads: map[string]string{