2 thoughts on “How can I run a script on the host, after all the vms are up?”

  1. This will only run on initial vagrant up (creation of the VM). If you mess up, you will have to vagrant destroy to run the provisioning again.

    Vagrantfile

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

    Vagrant.configure(“2”) do |config|
    config.vm.box = “bento/centos-7.6”
    config.vm.hostname = “yourhostname”
    config.vm.network “forwarded_port”, guest: 80, host: 8080
    config.vm.network “private_network”, ip: “192.168.33.10”
    config.vm.synced_folder “.”, “/var/www”, :nfs => { :mount_options => [“dmode=777″,”fmode=666”] }
    config.ssh.insert_key = false
    config.vm.provision “shell”, path: “install.sh”, privileged: false
    end

    [install.sh](https://install.sh)

    #!/bin/bash

    #whatever your heart desires
    sudo yum update

    Reply
  2. If you want to run a script on the host then you could use vagrant triggers, they were introduced in vagrant ver-2.1.0

    You could do something like this;
    “`
    Vagrant.configure(“2”) do |config|
    config.trigger.after :up do |trigger|
    trigger.run = {path: path/to/script.sh}
    end

    Machine definitions starts here
    “`
    This would run your script after all the machines are up

    Reply

Leave a Comment