diff --git a/.envrc.example b/.envrc.example index bf94fc0..d9b1196 100644 --- a/.envrc.example +++ b/.envrc.example @@ -7,3 +7,4 @@ export VM1_IP="192.168.56.80" export VM2_IP="192.168.56.81" export VM3_IP="192.168.56.82" export VAGRANT_NETWORK_PREFIX="192.168.56" +export K3S_URL_IP="192.168.56.250" diff --git a/vagrant/dev/ubuntu/ansible/copy_k8s_config.yaml b/vagrant/dev/ubuntu/ansible/copy_k8s_config.yaml index 7f42b08..554a31f 100644 --- a/vagrant/dev/ubuntu/ansible/copy_k8s_config.yaml +++ b/vagrant/dev/ubuntu/ansible/copy_k8s_config.yaml @@ -69,4 +69,4 @@ ansible.builtin.replace: path: /home/vagrant/.kube/config regexp: "127.0.0.1:6443" - replace: "{{ vm1_ip }}:6443" + replace: "{{ k3s_url_ip }}:6443" diff --git a/vagrant/dev/ubuntu/ansible/install_k3s_3node.yaml b/vagrant/dev/ubuntu/ansible/install_k3s_3node.yaml index 7902688..bd96230 100644 --- a/vagrant/dev/ubuntu/ansible/install_k3s_3node.yaml +++ b/vagrant/dev/ubuntu/ansible/install_k3s_3node.yaml @@ -8,13 +8,13 @@ - vars.yaml tasks: - - name: Debug IP variables - ansible.builtin.debug: - msg: - - "vm1_ip: {{ vm1_ip }}" - - "vm2_ip: {{ vm2_ip }}" - - "vm3_ip: {{ vm3_ip }}" - - "Current inventory_hostname: {{ inventory_hostname }}" + # - name: Debug IP variables + # ansible.builtin.debug: + # msg: + # - "vm1_ip: {{ vm1_ip }}" + # - "vm2_ip: {{ vm2_ip }}" + # - "vm3_ip: {{ vm3_ip }}" + # - "Current inventory_hostname: {{ inventory_hostname }}" - name: Check if k3s is already installed ansible.builtin.stat: @@ -55,7 +55,7 @@ - name: Install k3s on first node ansible.builtin.shell: | set -o pipefail - K3S_TOKEN=$(cat /opt/k3s-token) /bin/bash /tmp/k3s_install.sh server --cluster-init --disable traefik --disable servicelb --tls-san {{ vm1_ip }} --node-name vm1 --node-ip {{ vm1_ip }} + K3S_TOKEN=$(cat /opt/k3s-token) /bin/bash /tmp/k3s_install.sh server --cluster-init --disable traefik --disable servicelb --tls-san {{ k3s_url_ip }} --node-name vm1 --node-ip {{ vm1_ip }} if [ $? -eq 0 ]; then mkdir -p /home/vagrant/.kube && cp /etc/rancher/k3s/k3s.yaml /home/vagrant/.kube/config && chown vagrant:vagrant /home/vagrant/.kube/config fi @@ -89,9 +89,9 @@ {% else %} NODE_IP="{{ vm1_ip }}" {% endif %} - K3S_URL=https://{{ vm1_ip }}:6443 \ + K3S_URL=https://{{ k3s_url_ip }}:6443 \ K3S_TOKEN={{ k3s_token_content.stdout }} \ - INSTALL_K3S_EXEC="server --server https://{{ vm1_ip }}:6443 --disable traefik --disable servicelb --node-name={{ inventory_hostname }} --node-ip ${NODE_IP}" \ + INSTALL_K3S_EXEC="server --server https://{{ k3s_url_ip }}:6443 --disable traefik --disable servicelb --node-name={{ inventory_hostname }} --node-ip ${NODE_IP}" \ /bin/bash /tmp/k3s_install.sh 2>&1 exit_code=$? if [ $exit_code -ne 0 ]; then diff --git a/vagrant/dev/ubuntu/ansible/install_keepalived.yaml b/vagrant/dev/ubuntu/ansible/install_keepalived.yaml index 1dcc596..22c25fd 100644 --- a/vagrant/dev/ubuntu/ansible/install_keepalived.yaml +++ b/vagrant/dev/ubuntu/ansible/install_keepalived.yaml @@ -6,8 +6,7 @@ serial: 1 # Ensure tasks are executed one host at a time vars_files: - - vault.yml - - vars.yml + - vars.yaml vars: tailscale_host: "{{ hostvars[inventory_hostname]['tailscale_host'] }}" @@ -22,6 +21,9 @@ # msg: "{{ item.key }}: {{ item.value.ipv4 | map(attribute='address') | list }}" # with_dict: "{{ ansible_facts['network_interfaces'] }}" # when: ansible_facts['network_interfaces'] is defined + # - name: Debug k3s_url_ip + # ansible.builtin.debug: + # msg: "k3s_url_ip: {{ k3s_url_ip }}" - name: Detect interface with the desired IP range ansible.builtin.set_fact: @@ -65,7 +67,7 @@ auth_pass mysecret } virtual_ipaddress { - 192.168.56.250 + {{ k3s_url_ip }} } } owner: root diff --git a/vagrant/dev/ubuntu/ansible/vars.yaml b/vagrant/dev/ubuntu/ansible/vars.yaml index 2bc92dd..9a02a8e 100644 --- a/vagrant/dev/ubuntu/ansible/vars.yaml +++ b/vagrant/dev/ubuntu/ansible/vars.yaml @@ -3,6 +3,7 @@ vm1_ip: "{{ lookup('env', 'VM1_IP') | default('192.168.56.80', true) }}" vm2_ip: "{{ lookup('env', 'VM2_IP') | default('192.168.56.81', true) }}" vm3_ip: "{{ lookup('env', 'VM3_IP') | default('192.168.56.82', true) }}" +k3s_url_ip: "{{ lookup('env', 'K3S_URL_IP') | default('192.168.56.250', true) }}" workstation_ip: "{{ lookup('env', 'WORKSTATION_IP') | default('192.168.56.10', true) }}" network_prefix: "{{ lookup('env', 'VAGRANT_NETWORK_PREFIX') | default('192.168.56', true) }}"