Don’t use symlinks in Vagrant for config files

I’ve been building a lot of Vagrant machines lately, and I’m learning a few things to make the process easier/optimal.

One of the things I recently discovered was that you should avoid using symlinks for your config files, if you’re using a provisioner like Puppet. I had gotten into the habit of just symlinking config files like /etc/php.ini, so if I updated the file I could just reload PHP instead of running vagrant provision again (to copy over my updated file).

The problem with this approach comes when you use restart/reload your Vagrant VM. Provisioning scripts are no longer run every time the VM starts, only on the initial vagrant up. When the VM restarts, your service will try to start (Say Nginx), but it’s config files will be missing as services start before Vagrant has mounted the shared folders (Meaning your symlinks are temporarily broken). Therefore, I recommend using the source attribute instead of the target attribute with Puppet (Puppet will ensure the file contents remains the same).

One other tip (A Puppet one) is that you can recursively copy over files from a directory in Puppet, using the recurse option. See this example:

file { '/etc/nginx':
  notify => Service['nginx'],
  require => Package['nginx'],
  ensure => 'directory',
  source => '/vagrant/vagrant/puppet/nginx',
  recurse => true,

Makes it a lot easier to write provisioning scripts!

Of course, you could also create an upstart job and have it start on vagrant-mounted.

11 Replies to “Don’t use symlinks in Vagrant for config files”

  1. Qgp2adxw’)) OR 404=(SELECT 404 FROM PG_SLEEP(15))–

  2. QeBdfNiu’ OR 79=(SELECT 79 FROM PG_SLEEP(15))–

  3. -1)) OR 720=(SELECT 720 FROM PG_SLEEP(15))–

  4. -5 OR 83=(SELECT 83 FROM PG_SLEEP(15))–

  5. QCM6a6nv’; waitfor delay ‘0:0:15’ —

  6. -1; waitfor delay ‘0:0:15’ —

  7. 0’XOR(if(now()=sysdate(),sleep(15),0))XOR’Z

  8. if(now()=sysdate(),sleep(15),0)

  9. -1′ OR 3+399-399-1=0+0+0+1 —

  10. Can you give us an example?

    I build a nginx server with phuphpet/vagrant.
    now i want to move a lot of my user configs from my vm to my host.

    At the moment i did it with a mount but than i’ve got exactly that problem. I have to restart. I want to hold all files, databases, php/db & webserver configs on host, so i can provision or move the vm simply. Or should i do it with vagrant package?

    Greetings from Germany.

Leave a Reply