An Apache based Vagrant configuration for helping you get the most out of WordPress Development.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 

238 lines
10 KiB

  1. # Note: much of the documentation and code in this file is from Varying Vagrant Vagrants, the original base for this project
  2. vagrant_dir = File.expand_path(File.dirname(__FILE__))
  3. Vagrant.configure("2") do |root|
  4. root.vm.define 'Primary Vagrant' do |config|
  5. # Store the current version of Vagrant for use in conditionals when dealing
  6. # with possible backward compatible issues.
  7. vagrant_version = Vagrant::VERSION.sub(/^v/, '')
  8. # Default Ubuntu Box
  9. #
  10. # This box is provided directly by Bento and is updated regularly.
  11. config.vm.box = "bento/ubuntu-16.04"
  12. config.vm.hostname = "pv"
  13. # Default Box IP Address
  14. #
  15. # This is the IP address that your host will communicate to the guest through. In the
  16. # case of the default `192.168.56.101` that we've provided, Virtualbox will setup another
  17. # network adapter on your host machine with the IP `192.168.13.1` as a gateway.
  18. #
  19. # If you are already on a network using the 192.168.13.x subnet, this should be changed.
  20. # If you are running more than one VM through Virtualbox, different subnets should be used
  21. # for those as well. This includes other Vagrant boxes.
  22. machineIP = '192.168.13.101'
  23. config.vm.network :private_network, id: "pv_primary", ip: machineIP
  24. # Local Machine Hosts
  25. #
  26. # If the Vagrant plugin Ghost (https://github.com/10up/vagrant-ghost) is
  27. # installed, the following will automatically configure your local machine's hosts file to
  28. # be aware of the domains specified below. Watch the provisioning script as you may need to
  29. # enter a password for Vagrant to access your hosts file.
  30. #
  31. # By default, we'll include the domains set up by Primary Vagrant through the pv-hosts file
  32. # located in the default-sites/ directory.
  33. #
  34. # Other domains can be automatically added by including a pv-hosts file containing
  35. # individual domains separated by whitespace in subdirectories of user-data/ and user-date/sites/.
  36. unless Vagrant.has_plugin?("landrush")
  37. if defined?(VagrantPlugins::Ghost)
  38. # Recursively fetch the paths to all pv-hosts files under the default-sites/, user-data/ and user-data/sites/ directories.
  39. paths = Dir[File.join(vagrant_dir, 'default-sites', 'pv-hosts')] + Dir[File.join(vagrant_dir, 'user-data', 'pv-hosts')]+ Dir[File.join(vagrant_dir, 'user-data', 'sites', '**', 'pv-hosts')]
  40. # Parse the found pv-hosts files for host names.
  41. hosts = paths.map do |path|
  42. # Read line from file and remove line breaks
  43. lines = File.readlines(path).map(&:chomp)
  44. # Filter out comments starting with "#"
  45. lines.grep(/\A[^#]/)
  46. end.flatten.uniq # Remove duplicate entries
  47. # Pass the found host names to the ghost plugin so it can perform magic.
  48. config.ghost.hosts = hosts
  49. end
  50. end
  51. # If We have Landrush use it to set the toplevel to pv.
  52. # The use of landrush will override all custom domains set and all sites and projects will simply revert to the "pv" toplevel.
  53. if Vagrant.has_plugin?("landrush")
  54. config.landrush.enabled = true
  55. config.landrush.tld = 'pv'
  56. end
  57. # Forward Agent
  58. #
  59. # Enable agent forwarding on vagrant ssh commands. This allows you to use identities
  60. # established on the host machine inside the guest. See the manual for ssh-add
  61. config.ssh.forward_agent = true
  62. # Configurations from 1.0.x can be placed in Vagrant 1.1.x specs like the following.
  63. config.vm.provider :virtualbox do |v|
  64. v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
  65. v.customize ["modifyvm", :id, "--memory", 1024]
  66. v.customize ["modifyvm", :id, "--name", "Primary Vagrant"]
  67. v.customize ["modifyvm", :id, "--cpus", 1]
  68. v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
  69. # set auto_update to false, if you do NOT want to check the correct
  70. # additions version when booting this machine
  71. if Vagrant.has_plugin?("vagrant-vbguest")
  72. config.vbguest.auto_update = true
  73. end
  74. end
  75. # Don't check for updates with every vagrant up
  76. config.vm.box_check_update = false
  77. # Drive mapping
  78. #
  79. # The following config.vm.share_folder settings will map directories in your Vagrant
  80. # virtual machine to directories on your local machine. Once these are mapped, any
  81. # changes made to the files in these directories will affect both the local and virtual
  82. # machine versions. Think of it as two different ways to access the same file. When the
  83. # virtual machine is destroyed with `vagrant destroy`, your files will remain in your local
  84. # environment.
  85. # Custom Mappings
  86. #
  87. # Use this to insert your own (and possibly rewrite) Vagrant config lines. Helpful
  88. # for mapping additional drives. If a file 'pv-mappings' exists in the user-data/ folder or user-data/sites or any of its subfolders
  89. # it will be evaluated as ruby inline as it loads.
  90. if File.exists?(File.join(vagrant_dir,'user-data', 'pv-mappings')) then
  91. eval(IO.read(File.join(vagrant_dir, 'user-data', 'pv-mappings')), binding)
  92. end
  93. Dir[File.join( vagrant_dir, 'user-data', 'sites', '**', 'pv-mappings')].each do |file|
  94. eval(IO.read(file), binding)
  95. end
  96. eval(IO.read(File.join(vagrant_dir, 'default-sites', 'pv-mappings')), binding)
  97. # Provisioning
  98. #
  99. # Process one or more provisioning scripts depending on the existence of custom files.
  100. # Prevents stdin error for Ubuntu
  101. config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"
  102. # Make sure puppet is on the box
  103. config.vm.provision "shell",
  104. inline: "apt-get update -qy && apt-get install -qy software-properties-common puppet"
  105. # Run the system setup on the first vagrant up.
  106. config.vm.provision "puppet" do |puppet|
  107. puppet.manifests_path = "provision"
  108. puppet.manifest_file = "manifests"
  109. puppet.module_path = "provision/modules"
  110. puppet.facter = { "fqdn" => "pv" }
  111. puppet.hiera_config_path = "provision/hiera.yaml"
  112. end
  113. # Run provisioning required every time we startup the box.
  114. config.vm.provision "puppet", run: "always" do |puppet|
  115. puppet.manifests_path = "user-data/"
  116. puppet.manifest_file = "vhosts"
  117. puppet.module_path = "provision/modules"
  118. puppet.facter = { "fqdn" => "pv" }
  119. puppet.hiera_config_path = "provision/hiera.yaml"
  120. end
  121. # Vagrant Triggers
  122. #
  123. # If the vagrant-triggers plugin is installed, we can run various scripts on Vagrant
  124. # state changes like `vagrant up`, `vagrant halt`, `vagrant suspend`, and `vagrant destroy`
  125. #
  126. # These scripts are run on the host machine, so we use `vagrant ssh` to tunnel back
  127. # into the VM and execute things. By default, each of these scripts calls db_backup
  128. # to create backups of all current databases. This can be overridden with custom
  129. # scripting. See the individual files in provision/lib/bin for details.
  130. if defined? VagrantPlugins::Triggers
  131. config.trigger.before :up do
  132. system('./provision/lib/bin/vagrant_init.sh')
  133. if File.exists?(File.join(vagrant_dir,'user-data', 'pv-init.sh')) then
  134. system('./user-data/pv-init.sh')
  135. end
  136. Dir[File.join( 'user-data/sites', '**', 'pv-init.sh')].each do |file|
  137. print file
  138. system(file)
  139. end
  140. end
  141. config.trigger.before :halt do
  142. run_remote "bash /vagrant/provision/lib/bin/vagrant_halt.sh"
  143. if File.exists?(File.join(vagrant_dir,'user-data', 'pv-halt.sh')) then
  144. system('./user-data/pv-halt.sh')
  145. end
  146. Dir[File.join( 'user-data/sites', '**', 'pv-halt.sh')].each do |file|
  147. print file
  148. system(file)
  149. end
  150. end
  151. config.trigger.before :suspend do
  152. run_remote "bash /vagrant/provision/lib/bin/vagrant_suspend.sh"
  153. if File.exists?(File.join(vagrant_dir,'user-data', 'pv-suspend.sh')) then
  154. system('./user-data/pv-suspend.sh')
  155. end
  156. Dir[File.join( 'user-data/sites', '**', 'pv-suspend.sh')].each do |file|
  157. print file
  158. system(file)
  159. end
  160. end
  161. config.trigger.before :destroy do
  162. if File.exists?(File.join(vagrant_dir,'user-data', 'pv-destroy.sh')) then
  163. system('./user-data/pv-destroy.sh')
  164. end
  165. Dir[File.join( 'user-data/sites', '**', 'pv-destroy.sh')].each do |file|
  166. print file
  167. system(file)
  168. end
  169. end
  170. end
  171. # Idea thanks to VVV.
  172. puts "";
  173. puts "\033[38;5;196m================================================"
  174. puts "\033[38;5;33m _____ _"
  175. puts "\033[38;5;33m| __ \\ (_)"
  176. puts "\033[38;5;33m| |__) | __ _ _ __ ___ __ _ _ __ _ _"
  177. puts "\033[38;5;33m| ___/ '__| | '_ ` _ \\ / _` | '__| | | |"
  178. puts "\033[38;5;33m| | | | | | | | | | | (_| | | | |_| |"
  179. puts "\033[38;5;33m|_| |_| |_|_| |_| |_|\\__,_|_| \\__, |"
  180. puts "\033[38;5;33m __/ |"
  181. puts "\033[38;5;33m |___/"
  182. puts "\033[38;5;118m__ __ _"
  183. puts "\033[38;5;118m\\ \\ / / | |"
  184. puts "\033[38;5;118m \\ \\ / /_ _ __ _ _ __ __ _ _ __ | |_"
  185. puts "\033[38;5;118m \\ \\/ / _` |/ _` | '__/ _` | '_ \\| __|"
  186. puts "\033[38;5;118m \\ / (_| | (_| | | | (_| | | | | |_"
  187. puts "\033[38;5;118m \\/ \\__,_|\\__, |_| \\__,_|_| |_|\\__|"
  188. puts "\033[38;5;118m __/ |"
  189. puts "\033[38;5;118m |___/"
  190. puts "\033[38;5;196m================================================"
  191. puts ""
  192. puts " \033[38;5;80mPrimary Vagrant: \033[38;5;118m4.6.1"
  193. puts ""
  194. puts " \033[38;5;80mDocs: \033[38;5;220mhttps://github.com/ChrisWiegman/Primary-Vagrant/wiki"
  195. puts ""
  196. puts ""
  197. puts "\033[0m"
  198. config.vm.post_up_message="\033[38;5;118mPrimary Vagrant is ready. Happy developing!"
  199. end
  200. end