Deploying RKE2 with Ansible
Deploying RKE2 with Ansible
In this post, I’ll walk you through deploying RKE2 on six VMs using Ansible. I’ll be using an Ansible script from JimsGarage. Before proceeding, make sure you have an Ansible VM set up, as this guide assumes that you do.
Configuring the Ansible Script
Configure the
hosts.ini
File:The first step is to add the IP addresses of your VMs to the
hosts.ini
file located in theinventory
directory.1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Ensure the Ansible host has access to these devices. # It's a good idea to snapshot all machines and deploy using cloud-init. # Make sure the Ansible machine has the SSH key from the cloud-init VMs. # The SSH key should be placed in the .ssh directory and named id_rsa. [servers] server1 ansible_host=192.168.2.211 server2 ansible_host=192.168.2.221 server3 ansible_host=192.168.2.231 [agents] agent1 ansible_host=192.168.2.212 agent2 ansible_host=192.168.2.222 agent3 ansible_host=192.168.2.232
Configure the
all.yaml
File:Next, modify the
all.yaml
file located in the/inventory/group_vars/
directory. I recommend not changing the versions of MetalLB and Kube-VIP, as they could be incompatible with other versions, but this configuration works:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
os: "linux" arch: "amd64" kube_vip_version: "v0.8.0" vip_interface: eth0 vip: 192.168.2.240 metallb_version: v0.13.12 lb_range: 192.168.2.241-192.168.2.250 lb_pool_name: lb-pool rke2_version: "v1.29.4+rke2r1" rke2_install_dir: "/usr/local/bin" rke2_binary_url: "https://github.com/rancher/rke2/releases/download//rke2.linux-amd64" ansible_user: rke2 ansible_become: true ansible_become_method: sudo
Ensure SSH Key Availability:
The SSH key you used when setting up your VMs with cloud-init must be available on the Ansible VM. Place this SSH key in the
.ssh
directory of the Ansible VM with the nameid_rsa
. This will allow Ansible to connect to your VMs securely.1 2 3
#C opy the SSH key to the Ansible VM .ssh directory cp /path/to/your/id_rsa ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa
Running the Ansible Script
Once everything is configured, navigate to the directory where site.yaml
is located and run the following command:
1
ansible-playbook site.yaml -i inventory/hosts.ini --key-file ~/.ssh/id_rsa
I hope the script runs smoothly for you on the first try. If you encounter any issues, I recommend seeking support in the JimsGarage Discord channel.