From 59ac31feae6fedd3bea94243bc39531bd7583193 Mon Sep 17 00:00:00 2001 From: karsalan Date: Mon, 3 Feb 2025 15:03:45 +0100 Subject: [PATCH] Added variant for Vagrant --- README.md | 3 +-- run_demo.md | 23 +++++++++-------------- vagrant/libvirt/Vagrantfile | 27 +++++++++++++++++++++++++++ vagrant/{ => virtualbox}/Vagrantfile | 2 +- 4 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 vagrant/libvirt/Vagrantfile rename vagrant/{ => virtualbox}/Vagrantfile (94%) diff --git a/README.md b/README.md index efb7e11..bc74669 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,7 @@ Sur votre portable : ```bash apt-get install ansible -git clone https://github.com/barais/demoAnsible -cd demoAnsible/lamp_ubuntu2204_2hosts_withroles +cd lamp_ubuntu2204_2hosts_withroles # éditez le fichier hosts pour y mettre les IP de vos VMs ainsi que le login et le mot de passe nano -w hosts ansible-playbook site.yml -i hosts diff --git a/run_demo.md b/run_demo.md index ecd9be5..640f683 100644 --- a/run_demo.md +++ b/run_demo.md @@ -2,15 +2,18 @@ ## Setup -- Install Virtualbox - Install vagrant - Install ansible -- Start the VMs using vagrant +- Install Virtualbox (if libvirt provider is not used) +> Start the VMs using vagrant ```bash -git clone https://github.com/barais/demoAnsible -cd vagrant +# Choose between libvirt and virtualbox depending on your provider +cd vagrant/libvirt +cd vagrant/virtualbox + +# Start the VMs vagant up # Check that the VM are up # Check that you can login using ssh (ssh vagrant@192.168.56.141 # password: vagrant) @@ -18,7 +21,7 @@ vagant up ## Demo 1 -Run the playbook +- Run the playbook (verify that playbook parameters match your VMs) ```bash ansible-playbook playbook.yml -i hosts @@ -31,15 +34,7 @@ Try to access http://192.168.56.141/index.php - Kill the VMs and remove them. - Use vagrant to recreate them from scratch -```bash -git clone https://github.com/barais/demoAnsible -cd vagrant -vagant up -# Check that the VM are up -# Check that you can login using ssh (ssh vagrant@192.168.56.141 # password: vagrant) -``` - -Run the playbook +- Run the playbook ```bash ansible-playbook site.yml -i hosts diff --git a/vagrant/libvirt/Vagrantfile b/vagrant/libvirt/Vagrantfile new file mode 100644 index 0000000..7b3e46a --- /dev/null +++ b/vagrant/libvirt/Vagrantfile @@ -0,0 +1,27 @@ +# #################################################################### +# ################### CONFIGURATION VARIABLES ######################## +# #################################################################### +IMAGE_NAME = "generic/ubuntu2204" # Image to use +MEM = 2048 # Amount of RAM +CPU = 1 # Number of processors +SLAVE_NBR = 2 # Number of slaves node + + +Vagrant.configure("2") do |config| + # RAM and CPU config + config.vm.provider "libvirt" do |v| + v.memory = MEM + v.cpus = CPU + end + + # Slave node config + (1..SLAVE_NBR).each do |i| + config.ssh.insert_key = false + config.vm.define "slave-#{i}" do |slave| + # OS and Hostname + slave.vm.box = IMAGE_NAME + slave.vm.hostname = "slave-#{i}" + slave.vm.network "private_network", ip: "192.168.56.14#{i}" + end + end +end \ No newline at end of file diff --git a/vagrant/Vagrantfile b/vagrant/virtualbox/Vagrantfile similarity index 94% rename from vagrant/Vagrantfile rename to vagrant/virtualbox/Vagrantfile index 24868f5..96ae97a 100644 --- a/vagrant/Vagrantfile +++ b/vagrant/virtualbox/Vagrantfile @@ -1,7 +1,7 @@ # #################################################################### # ################### CONFIGURATION VARIABLES ######################## # #################################################################### -IMAGE_NAME = "bento/ubuntu-22.04" # Image to use +IMAGE_NAME = "generic/ubuntu-22.04" # Image to use MEM = 2048 # Amount of RAM CPU = 1 # Number of processors SLAVE_NBR = 2 # Number of slaves node