update: add installation scripts for Vagrant and Ansible, enhance k3s setup, and improve provisioning process
This commit is contained in:
parent
ff55197c58
commit
514e05a1f6
5 changed files with 103 additions and 22 deletions
|
|
@ -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."
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue