##################################################
# Generated by phansible.com
##################################################

# Check to determine whether we're on a windows or linux/os-x host,
# later on we use this to launch ansible in the supported way
# source: https://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
def which(cmd)
    exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
    ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
        exts.each { |ext|
            exe = File.join(path, "#{cmd}#{ext}")
            return exe if File.executable? exe
        }
    end
    return nil
end

Vagrant.configure("2") do |config|

    config.vm.provider :virtualbox do |v|
        v.name = "practicalneo4j-php"
        v.customize ["modifyvm", :id, "--memory", 512]
    end

    config.vm.box = "ubuntu/trusty64"

    config.vm.network :private_network, ip: "192.168.34.101"
    config.ssh.forward_agent = true

    #############################################################
    # Ansible provisioning (you need to have ansible installed)
    #############################################################

    if which('ansible-playbook')
        config.vm.provision "ansible" do |ansible|
            ansible.playbook = "ansible/playbook.yml"
            ansible.inventory_path = "ansible/inventories/dev"
            ansible.verbose = 'v'
            ansible.limit = 'phansible-web'
        end
    else
        config.vm.provision :shell, path: "ansible/windows.sh"
    end

    config.vm.synced_folder "./", "/vagrant", id: "vagrant-root",
        :nfs => false,
        owner: "vagrant",
        group: "www-data",
        mount_options: ["dmode=755,fmode=664"]
end
