Conditions
- Vagrant 2.0.1
- Vagrant Box: ubuntu/xenial64
- Provisioning: ansible
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.box_download_insecure = true
config.vm.define "foobar"
config.vm.provider "virtualbox" do |provider|
provider.name = "foobar"
provider.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ]
end
config.vm.network "private_network", ip: "192.168.5.4"
config.vm.hostname = "foobar.dev"
config.hostsupdater.aliases = ["pma.foobar.dev","readis.foobar.dev"]
config.vm.synced_folder ".", "/vagrant", type: "nfs"
config.vm.provision "Installing 'vagrant'", type: "ansible_local" do |provisioner|
provisioner.playbook = "/vagrant/env/ansible/install-vagrant.yml"
provisioner.inventory_path = "/vagrant/env/ansible/inv/integration/hosts"
provisioner.limit = "localhost"
end
end
Problem
As one can see I have 3 nginx hosts running on my guest. I symlinked these 3 separate configs (enabled-sites) from the guest system into my host system with ansible which will be equal to
sudo ln -s /vagrant/path/to/dist.conf /etc/nginx/sites-enabled/dist.conf
When I first vagrant up
my Box the sites are reachable, because at the end of the provisioning I restart the nginx
service. But as soon I halt the box and up it again, the sites are not reachable, but the nginx
service is running. I can then restart the nginx
service on the shell and everything works fine then.
Reason
I found out that at the time the nginx
service starts the synced /vagrant
folder has not been mounted. The nginx
service still starts properly regardless if the symlinked configs can be resolved or not.
Question
I could setup a provision shell script running always which restarts the nginx
service on every vagrant up
. But this is not the solution I'm looking for.
Is there a way to handle a trigger in the guest system as soon the /vagrant
folder has been mounted? I can imagine there's some sort of xyz.d
folder I can put scripts inside which will be executed with all necessary arguments to identify the vagrant mount.
Edit (2018-04-25)
I don't want to rely on Vagrant's mechanisms like plugins or further provisioning scripts. I recently changed from provisioning shell scripts to Ansible while I want to use the same provisioning for Docker or other deployment mechanisms. And I could imagine the same problem with the mount in Docker.
Edit (2018-04-27)
Launching services after Vagrant mount
I found this article of @razius having exactly the same problem. The solution is not up to date and I got the hint to look for a systemd
equivalent of his solution. But I'm not familiar with it. So may one can help me with.