Vagrant / Ansible config: change to /vagrant on login

This post is more than 18 months old. Since technology changes to rapidly, this content may be out of date (but that's not always the case). Please remember to verify any technical or programming information with the current release.

While those familiar with the specifics of linux and bash are probably very familiar with the various login sequence files, this might help someone!

If you’d like to save some keystrokes after a vagrant ssh - you might want to add this line to your ansible config. This will automatically change directory to the /vagrant folder when you log in.

tasks:
  - name: Create redirect for bash login
    lineinfile: 
      dest=/home/vagrant/.bash_login 
      line="cd /vagrant" 
      state=present 
      create=yes

This simply puts a .bash_login file in the vagrant user home directory with one line: to change to the /vagrant directory.

You could make this even more dynamic by making the mapped folder root in vagrant a variable, and then pass that to the ansible extra_vars if you wanted.

Return to All Posts