Alex
Alex

Reputation: 81

How do I find my synced folder when using Vagrant to host a PostgreSQL database?

As per the PostgreSQL wiki, I cloned a vagrant file preloaded with PostgreSQL onto my hard drive.

I am now trying to use that in conjunction with a .py and .sql file that I had been writing. The Vagrant documentation suggests that I should be able to cd straight into a folder called /vagrant once I have done vagrant up and vagrant ssh but whenever I try to do that, I get the following error message:

-bash: cd: /vagrant: No such file or directory

I am assuming it is something inside my Vagrantfile. The Vagrant documentation said this behaviour should happen by default, but I added in the extra line:

config.vm.synced_folder ".", "/vagrant"

But that did nothing.

So I want to know how I can access my /vagrant shared/synced folder. Can you help?

Upvotes: 2

Views: 286

Answers (1)

Frederic Henri
Frederic Henri

Reputation: 53773

The Vagrantfile from https://github.com/jackdb/pg-app-dev-vm looks a bit old and still has the version 1 syntax -

You can add the missing folder within the version 2 syntax part, so Vagrantfile like

# -*- mode: ruby -*-
# vi: set ft=ruby :

$script = <<SCRIPT
echo I am provisioning...
date > /etc/vagrant_provisioned_at
SCRIPT

Vagrant.configure("2") do |config|
  config.vm.provision "shell", inline: $script
  config.vm.synced_folder  ".", "/vagrant"
end

Vagrant::Config.run do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.box_url = "https://atlas.hashicorp.com/ubuntu/boxes/trusty64"
  config.vm.host_name = "postgresql" 

  config.vm.share_folder "bootstrap", "/mnt/bootstrap", ".", :create => true
  config.vm.provision :shell, :path => "Vagrant-setup/bootstrap.sh"

  # PostgreSQL Server port forwarding
  config.vm.forward_port 5432, 15432
end

Better would be to use version2 syntax (syntax1 is obsolete for a few years now) - the following will work

# -*- mode: ruby -*-
# vi: set ft=ruby :

$script = <<SCRIPT
echo I am provisioning...
date > /etc/vagrant_provisioned_at
SCRIPT

Vagrant.configure("2") do |config|
  config.vm.provision "shell", inline: $script

  config.vm.box = "ubuntu/trusty64"
  config.vm.box_url = "https://atlas.hashicorp.com/ubuntu/boxes/trusty64"
  config.vm.host_name = "postgresql" 

  config.vm.synced_folder  ".", "/mnt/bootstrap"

  config.vm.provision :shell, :path => "Vagrant-setup/bootstrap.sh"

  # PostgreSQL Server port forwarding
  config.vm.network "forwarded_port", guest: 5432, host: 15432
end

Using this you dont need to specify a /vagrant shared folder as you read its here by default

Upvotes: 2

Related Questions