Jeff Hu Jeff Hu - 1 year ago 85
Bash Question

Automating tasks after vagrant ssh

Wondering if it is possible to automatically run a script or execute a command ONLY after

vagrant ssh
into the box? I understand that Ansible can provide beforehand installation and set up. But it failed to allow doing things automatically after entering the machine.

I am currently create a file
. The file will be provided to the vagrant via Ansible. After I
vagrant ssh
into the box, I do
to run the script. Is there better way?

Any suggestion would be more appreciated.

Answer Source

Two ways to achieve this,

Say assume your script is in vagrant home directory like,


1) Run command along with ssh

1a) vagrant ssh -- -t '/home/vagrant/; /bin/bash'


1b) vagrant ssh -c '/home/vagrant/; /bin/bash'

2) Append complete script path in ~/.bashrc file (this should be in vagrant home directory if you are login as user vagrant)

:~$echo '. /home/vagrant/' >> ~/.bashrc
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download