Aller au contenu principal

config-vagrant-vmware

Pour configurer Vagrant SSH et installer Ansible, Node.js, et Git sur une machine Debian 12 en architecture ARM64, suivez les étapes ci-dessous :

1. Installer Vagrant

Si vous n'avez pas encore installé Vagrant, vous pouvez le faire en suivant les instructions officielles pour votre système d'exploitation.

2. Créer un fichier Vagrantfile

Créez un répertoire pour votre projet Vagrant et à l'intérieur, créez un fichier Vagrantfile avec le contenu suivant :

# Config vagrantfile virtual machine vmware with ansible
# run (vagrant up)
# connected user = ssh mekoo@192.168.50.100
# public_key fingerprint
# run sudo -l (look privilège)
# exit vagrant machine and run vagrant up --provision

Vagrant.configure("2") do |config|

config.vm.define "master" do |node|

node.vm.box = "bento/debian-12-arm64"
node.vm.hostname = 'master'
node.vm.network "private_network", type: "dhcp", ip: "192.168.50.100"
node.vm.box_version = "202404.23.0"
node.vm.provision "shell", inline: <<-SHELL
# Mise à jour du système
apt-get update
apt-get upgrade -y

# Installation d'Ansible
apt-get install -y ansible

# Installation de Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt-get install -y nodejs

# Installation de Git
apt-get install -y git
SHELL

node.vm.provider :vmware_desktop do |v|
v.vmx["memsize"] = 4096
v.vmx["numvcpus"] = 4
v.ssh_info_public = true
v.gui = true
end
end

config.vm.define "zabbixserver" do |mv|

mv.vm.box = "bento/debian-12-arm64"
mv.vm.host_name = 'zabbixserver'
mv.vm.network "private_network", type: "dhcp", ip: "192.168.50.101"
mv.vm.box_version = "202404.23.0"

mv.vm.provider :vmware_desktop do |v|
v.vmx["memsize"] = 2048
v.vmx["numvcpus"] = 2
v.ssh_info_public = true
v.gui = true
end
end

config.vm.define "zabbixproxy" do |mv|

mv.vm.box = "bento/debian-12-arm64"
mv.vm.host_name = 'zabbixproxy'
mv.vm.network "private_network", type: "dhcp", ip: "192.168.50.102"
mv.vm.box_version = "202404.23.0"

mv.vm.provider :vmware_desktop do |v|
v.vmx["memsize"] = 2048
v.vmx["numvcpus"] = 2
v.ssh_info_public = true
v.gui = true
end
end
config.vm.define "masterwebfront" do |mv|

mv.vm.box = "bento/debian-12-arm64"
mv.vm.host_name = 'masterwebfront'
mv.vm.network "private_network", type: "dhcp", ip: "192.168.50.103"
mv.vm.provision "shell", inline: <<-SHELL
# Mise à jour du système
apt-get update
apt-get upgrade -y

# Installation d'Ansible
apt-get install -y ansible

# Installation de Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt-get install -y nodejs

# Installation de Git
apt-get install -y git

# git config
#git config --global user.name "$(whoami)"
#git config --global user.email "$(whoami)@$(hostname).com"

# ssh create and add ssh eval key no passphrase ans no password
ssh-keygen -t ed25519 -C "$(whoami)@$(hostname)-$(date +%Y-%m-%d)" -N "" -f ~/.ssh/id_ed25519

# Variables
ZABBIX_SERVER="192.168.50.101" # Replace with your Zabbix server IP or hostname
HOSTNAME="masterwebfront" # Replace with the hostname of this machine

# Update the package list
sudo apt-get update

# Install the Zabbix agent
sudo apt-get install -y zabbix-agent

# Backup the original configuration file
sudo cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.bak

# Configure the Zabbix agent
sudo sed -i "s/^Server=.*/Server=$ZABBIX_SERVER/" /etc/zabbix/zabbix_agentd.conf
sudo sed -i "s/^ServerActive=.*/ServerActive=$ZABBIX_SERVER/" /etc/zabbix/zabbix_agentd.conf
sudo sed -i "s/^Hostname=.*/Hostname=$HOSTNAME/" /etc/zabbix/zabbix_agentd.conf

# Start and enable the Zabbix agent service
sudo systemctl restart zabbix-agent
sudo systemctl enable zabbix-agent

# Check the status of the Zabbix agent
sudo systemctl status zabbix-agent

echo "Zabbix agent installation and configuration completed."
SHELL
mv.vm.provider :vmware_desktop do |v|
v.vmx["memsize"] = 2048
v.vmx["numvcpus"] = 2
v.ssh_info_public = true
v.gui = true
end
end

config.vm.define "masterbackend" do |mv|

mv.vm.box = "bento/debian-12-arm64"
mv.vm.host_name = 'masterbackend'
mv.vm.network "private_network", type: "dhcp", ip: "192.168.50.104"
mv.vm.provision "shell", inline: <<-SHELL
# Mise à jour du système
apt-get update
apt-get upgrade -y

# Installation d'Ansible
apt-get install -y ansible

# Installation de Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt-get install -y nodejs

# Installation de Git
apt-get install -y git
SHELL
mv.vm.provider :vmware_desktop do |v|
v.vmx["memsize"] = 2048
v.vmx["numvcpus"] = 2
v.ssh_info_public = true
v.gui = true
end
end
end

3. Démarrer la machine virtuelle

Dans le répertoire où se trouve votre Vagrantfile, exécutez la commande suivante pour démarrer la machine virtuelle :

vagrant up

4. Se connecter à la machine virtuelle via SSH

Une fois la machine virtuelle démarrée, vous pouvez vous y connecter via SSH avec la commande :

vagrant ssh

5. Vérifier les installations

Une fois connecté, vous pouvez vérifier que les logiciels sont bien installés :

  • Ansible :

    ansible --version
  • Node.js :

    node -v
    npm -v
  • Git :

    git --version

6. (Optionnel) Configurer Ansible

Si vous souhaitez utiliser Ansible pour gérer d'autres machines, vous pouvez créer un fichier d'inventaire et des playbooks Ansible dans le répertoire partagé entre votre machine hôte et la machine virtuelle.

7. Arrêter ou détruire la machine virtuelle

  • Pour arrêter la machine virtuelle :

    vagrant halt
  • Pour détruire la machine virtuelle (cela supprimera la VM) :

    vagrant destroy

Remarques

  • Assurez-vous que VirtualBox ou un autre fournisseur de virtualisation est installé et compatible avec l'architecture ARM64.
  • La box bento/debian-12-arm64 est utilisée ici pour Debian 12 sur ARM64. Si cette box n'est pas disponible, vous devrez peut-être en trouver une autre compatible avec ARM64.

Avec ces étapes, vous devriez avoir une machine virtuelle Debian 12 ARM64 configurée avec Vagrant, et les logiciels Ansible, Node.js, et Git installés.