i am sysadmin, so you are in luck.

when you do vagrant ssh you get in as vagrant

but the shell provisioner run as root by default,

option 1, the clean one:


   -

   privileged (boolean) - Specifies whether to execute the shell script as
   a privileged user or not (sudo). By default this is "true". This has no
   effect for Windows guests.

add privileged=0 to the shell provider.


option 2, ugly one.
create an script, leave in the same path as the Vagrantfile is

so in the guest, that file will be at /vagrant/script.sh

then in your shell provider use something like

su - vagrant -c 'sh /vagrant/script.sh'

i document this, in case you want to use any other user other than
vagrant..

Alvaro.


On Fri, May 23, 2014 at 10:28 PM, Alberto Negron <[email protected]>wrote:

> Hi Alvaro,
>
> thanks for your reply - it does not print out anything to the console but
> I managed to pull out this:
>
> ==> default: ldconfig deferred processing now taking place
>
> ==> default: Cloning into '/root/.rbenv'...
>
> ==> default: Cloning into '/root/.rbenv/plugins/ruby-build'...
>
> so the cloning is in the root folder.... any idea on how can move this to
> /home/vagrant? I am not a sysadmin so not sure if this path exists at this
> point.
>
>
> This is the bit I need to modify - but hardcoding /home/vagrant does look
> like the right - any thoughts?
>
>
> git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
>
> touch ~/.bash_profile
>
> echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
>
> echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
>
> source ~/.bash_profile
>
>
> # Install Ruby 2.1.0
>
> git clone 
> https://github.com/sstephenson/ruby-build.git~/.rbenv/plugins/ruby-build
>
> cd ~/.rbenv/plugins/ruby-build
>
> sudo ./install.sh
>
> rbenv install 2.1.0
>
> rbenv rehash
>
> rbenv global 2.1.0
>
> On Thursday, May 22, 2014 10:28:28 PM UTC+1, Alvaro Miranda Aguilera wrote:
>>
>> I am under the impression that if youare using the shell provisioner all
>> that magic will happen under root user
>>
>> can you put some dummy things like
>>
>> id
>> pwd
>> echo $HOME
>>
>> to be sure path/user?
>>
>>
>>
>> On Fri, May 23, 2014 at 8:27 AM, Alberto Negron <[email protected]>wrote:
>>
>>> Hello Everyone,
>>>
>>> I have shell script that I use when I vagrant-up an Ubuntu precise64 box
>>> - The script runs updates and also install packages required for rbenv,
>>> ruby and rails - The script seems to run fine but when I ssh into the box I
>>> cannot find  the rbenv git. repo nor a custom .bash_profile I created
>>> during provision.
>>>
>>> This is an extract from my script that is somehow missing in action:
>>>
>>> git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
>>> touch ~/.bash_profile
>>> echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
>>> echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
>>> source ~/.bash_profile
>>>
>>> and when I ssh and check my vagrant home directory there is no repo nor
>>> .bash_profile :-s.
>>>
>>> vagrant@precise64:~$ ls -a
>>>
>>> .   .bash_history   .cache     .profile  .sudo_as_admin_successful
>>> .veewee_version
>>>
>>> ..  .bash_logout   .bashrc        postinstall.sh  .ssh
>>> .vbox_version
>>>
>>> I'd have expected to see ~/.rbenv and ~/.bash_profile
>>>
>>> vagrant@precise64:~$ which rbenv
>>>
>>> vagrant@precise64:~$ source ~/.bash_profile
>>>
>>> The program 'rbenv' is currently not installed.  You can install it by
>>> typing:
>>>
>>> sudo apt-get install rbenv
>>>
>>> The above error is clearly because it can find the ~/.rbenv folder.
>>>
>>> *How do I know that my scripts run ok?*
>>>
>>> Well  apart from no apparent errors here there are last few lines where
>>> anyone can see that rails has been installed
>>>
>>> ==> default: Installing ri documentation for tzinfo-1.1.0
>>>
>>> ==> default: Done installing documentation for actionmailer, actionpack,
>>> actionview, activemodel, activerecord, activesupport, arel, builder,
>>> erubis, hike, i18n, mail, mime-types, minitest, multi_json, polyglot, rack,
>>> rack-test, rails, railties, sprockets, sprockets-rails, thor, thread_safe,
>>> tilt, treetop, tzinfo after 420 seconds
>>>
>>> ==> default: 27 gems installed
>>>
>>> I've done it manually before and it works like a charm but I'd like to
>>> do it automatically.
>>>
>>> Any ideas? what am I missing?
>>>
>>> Many thanks in advance!
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Vagrant" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to