python - Updating .bashrc and environment variables during Vagrant provisioning -
python - Updating .bashrc and environment variables during Vagrant provisioning -
i'm using vagrant set box python, pip, virtualenv, virtualenvwrapper , requirements. provisioning shell script adds the required lines virtualenvwrapper .bashrc
. basic check they're not there, doesn't duplicate them every provision:
if ! grep -fq "workon_home" /home/vagrant/.bashrc; echo 'export workon_home=/home/vagrant/.virtualenvs' >> /home/vagrant/.bashrc echo 'export project_home=/home/vagrant/devel' >> /home/vagrant/.bashrc echo 'source /usr/local/bin/virtualenvwrapper.sh' >> /home/vagrant/.bashrc source /home/vagrant/.bashrc fi
that seems work fine; after provisioning finished, lines in .bashrc
, , can ssh box , utilize virtualenvwrapper.
however, virtualenvwrapper doesn't work during provisioning. after section above, next checks pip requirements file , tries install virtualenvwrapper:
if [[ -f /vagrant/requirements.txt ]]; mkvirtualenv 'myvirtualenv' -r /vagrant/requirements.txt fi
but generates:
==> default: /tmp/vagrant-shell: line 50: mkvirtualenv: command not found
if seek , echo $workon_home
shell script, nil appears.
what missing have environment variables available, virtualenvwrapper run?
update: farther attempts... seems doing source /home/vagrant/.bashrc
has no effect in shell script - can set echo "hello"
in .bashrc
file , , isn't output during provisioning (but if run source /home/vagrant/.bashrc
when logged in.
i've tried su -c "source /home/vagrant/.bashrc" vagrant
in shell script no different.
update 2: removed $bashrc_path
variable, confusing issue.
update 3: in another question got reply why source /home/vagrant/.bashrc
wasn't working: first part of .bashrc
file prevented doing when run "not interactively" in way.
the vagrant script provisioner run root, it's home dir (~) /root. in script if define bashrc_path=/home/vagrant, believe steps work: appending to, sourcing /home/vagrant/.bashrc.
update:
scratching before thought ^^ because bashrc_path set correctly.
as alternative utilize .profile or .bash_profile. here's simplified illustration sets environment variable foo, making available during provisioning , after ssh login:
vagrantfile
vagrant.configure(2) |config| config.vm.box = "hashicorp/precise32" $prov_script = <<script if ! grep -q "export foo" /home/vagrant/.profile; sudo echo "export foo=bar" >> /home/vagrant/.profile echo "before source, foo=$foo" source /home/vagrant/.profile echo "after source, foo=$foo" fi script config.vm.provision "shell", inline: $prov_script end
results
$ vagrant ... ==> default: running provisioner: shell... default: running: inline script ==> default: before source, foo= ==> default: after source, foo=bar $ vagrant ssh -c 'echo $foo' bar $ vagrant ssh -c 'tail -n 1 ~/.profile' export foo=bar
python shell vagrant virtualenvwrapper
Comments
Post a Comment