Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- mode: ruby -*-
- # vi: set ft=ruby :
- # Specify Vagrant provider as Virtualbox
- ENV['VAGRANT_DEFAULT_PROVIDER'] = 'parallels'
- require 'yaml'
- ANSIBLE_PATH = __dir__ # absolute path to Ansible directory
- # Set Ansible roles_path relative to Ansible directory
- ENV['ANSIBLE_ROLES_PATH'] = File.join(ANSIBLE_PATH, 'vendor', 'roles')
- config_file = File.join(ANSIBLE_PATH, 'group_vars/development/wordpress_sites.yml')
- if File.exists?(config_file)
- wordpress_sites = YAML.load_file(config_file)['wordpress_sites']
- raise "no sites found in #{config_file}" if wordpress_sites.to_h.empty?
- else
- raise "#{config_file} file not found. Please set `ANSIBLE_PATH` in Vagrantfile"
- end
- Vagrant.require_version '>= 1.5.1'
- Vagrant.configure('2') do |config|
- config.vm.box = 'fza/trusty64'
- config.ssh.forward_agent = true
- # Required for NFS to work, pick any local IP
- config.vm.network :private_network, ip: '192.168.50.5'
- hostname, *aliases = wordpress_sites.flat_map { |(_name, site)| site['site_hosts'] }
- config.vm.hostname = hostname
- www_aliases = ["www.#{hostname}"] + aliases.map { |host| "www.#{host}" }
- if Vagrant.has_plugin? 'vagrant-hostsupdater'
- config.hostsupdater.aliases = aliases + www_aliases
- else
- puts 'vagrant-hostsupdater missing, please install the plugin:'
- puts 'vagrant plugin install vagrant-hostsupdater'
- end
- if Vagrant::Util::Platform.windows?
- wordpress_sites.each do |(name, site)|
- config.vm.synced_folder local_site_path(site), remote_site_path(name), owner: 'vagrant', group: 'www-data', mount_options: ['dmode=776', 'fmode=775']
- end
- else
- if !Vagrant.has_plugin? 'vagrant-bindfs'
- raise Vagrant::Errors::VagrantError.new,
- "vagrant-bindfs missing, please install the plugin:\nvagrant plugin install vagrant-bindfs"
- else
- wordpress_sites.each do |(name, site)|
- config.vm.synced_folder local_site_path(site), nfs_path(name), type: 'nfs'
- config.bindfs.bind_folder nfs_path(name), remote_site_path(name), u: 'vagrant', g: 'www-data'
- end
- end
- end
- if Vagrant::Util::Platform.windows?
- config.vm.provision :shell do |sh|
- sh.path = File.join(ANSIBLE_PATH, 'windows.sh')
- end
- else
- config.vm.provision :ansible do |ansible|
- ansible.playbook = File.join(ANSIBLE_PATH, 'dev.yml')
- ansible.groups = {
- 'web' => ['default'],
- 'development' => ['default']
- }
- if vars = ENV['ANSIBLE_VARS']
- extra_vars = Hash[vars.split(',').map { |pair| pair.split('=') }]
- ansible.extra_vars = extra_vars
- end
- end
- end
- config.vm.provider "parallels" do |prl|
- prl.name = "project-name"
- prl.memory = 1024
- prl.cpus = 2
- end
- end
- def local_site_path(site)
- File.expand_path(site['local_path'], ANSIBLE_PATH)
- end
- def nfs_path(site_name)
- "/vagrant-nfs-#{site_name}"
- end
- def remote_site_path(site_name)
- File.join('/srv/www/', site_name, 'current')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement