How to use this box with Vagrant:
Vagrant.configure("2") do |config|
config.vm.box = "cirillialberto/Centos9stream-aarch64"
config.vm.box_version = "0.1.0"
end
vagrant init cirillialberto/Centos9stream-aarch64 \
--box-version 0.1.0
vagrant up
This version was created 3 months ago.
With this image i'm able to rum almost all the examples from https://github.com/geerlingguy/ansible-vagrant-examples and https://github.com/geerlingguy/ansible-for-devops . It is possible to define multiple VMs with static IP and connectivity between VMs. With this configuration i define two network adapters. One "internal" for vagrant and one "public"
For example this Vagrantfile is the one i use for the 3 nodes kubernetes cluster
VAGRANTFILE_API_VERSION = "2"
# Define two VMs with static private IP addresses.
boxes = [
{ :name => "kube1",
:ssh_port => "60022",
:cpu => "cpus=2,sockets=1,cores=2,threads=1",
:mem => "4G",
:private_ip => "10.2.0.71",
:private_net => "10.2.0.0/24",
:public_ip => "192.168.1.71",
:public_mask => "24",
:public_gw => "192.168.1.1",
:public_ifname => "en0",
:public_mac => "AA:AB:AC:AD:00:71"
},
{ :name => "kube2",
:ssh_port => "60023",
:cpu => "cpus=2,sockets=1,cores=2,threads=1",
:mem => "4G",
:private_ip => "10.2.0.72",
:private_net => "10.2.0.0/24",
:public_ip => "192.168.1.72",
:public_mask => "24",
:public_gw => "192.168.1.1",
:public_ifname => "en0",
:public_mac => "AA:AB:AC:AD:00:72"
},
{ :name => "kube3",
:ssh_port => "60024",
:cpu => "cpus=2,sockets=1,cores=2,threads=1",
:mem => "4G",
:private_ip => "10.2.0.73",
:private_net => "10.2.0.0/24",
:public_ip => "192.168.1.73",
:public_mask => "24",
:public_gw => "192.168.1.1",
:public_ifname => "en0",
:public_mac => "AA:AB:AC:AD:00:73"
}
]
# Build my own ansible.host_var variable
fixIP_host_var = {}
# Load machines
for m in boxes do
pub = {}
# Add here all the variable you need to set for your host
pub["public_ip"] = (m[:public_ip])
pub["public_gw"] = (m[:public_gw])
pub["public_mask"] = (m[:public_mask])
fixIP_host_var[m[:name]] = pub
end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Provision each of the VMs.
boxes.each do |node|
# Define VM
config.vm.define node[:name] do |nodeconfig|
# Define the base box
nodeconfig.vm.box = "cirillialberto/Centos9stream-aarch64"
nodeconfig.vm.box_version = "0.1.0"
# nodeconfig.vm.box = "perk/ubuntu-2204-arm64"
# nodeconfig.vm.box_version = "20230107"
nodeconfig.vm.hostname = node[:name]
nodeconfig.vm.synced_folder '.', '/vagrant', disabled: true
# Configure QEMU provider
nodeconfig.vm.provider "qemu" do |qemu|
qemu.machine = "virt,accel=hvf"
qemu.ssh_port = node[:ssh_port]
qemu.cpu = "host"
qemu.smp = node[:cpu] || 1
qemu.memory = node[:mem] || 1024
qemu.arch = "aarch64"
qemu.qemu_dir = "/opt/homebrew/share/qemu"
qemu.net_device = "virtio-net-device"
qemu.extra_netdev_args = "net=" + node[:private_net] + ",dhcpstart=" + node[:private_ip]
ARGS1 = "virtio-net-pci,netdev=vmnet,mac=#{node[:public_mac]}"
ARGS2 = "vmnet-bridged,id=vmnet,ifname=#{node[:public_ifname]}"
# Create a new adapter for inter-VM communication
qemu.extra_qemu_args = %W(-device #{ARGS1} -netdev #{ARGS2})
end
# WORKAROUND TO RUN ansible only once
# Run provisiones only when in the last node
if node[:name] == boxes[-1][:name]
# Set static IP on external network - Run Internal vmnet-bridged ansible provisioner
nodeconfig.vm.provision :ansible do |ansible|
ansible.compatibility_mode = "2.0"
ansible.playbook = "fixIP.yml"
ansible.host_vars = fixIP_host_var
ansible.limit = "all"
end
# Provisioning Server
nodeconfig.vm.provision :ansible do |ansible|
ansible.compatibility_mode = "2.0"
ansible.playbook = "main.yml"
ansible.limit = "all"
ansible.become = true
ansible.groups = {
"kubernetes" => ["kube1", "kube2", "kube3"],
"kubernetes_master" => ["kube1"],
"kubernetes_master:vars" => {
kubernetes_role: "master",
swapfile_path: "/dev/mapper/vagrant--vg-swap_1",
kubernetes_apiserver_advertise_address: "192.168.1.71"
},
"kubernetes_node" => ["kube2", "kube3"],
"kubernetes_node:vars" => {
kubernetes_role: "node",
swapfile_path: "/dev/mapper/vagrant--vg-swap_1"
}
}
end
end
end
end
end