From df909ca3caea08afb39102b6298496154aac34b9 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Mon, 20 Jul 2015 18:31:32 +0200 Subject: [PATCH 1/2] Fix an issue with `sudo` and `hints` Fixes issue #2781 --- .../provisioners/chef/linux_provisioner.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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 From 885b4e9278ebe6cba8aa1b7730352a9372908db7 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Mon, 20 Jul 2015 18:34:44 +0200 Subject: [PATCH 2/2] Updating the test accordingly... --- builtin/provisioners/chef/linux_provisioner_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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{