Guest User

Untitled

a guest
Mar 1st, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. <% config[:vagrantfiles].each do |vagrantfile| %>
  2. require "<%= vagrantfile %>"
  3. <% end %>
  4.  
  5. Vagrant.configure("2") do |c|
  6. c.berkshelf.enabled = false if Vagrant.has_plugin?("vagrant-berkshelf")
  7. <% if config[:cachier] %>
  8. if Vagrant.has_plugin?("vagrant-cachier")
  9. c.cache.scope = <%= [':box', ':machine'].include?(config[:cachier]) ? config[:cachier] : ':box' %>
  10. end
  11. <% end %>
  12.  
  13. c.vm.box = "<%= config[:box] %>"
  14.  
  15. <% if config[:box_url] %>
  16. c.vm.box_url = "<%= config[:box_url] %>"
  17. <% end %>
  18.  
  19. <% if config[:box_version] %>
  20. c.vm.box_version = "<%= config[:box_version] %>"
  21. <% end %>
  22.  
  23. <% if !config[:box_check_update].nil? %>
  24. c.vm.box_check_update = <%= config[:box_check_update] %>
  25. <% end %>
  26.  
  27. <% if !config[:box_download_ca_cert].nil? %>
  28. c.vm.box_download_ca_cert = "<%= config[:box_download_ca_cert] %>"
  29. <% end %>
  30.  
  31. <% if !config[:box_download_insecure].nil? %>
  32. c.vm.box_download_insecure = "<%= config[:box_download_insecure] %>"
  33. <% end %>
  34.  
  35. <% if config[:vm_hostname] %>
  36. c.vm.hostname = "<%= @instance.name %>.<%= config[:var_domain] ? config[:var_domain] : config[:kitchen_root].split('/')[-1] %>.<%= config[:var_suffix] ? config[:var_suffix] : "vagrantup.com" %>"
  37. <% end %>
  38.  
  39. <% if config[:communicator] %>
  40. c.vm.communicator = "<%= config[:communicator] %>"
  41. <% end %>
  42.  
  43. <% if config[:guest] %>
  44. c.vm.guest = "<%= config[:guest] %>"
  45. <% end %>
  46.  
  47. <% if config[:communicator] %>
  48. <% if config[:username] %>
  49. c.<%= config[:communicator] %>.username = "<%= config[:username] %>"
  50. <% end %>
  51. <% if config[:password] %>
  52. c.<%= config[:communicator] %>.password = "<%= config[:password] %>"
  53. <% end %>
  54. <% else %>
  55. <% if config[:username] %>
  56. c.ssh.username = "<%= config[:username] %>"
  57. <% end %>
  58. <% if config[:password] %>
  59. c.ssh.password = "<%= config[:password] %>"
  60. <% end %>
  61. <% end %>
  62.  
  63. <% if config[:ssh_key] %>
  64. c.ssh.private_key_path = "<%= config[:ssh_key] %>"
  65. <% end %>
  66. <% config[:ssh].each do |key, value| %>
  67. c.ssh.<%= key %> = <%= [true, false].include?(value) ? value : value.inspect %>
  68. <% end %>
  69. <% if config[:winrm] %>
  70. <% config[:winrm].each do |key, value| %>
  71. <% if value.is_a? String %>
  72. c.winrm.<%= key %> = "<%= value%>"
  73. <% else %>
  74. c.winrm.<%= key %> = <%= value%>
  75. <% end %>
  76. <% end %>
  77. <% end %>
  78.  
  79. <% if config[:boot_timeout] %>
  80. c.vm.boot_timeout = <%= config[:boot_timeout] %>
  81. <% end %>
  82.  
  83. <% Array(config[:network]).each do |opts| %>
  84. c.vm.network(:<%= opts[0] %>, <%= opts[1..-1].join(", ") %>)
  85. <% end %>
  86.  
  87. c.vm.synced_folder ".", "/vagrant", disabled: true
  88. <% config[:synced_folders].each do |source, destination, options| %>
  89. c.vm.synced_folder <%= source.inspect %>, <%= destination.inspect %>, <%= options %>
  90. <% end %>
  91.  
  92. c.vm.provider :<%= config[:provider] %> do |p|
  93. <% case config[:provider]
  94. when "virtualbox", /^vmware_/
  95. if config[:gui] == true || config[:gui] == false %>
  96. p.gui = <%= config[:gui] %>
  97. <% end
  98. end
  99.  
  100. case config[:provider]
  101. when "virtualbox", /^vmware_/, "parallels"
  102. if config[:linked_clone] == true || config[:linked_clone] == false %>
  103. p.linked_clone = <%= config[:linked_clone] %>
  104. <% end
  105. end %>
  106.  
  107. <% config[:customize].each do |key, value| %>
  108. <% case config[:provider]
  109. when "libvirt" %>
  110. <% if key == :storage %>
  111. <% if value.is_a? String %>
  112. p.storage <%= value %>
  113. <% elsif value.is_a? Array %>
  114. <% value.each do |v| %>
  115. p.storage <%= v %>
  116. <% end %>
  117. <% end %>
  118. <% else %>
  119. <% if value.is_a? String %>
  120. p.<%= key %> = "<%= value%>"
  121. <% else %>
  122. p.<%= key %> = <%= value%>
  123. <% end %>
  124. <% end %>
  125. <% when "lxc" %>
  126. <% if key == :container_name %>
  127. p.container_name = <%= value == ":machine" ? value : "\"#{value}\"" %>
  128. <% elsif key == :backingstore %>
  129. p.backingstore = "<%= value %>"
  130. <% elsif key == :backingstore_options %>
  131. <% config[:customize][:backingstore_options].each do |opt, opt_val| %>
  132. p.backingstore_option "--<%= opt %>", "<%= opt_val %>"
  133. <% end %>
  134. <% elsif key == :include %>
  135. <% Array(value).each do |include| %>
  136. p.customize "<%= key %>", "<%= include %>"
  137. <% end %>
  138. <% else %>
  139. p.customize "<%= key %>", "<%= value %>"
  140. <% end %>
  141. <% when "managed" %>
  142. <% if key == :server %>
  143. p.server = "<%= value %>"
  144. <% end %>
  145. <% when "parallels" %>
  146. <% if key == :memory || key == :cpus %>
  147. p.<%= key %> = <%= value %>
  148. <% else %>
  149. p.customize ["set", :id, "--<%= key.to_s.gsub('_', '-') %>", "<%= value %>"]
  150. <% end %>
  151. <% when "softlayer" %>
  152. <% if key == :disk_capacity %>
  153. p.<%= key %> = <%= value %>
  154. <% else %>
  155. p.<%= key %> = "<%= value %>"
  156. <% end %>
  157. <% when "virtualbox" %>
  158. <% if key == :createhd %>
  159. <% value = [value] unless value.instance_of?(Array) %>
  160. <% value.each do |item| %>
  161. p.customize ["createhd", "--filename", "<%= item[:filename] %>", "--size", <%= item[:size] %>]
  162. <% end %>
  163. <% elsif key == :storageattach || key == :storagectl %>
  164. <% value = [value] unless value.instance_of?(Array) %>
  165. <% value.each do |item| %>
  166. <% options = [] %>
  167. <% item.each do |storage_option_key, storage_option_value|
  168. options << "\"--#{storage_option_key}\""
  169. if storage_option_value.instance_of? Fixnum
  170. options << storage_option_value
  171. else
  172. options << "\"#{storage_option_value}\""
  173. end
  174. end %>
  175. p.customize ["<%= key.to_s %>", :id, <%= options.join(', ') %>]
  176. <% end %>
  177. <% elsif key == :cpuidset %>
  178. <% ids = [] %>
  179. <% value.each do | id |
  180. ids << "\"#{id}\""
  181. end %>
  182. p.customize ["modifyvm", :id, "--cpuidset", <%= ids.join(', ') %>]
  183. <% else %>
  184. p.customize ["modifyvm", :id, "--<%= key %>", "<%= value %>"]
  185. <% end %>
  186. <% when /^vmware_/ %>
  187. <% if key == :memory %>
  188. <% unless config[:customize].include?(:memsize) %>
  189. p.vmx["memsize"] = "<%= value %>"
  190. <% end %>
  191. <% elsif key == :cpus %>
  192. <% unless config[:customize].include?(:numvcpus) %>
  193. p.vmx["numvcpus"] = "<%= value %>"
  194. <% end %>
  195. <% else %>
  196. p.vmx["<%= key %>"] = "<%= value %>"
  197. <% end %>
  198. <% else %>
  199. <% if value.is_a? String %>
  200. p.<%= key %> = "<%= value%>"
  201. <% else %>
  202. p.<%= key %> = <%= value%>
  203. <% end %>
  204. <% end %>
  205. <% end %>
  206. end
  207.  
  208. end
Add Comment
Please, Sign In to add comment