DEV Community

nithinalias
nithinalias

Posted on • Edited on

Generate three servers using Vagrant file

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# This defines the version of vagrant
Vagrant.configure("2") do |config|

MACHINE = ["nginx","wordpress","mysql"]
N = 2

(0..N).each do |i|

  config.vm.define "#{MACHINE[i]}" do |node|
  node.vm.hostname = MACHINE[i]
  node.vm.box = "ubuntu/focal64"
  node.vm.network :private_network, ip: "192.168.33.#{10+i}"

  if (i == 0)
  node.vm.provider "virtualbox" do |vb|
  vb.memory = "512"
  end
  node.vm.provision "shell", inline: <<-SHELL
       apt update
     apt install -y php libapache2-mod-php php-mysql
     cd /tmp
     curl -O https://wordpress.org/latest.tar.gz
     tar xzvf latest.tar.gz
     touch /tmp/wordpress/.htaccess
     cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
     mkdir /tmp/wordpress/wp-content/upgrade
     mkdir /var/www/wordpress
     cp -a /tmp/wordpress/. /var/www/wordpress

  SHELL


  else if (i == 1)
  node.vm.provider "virtualbox" do |vb|
  vb.memory = "700"
  end
  node.vm.provision "shell", inline: <<-SHELL
      apt update
      apt install -y apache2
      systemctl enable apache2
      systemctl restart apache2
 SHELL
 else
  node.vm.provider "virtualbox" do |vb|
  vb.memory = "1024"
  end
  node.vm.provision "shell", inline: <<-SHELL
      apt update
      apt install -y mysql-server
      systemctl enable mysql
      systemctl restart mysql

  SHELL


end
end
end
end
end


Enter fullscreen mode Exit fullscreen mode

Top comments (0)