update: add installation scripts for Vagrant and Ansible, enhance k3s setup, and improve provisioning process

This commit is contained in:
jon brookes 2025-08-07 19:08:46 +01:00
parent ff55197c58
commit 514e05a1f6
5 changed files with 103 additions and 22 deletions

View file

@ -0,0 +1 @@
export VAGRANT_BRIDGE=<preferred interface to bride to>

View file

@ -109,4 +109,39 @@
msg: "K3S installation failed on {{ inventory_hostname }}"
when: inventory_hostname != 'vm1' and not k3s_binary.stat.exists and k3s_install_result.rc != 0
- name: Ensure /home/vagrant/.kube directory exists
ansible.builtin.file:
path: /home/vagrant/.kube
state: directory
owner: vagrant
group: vagrant
mode: '0700'
- name: Copy kubeconfig to vagrant user
ansible.builtin.copy:
src: /etc/rancher/k3s/k3s.yaml
dest: /home/vagrant/.kube/config
owner: vagrant
group: vagrant
mode: '0600'
remote_src: true
- name: Ensure KUBECONFIG is set in vagrant .bashrc
ansible.builtin.lineinfile:
path: /home/vagrant/.bashrc
line: 'export KUBECONFIG=~/.kube/config'
state: present
insertafter: EOF
owner: vagrant
group: vagrant
mode: '0644'
- name: Ensure kubectl completion is sourced in vagrant .bashrc
ansible.builtin.lineinfile:
path: /home/vagrant/.bashrc
line: 'source <(kubectl completion bash)'
state: present
insertafter: EOF
owner: vagrant
group: vagrant
mode: '0644'

View file

@ -16,14 +16,15 @@ sudo chmod 700 /home/vagrant/.ssh
# Copy the Vagrant private keys (these will be synced by Vagrant)
for i in {1..3}; do
sudo -u vagrant cp /vagrant/.vagrant/machines/vm$i/virtualbox/private_key /home/vagrant/.ssh/vm${i}_key
sudo -u root cp /vagrant/.vagrant/machines/vm$i/virtualbox/private_key /root/.ssh/vm${i}_key
sudo chmod 600 /home/vagrant/.ssh/vm${i}_key
sudo chmod 600 /root/.ssh/vm${i}_key
done
# Disable host key checking for easier learning
echo "[defaults]" > /home/vagrant/.ansible/ansible.cfg
echo "host_key_checking = False" >> /home/vagrant/.ansible/ansible.cfg
cp /vagrant/ansible/* /home/vagrant/ansible/
ANSIBLE_DIR=/home/vagrant/ansible
echo "Ansible directory: $ANSIBLE_DIR"
@ -42,6 +43,7 @@ if [ ! -d "venv" ]; then
exit 1
fi
echo "Virtual environment created and activated."
cp /vagrant/ansible/requirements.txt .
if [ -f "requirements.txt" ]; then
echo "Installing dependencies from requirements.txt..."
pip install --upgrade pip
@ -58,6 +60,11 @@ fi
ANSIBLE_VENV_DIR="$ANSIBLE_DIR/venv"
echo "Ansible virtual environment directory: $ANSIBLE_VENV_DIR"
ls -al "$ANSIBLE_VENV_DIR/bin/activate"
if [ -d "$ANSIBLE_VENV_DIR" ]; then
echo "Activating Ansible virtual environment..."
source "$ANSIBLE_VENV_DIR/bin/activate"
@ -70,13 +77,15 @@ echo ""
ansible --version
cp -r /vagrant/.vagrant/machines /home/vagrant/machines
cp -r ~/.vagrant/machines /home/vagrant/machines
if [ $? -ne 0 ]; then
echo "Ansible is not installed or not found in the virtual environment. Please check your installation."
exit 1
fi
cp -r /vagrant/ansible/* /home/vagrant/ansible/
chmod 600 /home/vagrant/machines/*/virtualbox/private_key
chmod 600 ~/machines/*/virtualbox/private_key
eval `ssh-agent -s`
ssh-add ~/machines/*/virtualbox/private_key
ssh-add # ~/machines/*/virtualbox/private_key
BASHRC="/home/vagrant/.bashrc"
BLOCK_START="# ADDED BY infctl provisioning"
@ -95,8 +104,23 @@ else
fi
echo ""
echo "user id is $(id)"
echo "group id is $(groups)"
ANSIBLE_HOST_KEY_CHECKING=False ansible --inventory-file ansible_inventory.ini -m ping all | cat
ls -al /home/vagrant/ansible
echo ""
cat /vagrant/ansible/ansible_inventory.ini
echo ""
echo "root keys"
ls -al ~/.ssh/vm*_key
echo "vagrant keys"
ls -al /home/vagrant/.ssh/vm*_key
ANSIBLE_HOST_KEY_CHECKING=False ansible --inventory-file /home/vagrant/ansible/ansible_inventory.ini -m ping all
if [ $? -ne 0 ]; then
echo "Ansible ping failed. Please check your Vagrant VMs and network configuration."
@ -104,12 +128,12 @@ if [ $? -ne 0 ]; then
fi
# install_keepalived.yaml
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook install_keepalived.yaml --inventory-file ansible_inventory.ini | cat
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook install_keepalived.yaml --inventory-file ansible_inventory.ini
if [ $? -ne 0 ]; then
echo "Ansible playbook failed. Please check your Vagrant VMs and network configuration."
exit 1
fi
echo "Keepalived installation completed successfully."
echo "Keepalived installation completed."
# install_k3s_3node.yaml
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook install_k3s_3node.yaml --inventory-file ansible_inventory.ini | cat
@ -117,4 +141,4 @@ if [ $? -ne 0 ]; then
echo "Ansible playbook failed. Please check your Vagrant VMs and network configuration."
exit 1
fi
echo "K3s installation completed successfully."