emyl / vagrant-triggers

Allow the definition of arbitrary scripts that will run on the host before and/or after Vagrant commands.
MIT License
546 stars 35 forks source link

run_remote via triggers for user other than root #80

Closed anujsrc closed 6 years ago

anujsrc commented 7 years ago

Environment

Issue

Trying to run a script under /vagrant that is owned by the ubuntu user. Also, there are additional environment settings including password-less SSH for ubuntu user. Triggers are fired via root user that may not get those environment variables and other SSH settings of ubuntu user hence the script fails to execute due to component level errors but the trigger does get fired correctly.

Query

Is there a way to run the triggers as a specific user?

anujsrc commented 7 years ago

Currently, I am using the run directive to achieve this-

 run "ssh -F vagrant-ssh default '/vagrant/start.sh'"

where, vagrant-ssh is vagrant ssh config-

vagrant ssh-config > vagrant-ssh

or simply

run "ssh -i ./.vagrant/machines/default/virtualbox/private_key ubuntu@172.21.1.11 '/vagrant/start.sh'"

If there is a better way, do let me know. Thanks.

marcrohloff commented 7 years ago

I agree it would be nice to have this as an option to run_remote. I used

run_remote 'sudo -u vagrant -H /vagrant/start,sh'

You should be able to use

run 'vagrant ssh -c /vagrant/start.sh'