# -*- mode: ruby -*- # vi: set ft=ruby : # Faire au dépant des hostname Vagrant.configure("2") do |config| config.vm.box = "fujimakishouten/debian-stretch64" config.vm.box_check_update = false # Provision des deux machines : config.vm.provision "shell", inline: <<-EOS set -x sudo echo "deb [trusted=yes] https://apt.dockerproject.org/repo debian-stretch main" > /etc/apt/sources.list.d/docker.list sudo apt-get install apt-transport-https ca-certificates iftop curl htop iotop tmux dirmngr sshpass -y sudo apt-get --allow-unauthenticated update # Onstallatio nde docker : #sudo curl -sSL get.docker.com |sh sudo sudo apt-get --allow-unauthenticated install docker-engine -y # L'utilisateur swarm aura les droits d'executer les conteneurs : sudo useradd -m -s /bin/bash -g users swarm echo swarm:swarm |chpasswd sudo usermod -aG docker swarm sudo sed -i.bak 's/^PasswordAuthentication/#/' /etc/ssh/sshd_config sudo service ssh restart EOS # Configuration matériel appliqué aux machines : config.vm.provider "virtualbox" do |vb| vb.customize ["modifyvm", :id, "--memory", "1024"] vb.customize ["modifyvm", :id, "--cpus", "1"] end # Déclaration des VMs : config.vm.define "swarm2" do |server| config.vm.hostname = "swarm2" config.vm.network "public_network", adapter: 2, :bridge => "eno1", ip: "192.168.1.205" sleep(2) if ARGV.include?("--provision") then config.vm.provision "shell", inline: <<-EOS set -x token=$(cat /tmp/token.txt |grep token |head -1 |awk '{ print $2 }') docker swarm join --token $token 192.168.1.201 EOS end end config.vm.define "swarm3" do |server| config.vm.hostname = "swarm3" config.vm.network "public_network", adapter: 2, :bridge => "eno1", ip: "192.168.1.203" sleep(2) if ARGV.include?("--provision") then config.vm.provision "shell", inline: <<-EOS set -x token=$(cat /tmp/token.txt |grep token |head -1 |awk '{ print $2 }') docker swarm join --token $token 192.168.1.201 EOS end end config.vm.define "swarm4" do |server| config.vm.hostname = "swarm4" config.vm.network "public_network", adapter: 2, :bridge => "eno1", ip: "192.168.1.204" sleep(2) if ARGV.include?("--provision") then config.vm.provision "shell", inline: <<-EOS set -x token=$(cat /tmp/token.txt |grep token |head -1 |awk '{ print $2 }') docker swarm join --token $token 192.168.1.201 EOS end end config.vm.define "swarm1" do |server| config.vm.hostname = "swarm1" config.vm.network "public_network", adapter: 2, :bridge => "eno1", ip: "192.168.1.201" config.vm.provision "shell", inline: <<-EOS set -x sudo -u swarm docker swarm init --listen-addr 192.168.1.201 --advertise-addr enp0s8 > /tmp/token.txt sudo -u swarm sshpass -p swarm scp -o StrictHostKeyChecking=no /tmp/token.txt swarm@192.168.1.205:/tmp/token.txt sudo -u swarm sshpass -p swarm scp -o StrictHostKeyChecking=no /tmp/token.txt swarm@192.168.1.203:/tmp/token.txt sudo -u swarm sshpass -p swarm scp -o StrictHostKeyChecking=no /tmp/token.txt swarm@192.168.1.204:/tmp/token.txt EOS end end