devopsgroup-io / vagrant-digitalocean

:droplet: A Vagrant provider plugin that manages DigitalOcean droplets.
Mozilla Public License 2.0
1.71k stars 182 forks source link

Use "privileged: false" for shell scripts? #174

Open soulgalore opened 9 years ago

soulgalore commented 9 years ago

Hi Shawn, first, thanks for the great work with the provider!

I have a problem, I'm deploying a Ubuntu box that uses two shell scripts as provisioner. One can run as root, the other needs to have normal privilege. In my Vagrantfile it looks like this (it install packages using npm): config.vm.provision :shell, :path => "setup-nodejs.sh", privileged: false

Running Vagrant on my own box, that script runs using the vagrant user, but on DigitalOcean root runs it (and gives me an error). Do you know any best practice how I should handle it?

Best Peter

hamiltont commented 9 years ago

@soulgalore In case you don't know about it, here is one "hacky" way to overcome this. Naturally, if anyone knows a method that relies solely on the ruby that's preferred

# Put this at the top of your provision script
# to run the remainder of the script as "someuser"
sudo -u someuser -H bash << EOF

# Put your current script commands here

EOF
hamiltont commented 9 years ago

Huh, found an unexpected solution. Doing this causes the provision to happen as the user setup using override.ssh.username

$ vagrant up --provider digital_ocean --no-provision
$ vagrant provision
valzav commented 9 years ago

bump

baderas commented 8 years ago

What information is needed?

If you use the example in the first post in a Vagrantfile, the command should be run with vagrant and not with root as user.

privileged: false -> executed as vagrant privileged: true -> executed as root (default if privileged is omitted)

vagrant-digitalocean simply ignores the privileged setting and executed everything as root.

hamiltont's examples are just workarounds.

christopherraa commented 8 years ago

Same bug here. Vagrant 1.8.1 and vagrant-digitalocean 0.9.0.