Advertisement
Guest User

Vagrant + Parallels Desktop

a guest
Aug 28th, 2015
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.97 KB | None | 0 0
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3.  
  4. # Specify Vagrant provider as Virtualbox
  5. ENV['VAGRANT_DEFAULT_PROVIDER'] = 'parallels'
  6.  
  7. require 'yaml'
  8.  
  9. ANSIBLE_PATH = __dir__ # absolute path to Ansible directory
  10.  
  11. # Set Ansible roles_path relative to Ansible directory
  12. ENV['ANSIBLE_ROLES_PATH'] = File.join(ANSIBLE_PATH, 'vendor', 'roles')
  13.  
  14. config_file = File.join(ANSIBLE_PATH, 'group_vars/development/wordpress_sites.yml')
  15.  
  16. if File.exists?(config_file)
  17.   wordpress_sites = YAML.load_file(config_file)['wordpress_sites']
  18.   raise "no sites found in #{config_file}" if wordpress_sites.to_h.empty?
  19. else
  20.   raise "#{config_file} file not found. Please set `ANSIBLE_PATH` in Vagrantfile"
  21. end
  22.  
  23. Vagrant.require_version '>= 1.5.1'
  24.  
  25. Vagrant.configure('2') do |config|
  26.   config.vm.box = 'fza/trusty64'
  27.   config.ssh.forward_agent = true
  28.  
  29.   # Required for NFS to work, pick any local IP
  30.   config.vm.network :private_network, ip: '192.168.50.5'
  31.  
  32.   hostname, *aliases = wordpress_sites.flat_map { |(_name, site)| site['site_hosts'] }
  33.   config.vm.hostname = hostname
  34.   www_aliases = ["www.#{hostname}"] + aliases.map { |host| "www.#{host}" }
  35.  
  36.   if Vagrant.has_plugin? 'vagrant-hostsupdater'
  37.     config.hostsupdater.aliases = aliases + www_aliases
  38.   else
  39.     puts 'vagrant-hostsupdater missing, please install the plugin:'
  40.     puts 'vagrant plugin install vagrant-hostsupdater'
  41.   end
  42.  
  43.   if Vagrant::Util::Platform.windows?
  44.     wordpress_sites.each do |(name, site)|
  45.       config.vm.synced_folder local_site_path(site), remote_site_path(name), owner: 'vagrant', group: 'www-data', mount_options: ['dmode=776', 'fmode=775']
  46.     end
  47.   else
  48.     if !Vagrant.has_plugin? 'vagrant-bindfs'
  49.       raise Vagrant::Errors::VagrantError.new,
  50.         "vagrant-bindfs missing, please install the plugin:\nvagrant plugin install vagrant-bindfs"
  51.     else
  52.       wordpress_sites.each do |(name, site)|
  53.         config.vm.synced_folder local_site_path(site), nfs_path(name), type: 'nfs'
  54.         config.bindfs.bind_folder nfs_path(name), remote_site_path(name), u: 'vagrant', g: 'www-data'
  55.       end
  56.     end
  57.   end
  58.  
  59.   if Vagrant::Util::Platform.windows?
  60.     config.vm.provision :shell do |sh|
  61.       sh.path = File.join(ANSIBLE_PATH, 'windows.sh')
  62.     end
  63.   else
  64.     config.vm.provision :ansible do |ansible|
  65.       ansible.playbook = File.join(ANSIBLE_PATH, 'dev.yml')
  66.       ansible.groups = {
  67.         'web' => ['default'],
  68.         'development' => ['default']
  69.       }
  70.  
  71.       if vars = ENV['ANSIBLE_VARS']
  72.         extra_vars = Hash[vars.split(',').map { |pair| pair.split('=') }]
  73.         ansible.extra_vars = extra_vars
  74.       end
  75.     end
  76.   end
  77.  
  78.   config.vm.provider "parallels" do |prl|
  79.     prl.name = "project-name"
  80.     prl.memory = 1024
  81.     prl.cpus = 2
  82.   end
  83. end
  84.  
  85. def local_site_path(site)
  86.   File.expand_path(site['local_path'], ANSIBLE_PATH)
  87. end
  88.  
  89. def nfs_path(site_name)
  90.   "/vagrant-nfs-#{site_name}"
  91. end
  92.  
  93. def remote_site_path(site_name)
  94.   File.join('/srv/www/', site_name, 'current')
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement