Added variant for Vagrant

This commit is contained in:
karsalan
2025-02-03 15:03:45 +01:00
parent b6f7bf632d
commit 59ac31feae
4 changed files with 38 additions and 17 deletions

View File

@@ -28,8 +28,7 @@ Sur votre portable :
```bash ```bash
apt-get install ansible apt-get install ansible
git clone https://github.com/barais/demoAnsible cd lamp_ubuntu2204_2hosts_withroles
cd demoAnsible/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 # éditez le fichier hosts pour y mettre les IP de vos VMs ainsi que le login et le mot de passe
nano -w hosts nano -w hosts
ansible-playbook site.yml -i hosts ansible-playbook site.yml -i hosts

View File

@@ -2,15 +2,18 @@
## Setup ## Setup
- Install Virtualbox
- Install vagrant - Install vagrant
- Install ansible - Install ansible
- Start the VMs using vagrant - Install Virtualbox (if libvirt provider is not used)
> Start the VMs using vagrant
```bash ```bash
git clone https://github.com/barais/demoAnsible # Choose between libvirt and virtualbox depending on your provider
cd vagrant cd vagrant/libvirt
cd vagrant/virtualbox
# Start the VMs
vagant up vagant up
# Check that the VM are up # Check that the VM are up
# Check that you can login using ssh (ssh vagrant@192.168.56.141 # password: vagrant) # Check that you can login using ssh (ssh vagrant@192.168.56.141 # password: vagrant)
@@ -18,7 +21,7 @@ vagant up
## Demo 1 ## Demo 1
Run the playbook - Run the playbook (verify that playbook parameters match your VMs)
```bash ```bash
ansible-playbook playbook.yml -i hosts 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. - Kill the VMs and remove them.
- Use vagrant to recreate them from scratch - Use vagrant to recreate them from scratch
```bash - Run the playbook
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
```bash ```bash
ansible-playbook site.yml -i hosts ansible-playbook site.yml -i hosts

27
vagrant/libvirt/Vagrantfile vendored Normal file
View File

@@ -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

View File

@@ -1,7 +1,7 @@
# #################################################################### # ####################################################################
# ################### CONFIGURATION VARIABLES ######################## # ################### 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 MEM = 2048 # Amount of RAM
CPU = 1 # Number of processors CPU = 1 # Number of processors
SLAVE_NBR = 2 # Number of slaves node SLAVE_NBR = 2 # Number of slaves node