Advertisement
Guest User

Untitled

a guest
Feb 1st, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # vim: noai:ts=2:sw=2:et
  4.  
  5. # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
  6. VAGRANTFILE_API_VERSION = "2"
  7.  
  8. UBUNTU_BOX='ubuntu/trusty64'
  9. CENTOS_BOX='centos/7'
  10.  
  11. DOCKER_MEM = 1024
  12. DOCKER_CPUS = 2
  13.  
  14. $ansible_script = <<SHELL
  15. # do this to refresh your patch repo db
  16. sudo yum makecache fast
  17. sudo yum update -y
  18. # install stuff
  19. sudo yum install vim epel-release yum-utils git -y
  20. # as Ansible comes from EPEL, we install it after we installed EPEL
  21. sudo yum install ansible python-pip gcc python-devel openssl-devel -y
  22. # now install winrm to access windows boxes from Ansible
  23. sudo pip install pywinrm
  24. # fix for missing/outdated security libs
  25. sudo pip install requests[security]
  26. # openstack clients
  27. sudo pip install python-openstackclient
  28. SHELL
  29.  
  30. $redhat_network = <<SHELL
  31. SHELL
  32.  
  33. servers = {
  34. "ansible01" => { :ip => "172.30.5.60", :bridge => "eth1", :mem => DOCKER_MEM, :cpus => DOCKER_CPUS, :box => CENTOS_BOX, :script => $ansible_script },
  35. "docker-engine01" => { :ip => "172.30.5.61", :bridge => "eth1", :mem => DOCKER_MEM, :cpus => DOCKER_CPUS, :box => UBUNTU_BOX, :script => '' },
  36. "docker-engine02" => { :ip => "172.30.5.62", :bridge => "eth1", :mem => DOCKER_MEM, :cpus => DOCKER_CPUS, :box => UBUNTU_BOX, :script => '' },
  37. "docker-engine03" => { :ip => "172.30.5.63", :bridge => "eth1", :mem => DOCKER_MEM, :cpus => DOCKER_CPUS, :box => UBUNTU_BOX, :script => '' },
  38. "docker-engine04" => { :ip => "172.30.5.64", :bridge => "eth1", :mem => DOCKER_MEM, :cpus => DOCKER_CPUS, :box => UBUNTU_BOX, :script => '' }
  39. }
  40.  
  41. Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  42.  
  43. config.vm.box_check_update = false
  44. # enable logging in via ssh with a password
  45. #config.ssh.username = "vagrant"
  46. #config.ssh.password = "vagrant"
  47.  
  48. ################################################################################
  49. servers.each_with_index do |(hostname, info), index|
  50.  
  51. #
  52. # build a vm - from the server dict
  53. #
  54. config.vm.define hostname do |cfg|
  55. cfg.vm.box = info[:box]
  56. cfg.vm.hostname = hostname
  57.  
  58. # note the public network
  59. cfg.vm.network "public_network", ip: info[:ip], bridge: info[:bridge]
  60.  
  61. config.vm.provider "virtualbox" do |v|
  62. v.name = hostname
  63. v.memory = info[:mem]
  64. v.cpus = info[:cpus]
  65. v.customize ["modifyvm", :id, "--hwvirtex", "on"]
  66. end
  67.  
  68. #
  69. # do some provisioning - but only once
  70. #
  71. config.vm.provision "shell", run: "once" do |s|
  72. ssh_prv_key = ""
  73. ssh_pub_key = ""
  74. if File.file?("#{Dir.home}/.ssh/vagrant")
  75. ssh_prv_key = File.read("#{Dir.home}/.ssh/vagrant")
  76. ssh_pub_key = File.readlines("#{Dir.home}/.ssh/vagrant.pub").first.strip
  77. else
  78. puts "No SSH key found. You will need to remedy this before pushing to the repository."
  79. end
  80. puts "SSH key insertion"
  81. s.inline = <<-SHELL
  82. if grep -sq "#{ssh_pub_key}" /home/vagrant/.ssh/authorized_keys; then
  83. echo "SSH keys already provisioned."
  84. exit 0;
  85. fi
  86. echo "SSH key provisioning."
  87. mkdir -p /home/vagrant/.ssh/
  88. touch /home/vagrant/.ssh/authorized_keys
  89. echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
  90. echo #{ssh_pub_key} > /home/vagrant/.ssh/id_rsa.pub
  91. chmod 644 /home/vagrant/.ssh/id_rsa.pub
  92. echo "#{ssh_prv_key}" > /home/vagrant/.ssh/id_rsa
  93. chmod 600 /home/vagrant/.ssh/id_rsa
  94. chown -R vagrant:vagrant /home/vagrant
  95. exit 0
  96. SHELL
  97. #
  98. # this fixes the centos boxes not enabling their eth1 IPs
  99. #
  100. $box = info[:box]
  101. if $box =~ /redhat|centos/i
  102. puts "RedHat check and network fix"
  103. s.inline = <<SHELL
  104. if [ -e /etc/redhat-release ] ; then
  105. echo "Redhat release found"
  106. if [ $(ip a s dev eth1 | grep -c "inet #{info[:ip]}") -eq 0 ] ; then
  107. echo "Restarting network"
  108. touch /tmp/network-setup
  109. sudo nmcli connection reload
  110. sudo systemctl restart network.service
  111. else
  112. echo "Network is already up"
  113. fi
  114. else
  115. echo "Not redhat"
  116. fi
  117. exit 0
  118. SHELL
  119. end
  120. #
  121. # any script per vm to install
  122. #
  123. s.inline = info[:script]
  124. # end scripts
  125. end
  126.  
  127. end
  128. end
  129. ################################################################################
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement