Advertisement
Guest User

Untitled

a guest
Nov 5th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. VAGRANTFILE_API_VERSION = "2"
  2.  
  3. require 'io/console'
  4.  
  5. # Capture login details if starting up vagrant or provisioning it
  6. # Required for AD operations.
  7. #
  8. # Environment variables prevent explicit user input. Useful for CI.
  9. username = ENV["VAGRANT_USER"] || nil
  10. password = ENV["VAGRANT_PASSWORD"] || nil
  11.  
  12. # Used to generate a unique VM name registered to AD
  13. computerName, shareComputerName =
  14. if ENV["VAGRANT_COMPUTERNAME"]
  15. [ENV["VAGRANT_COMPUTERNAME"], ENV["COMPUTERNAME"]]
  16. elsif ENV["COMPUTERNAME"]
  17. [ENV["COMPUTERNAME"].sub(/^D/, 'V'), ENV["COMPUTERNAME"]]
  18. else
  19. ['v' + `hostname`.sub(".yourdomain.int", "").strip, `hostname`.strip]
  20. end
  21.  
  22. # Setup local code shares for Vagrant
  23. # NOTE: this feature will be available natively in Vagrant 1.7
  24. sharePath = File.dirname(__FILE__)
  25. shareName = 'vworkspace'
  26. shareGuestPath = 'c:\vworkspace'
  27.  
  28. # Collect credentials from the user (unless specified through ENV vars)
  29. # Only request creds for provisioning type operations
  30. # NOTE: Replace DOMAIN with your company domain
  31. if ARGV[0] != nil && ['up', 'provision', 'reload'].include?(ARGV[0])
  32. if !username
  33. print "Please enter your DOMAIN username: "
  34. username = "DOMAIN\\" + STDIN.gets.chomp
  35. end
  36. if !password
  37. print "Please enter your password (input is hidden): "
  38. password = STDIN.noecho(&:gets).chomp
  39. end
  40. puts ""
  41.  
  42. # Let's fail early and loud if the users'
  43. # credentials supplied are not actually valid.
  44. # Sorry Mac\Linux users - this only works on Windows!
  45. share = false
  46. message = "Unable to create share. Skipping."
  47. if Gem.win_platform?
  48. system("powershell.exe ./.box/authenticate.ps1 #{username} #{password}")
  49.  
  50. if !$?.success?
  51. puts "Authentication failed, please try again."
  52. exit 1
  53. end
  54.  
  55. # Create Local Share
  56. share = system("powershell.exe ./.box/setup-share.ps1 #{sharePath} #{shareName}")
  57.  
  58. elsif RUBY_PLATFORM.match("darwin")
  59. share = system("sh ./.box/setup-share-mac.sh")
  60. else
  61. message = "Sorry, we haven't created automatic SMB sharing support for your platform yet."
  62. share = false
  63. end
  64.  
  65. if !share
  66. puts "#{message}"
  67. end
  68.  
  69. end
  70.  
  71. # Actual Vagrantfile.
  72. #
  73. # Vagrant is responsible for running your infrastructure!
  74. #
  75. Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  76. config.vm.box = "dev-base-v3"
  77.  
  78. guest_port = 5895
  79. config.vm.network :forwarded_port, guest: 3389, host: 3299, id: "rdp", auto_correct: false
  80. config.vm.network :forwarded_port, guest: 5985, host: guest_port, id: "winrm", auto_correct: false
  81. config.vm.network :forwarded_port, guest: 80, host: 8001, id: "web", auto_correct: false
  82. config.vm.network :forwarded_port, guest: 443, host: 8444, id: "ssl", auto_correct: false
  83. config.winrm.guest_port = guest_port
  84. config.winrm.host = "localhost"
  85. config.vm.host_name = computerName
  86. config.vm.synced_folder ".", "/vagrant"
  87.  
  88. # This creates network access into the guest from the host.
  89. #
  90. # If you prefer to manualy set the IP of the guest,
  91. # this is how you do it:
  92. #
  93. # config.vm.network "private_network", ip: "192.168.3.1"
  94. config.vm.network "private_network", type: "dhcp"
  95.  
  96. config.vm.provider "virtualbox" do |v|
  97. v.gui = true
  98. end
  99.  
  100. # Connect to the created network share each time the box is started
  101. $setup_share = <<SCRIPT
  102. $secpasswd = ConvertTo-SecureString "#{password}" -AsPlainText -Force
  103. $DOMAIN_CREDENTIALS = New-Object System.Management.Automation.PSCredential ("#{username}", $secpasswd)
  104. $env:DOMAIN_COMPUTERNAME="#{computerName}"
  105. $env:DOMAIN_USERNAME="#{username}"
  106.  
  107. $host_path = "\\\\#{shareComputerName}\\#{shareName}"
  108. net use * $host_path /user:#{username} #{password} /persistent:yes
  109. SCRIPT
  110.  
  111. # The main provisioning script
  112. $do_something = <<SCRIPT
  113. # ...
  114. SCRIPT
  115.  
  116. config.vm.provision "shell", inline: $setup_share, run: always
  117. config.vm.provision "shell", inline: $do_something
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement