Vagrant: Ability to run file provisioner in sudo mode

Created on 13 Jun 2014  ยท  4Comments  ยท  Source: hashicorp/vagrant

Would be great to have a sudo mode for the file provisioner to copy files to certain locations that are owned by root. E.g. The /vagrant folder is owned by root on CentOS 6.5. Attempting to copy a file into that folder fails with the following:

Failed to upload a file to the guest VM via SCP due to a permissions
error. This is normally because the SSH user doesn't have permission
to write to the destination location. Alternately, the user running
Vagrant on the host machine may not have permission to read the file.

Most helpful comment

I ran into the same issue where I needed to copy the .dockercfg file to root. Thanks for the suggestion, I got it working with this:

c.vm.provision "file", source: Dir.getwd + "/keys/.dockercfg", destination: "~/.dockercfg"

c.vm.provision "shell" do |s|
  s.inline = "apt-get update -y; DEBIAN_FRONTEND=noninteractive apt-get install docker.io mysql-server -y; cp /home/vagrant/.dockercfg /root/.dockercfg"
  s.privileged = true
end

All 4 comments

The file provisioner uses SCP, which doesn't have a sudo mode exactly, since it connects via the SSH user. We recommend you just use the file provisioner to copy to a temp folder, then the shell provsiioner to copy.

I ran into the same issue where I needed to copy the .dockercfg file to root. Thanks for the suggestion, I got it working with this:

c.vm.provision "file", source: Dir.getwd + "/keys/.dockercfg", destination: "~/.dockercfg"

c.vm.provision "shell" do |s|
  s.inline = "apt-get update -y; DEBIAN_FRONTEND=noninteractive apt-get install docker.io mysql-server -y; cp /home/vagrant/.dockercfg /root/.dockercfg"
  s.privileged = true
end

Being bite by this, provision job has not enough permission feature, I really think the solution above is ugly. Anyone agree with me?

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lebogan picture lebogan  ยท  3Comments

bbaassssiiee picture bbaassssiiee  ยท  3Comments

janw-me picture janw-me  ยท  3Comments

jazzfog picture jazzfog  ยท  3Comments

jsirex picture jsirex  ยท  3Comments