From 106c9403ed3d21ed16e03551b6a7783f42538180 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 15 Jun 2015 13:37:20 -0700 Subject: [PATCH 1/2] provisioner/chef-client: chmod the directories --- provisioner/chef-client/provisioner.go | 21 +++++++++++++------ .../provisioners/chef-client.html.markdown | 9 ++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/provisioner/chef-client/provisioner.go b/provisioner/chef-client/provisioner.go index b28c9e83a..527b375c1 100644 --- a/provisioner/chef-client/provisioner.go +++ b/provisioner/chef-client/provisioner.go @@ -310,16 +310,25 @@ func (p *Provisioner) createDir(ui packer.Ui, comm packer.Communicator, dir stri mkdirCmd = "sudo " + mkdirCmd } - cmd := &packer.RemoteCmd{ - Command: mkdirCmd, - } - + cmd := &packer.RemoteCmd{Command: mkdirCmd} if err := cmd.StartWithUi(comm, ui); err != nil { return err } - if cmd.ExitStatus != 0 { - return fmt.Errorf("Non-zero exit status.") + return fmt.Errorf("Non-zero exit status. See output above for more info.") + } + + // Chmod the directory to 0777 just so that we can access it as our user + mkdirCmd = fmt.Sprintf("chmod 0777 '%s'", dir) + if !p.config.PreventSudo { + mkdirCmd = "sudo " + mkdirCmd + } + cmd = &packer.RemoteCmd{Command: mkdirCmd} + if err := cmd.StartWithUi(comm, ui); err != nil { + return err + } + if cmd.ExitStatus != 0 { + return fmt.Errorf("Non-zero exit status. See output above for more info.") } return nil diff --git a/website/source/docs/provisioners/chef-client.html.markdown b/website/source/docs/provisioners/chef-client.html.markdown index eaeadbf45..22e965149 100644 --- a/website/source/docs/provisioners/chef-client.html.markdown +++ b/website/source/docs/provisioners/chef-client.html.markdown @@ -161,3 +161,12 @@ curl -L https://www.opscode.com/chef/install.sh | \ ``` This command can be customized using the `install_command` configuration. + +## Folder Permissions + +The `chef-client` provisioner will chmod the directory with your Chef +keys to 777. This is to ensure that Packer can upload and make use of that +directory. However, once the machine is created, you usually don't +want to keep these directories with those permissions. To change the +permissions on the directories, append a shell provisioner after Chef +to modify them. From 906c45266d96e1cdbbb03853c8c5c43b48e93800 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 15 Jun 2015 13:46:43 -0700 Subject: [PATCH 2/2] website: make warning for chef perms --- website/source/docs/provisioners/chef-client.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/source/docs/provisioners/chef-client.html.markdown b/website/source/docs/provisioners/chef-client.html.markdown index 22e965149..9a2a11379 100644 --- a/website/source/docs/provisioners/chef-client.html.markdown +++ b/website/source/docs/provisioners/chef-client.html.markdown @@ -164,7 +164,7 @@ This command can be customized using the `install_command` configuration. ## Folder Permissions -The `chef-client` provisioner will chmod the directory with your Chef +!> The `chef-client` provisioner will chmod the directory with your Chef keys to 777. This is to ensure that Packer can upload and make use of that directory. However, once the machine is created, you usually don't want to keep these directories with those permissions. To change the