wikiv2:ansible_preparation_lab01
Table of Contents
Preparação
Vagrantfile
- Vagrantfile
# -*- mode: ruby -*- # vi: set ft=ruby : require 'yaml' secmachines = YAML.load_file("machines.yml") Vagrant.configure("2") do |config| secmachines.each do |machines| config.vm.define machines["name"] do |server| server.vm.hostname = machines["name"] server.vm.box = machines["box"] server.vm.box_check_update = false server.vm.network "private_network", ip: machines["ip"] server.vm.provider "virtualbox" do |vb| vb.customize ["modifyvm", :id, "--groups", "/LabAnsible"] vb.memory = machines["memory"] vb.cpus = machines["cpus"] vb.name = machines["name"] end server.vm.provision "file", source: "keys/ansible", destination: "/tmp/ansible" server.vm.provision "file", source: "keys/ansible.pub", destination: "/tmp/ansible.pub" server.vm.provision "shell", path: machines["script"] end end end
Definição das VMs
- machines.yml
# automation - Ansible server - name: automation cpus: 2 memory: 2048 ip: 192.168.100.10 box: debian/bullseye64 script: startup.sh # ol9 - Oracle Linux 9 - name: ol9 cpus: 2 memory: 2048 ip: 192.168.100.20 box: generic/oracle9 script: startup.sh # deb11 - Debian 11 - name: deb11 cpus: 2 memory: 2048 ip: 192.168.100.30 box: debian/bullseye64 script: startup.sh # bsd - FreeBSD 13 - name: bsd13 cpus: 2 memory: 2048 ip: 192.168.100.40 box: generic/freebsd13 script: startup.sh
Script de inicialização
- startup.sh
#!/bin/bash validateCommand() { if [ $? -eq 0 ]; then echo "[OK] $1" else echo "[ERROR] $1" exit 1 fi } # Inserindo chave SSH sudo test -f /root/.ssh/id_rsa if [ $? -eq 1 ]; then sudo mkdir -p /root/.ssh/ && \ sudo cp /tmp/ansible /root/.ssh/id_rsa && \ sudo cp /tmp/ansible.pub /root/.ssh/authorized_keys && \ sudo chmod 600 /root/.ssh/id_rsa validateCommand "Preparando SSH KEY" else echo "[OK] SSH KEY" fi
Chave ssh
> ssh-keygen -f ansible
Iniciando as VMs
> vagrant up
wikiv2/ansible_preparation_lab01.txt · Last modified: by 127.0.0.1
