Vagrant provision script: echo "source /root/.venvburrito/startup.sh" >> ~/.profile fails

2

1

I'm running my vagrant provisioning with a bootstrap.sh script. The script runs fine except for one line:

echo "source /root/.venvburrito/startup.sh" >> ~/.profile

This line fails. I don't get any output about it, but when I do vagrant ssh and check the ~/.profile file I can see that source /root/.venvburrito/startup.sh is not appended to the file.

How can I append source /root/.venvburrito/startup.sh to the file so that command is sourced every time I do vagrant ssh?

Bentley4

Posted 2014-02-26T11:37:59.473

Reputation: 1 588

Answers

2

The shell (and most other) provisioners are run as the root user using sudo. But for the shell provisioner you can set privileged attribute to false to run as the SSH user.

Example:

Vagrant.configure("2") do |config|
  # ...

  config.vm.provision "shell", path: "bootstrap.sh", privileged: false
end

See the documentations for more details.

tmatilai

Posted 2014-02-26T11:37:59.473

Reputation: 1 892

This does not work for me. Even when running as the SSH user, I cannot append to files using echo. The version of echo used by SSH differs from the version available on the guest OS (where it is possible to execute the command if I copy and paste it there). – 8bitjunkie – 2015-11-13T20:13:08.570

1

Running a script with vagrant provision:

#whoami
root
#echo $HOME
/root

compared to running vagrant ssh:

#whoami
vagrant
#echo $HOME
/home/vagrant

In other words, when I use ~/.profile, the ~ expands to /root in a provision script compared to when I use it after I sssh into the virtual box where it expands to /home/vagrant.

So in order to append the line to the ~/.profile file that you can access with ssh, you'd need the following line in your provision script:

echo "source /root/.venvburrito/startup.sh" >> /home/vagrant/.profile

If you use printenv you can see all the env variables set. That reveals that you could also use:

echo "source /root/.venvburrito/startup.sh" >> $PWD/.profile

Bentley4

Posted 2014-02-26T11:37:59.473

Reputation: 1 588

0

I ran into the same thing. Then I realized after reading @tmatilai's comment that it has actually set it for the root user!

You can do

sudo su -

to get to root. and there you will see your line appended to the file (in /root/.profile)

Also, instead of setting privileges as he suggested, you can use a fully qualified name instead:

echo "source /root/.venvburrito/startup.sh" >> /home/vagrant/.profile

Siddhartha

Posted 2014-02-26T11:37:59.473

Reputation: 527