Manage multiple server & client computers with SaltStack (finnish)
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.

87 lines
2.1 KiB

  1. # Create multiple virtual machines with Vagrant on Linux
  2. # Author: Pekka Helenius (~Fincer), 2018
  3. #######################################
  4. # Basic Vagrantfile configuration
  5. # Number of virtual machines
  6. vbox_num = 2
  7. # Virtual machine name prefix
  8. vbox_prefix = "minion_"
  9. # Allocated memory per virtual machine
  10. # NOTE: Remember the RAM limits of your host machine!
  11. vbox_mem = 512
  12. # CPU's per virtual machine
  13. vbox_cpu = 1
  14. # Vagrant box template for virtual machines
  15. #
  16. # If you change this, remember to check for salt file locations &
  17. # package manager commands used in this Vagrantfile
  18. #
  19. # For more templates, see: https://app.vagrantup.com/boxes/search
  20. vbox_template = "bento/ubuntu-16.04"
  21. #######################################
  22. # Create a new array for virtual machines
  23. vboxes = []
  24. (1..vbox_num).each do |vbox|
  25. vboxes.push("#{vbox_prefix}#{vbox}")
  26. end
  27. #######################################
  28. VAGRANT_API_VERSION = 2
  29. #######################################
  30. # This is for salt_install provision below
  31. initial_setup = "
  32. # Start of $initial_setup variable
  33. apt-get update && \
  34. apt-get -y install salt-minion && \
  35. systemctl enable salt-minion
  36. if [ $? -ne 0 ]; then
  37. exit 1
  38. fi
  39. # End of $initial_setup variable
  40. "
  41. #######################################
  42. # Define Vagrant machine configuration here
  43. Vagrant.configure(VAGRANT_API_VERSION) do |config|
  44. config.vm.box = "#{vbox_template}"
  45. config.vm.box_check_update = true
  46. config.vm.synced_folder ".", "/vagrant", disabled: true
  47. vboxes.each do |box|
  48. config.vm.define "#{box}" do |node|
  49. node.vm.provision "salt_install", run: "once", type: "shell" do |cmd_1|
  50. cmd_1.inline = "#{initial_setup}"
  51. cmd_1.privileged = "true"
  52. end
  53. node.vm.provision "salt_config", run: "once", type: "shell" do |cmd_2|
  54. cmd_2.inline = "echo 'master: #{`hostname`}id: #{box}' | tee -a /etc/salt/minion && systemctl restart salt-minion"
  55. cmd_2.privileged = "true"
  56. end
  57. node.vm.provider "virtualbox" do |v|
  58. v.memory = "#{vbox_mem}"
  59. v.cpus = "#{vbox_cpu}"
  60. v.name = "#{box}"
  61. end
  62. end
  63. end
  64. end