Preparación del laboratorio para curso de Ansible
Se necesitan 3 máquinas para el laboratorio, 1 Ansible controller y 2 Ansible target. El entorno lo levanto a través de Vagrant con 3 máquinas Centos 9 Stream. El Vagrantfile que creo es:
Vagrant.configure("2") do |config|
config.vm.define "ans_controller" do |ans_c|
ans_c.vm.box = "generic/centos9s"
ans_c.vm.network "public_network"
ans_c.vm.provision "shell", inline: <<-SHELL
sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
sudo sed -i 's/centos9s/ansiblecontroller/' /etc/hosts
sudo service sshd restart
sudo hostnamectl set-hostname ansiblecontroller
sudo yum install ansible -y
sudo reboot
SHELL
end
config.vm.define "ans_target1" do |ans_t1|
ans_t1.vm.box = "generic/centos9s"
ans_t1.vm.network "public_network"
ans_t1.vm.provision "shell", inline: <<-SHELL
sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
sudo sed -i 's/centos9s/ansibletarget1/' /etc/hosts
sudo service sshd restart
sudo hostnamectl set-hostname ansibletarget1
sudo reboot
SHELL
end
config.vm.define "ans_target2" do |ans_t2|
ans_t2.vm.box = "generic/centos9s"
ans_t2.vm.network "public_network"
ans_t2.vm.provision "shell", inline: <<-SHELL
sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
sudo sed -i 's/centos9s/ansibletarget2/' /etc/hosts
sudo service sshd restart
sudo hostnamectl set-hostname ansibletarget2
sudo reboot
SHELL
end
end
En la parte de provision lo que hago es habilitar el acceso por SSH con contraseña, cambiar el hostname e instalar Ansible (solo en el controller, ya que Ansible es agentless) y por último reiniciar la máquina.