diff --git a/Ansible/Playbooks/Talos/collections/requirements.yaml b/Ansible/Playbooks/Talos/collections/requirements.yaml new file mode 100644 index 0000000..3ffb535 --- /dev/null +++ b/Ansible/Playbooks/Talos/collections/requirements.yaml @@ -0,0 +1,6 @@ +--- +collections: + - name: ansible.utils + - name: community.general + - name: ansible.posix + - name: kubernetes.core \ No newline at end of file diff --git a/Ansible/Playbooks/Talos/inventory/group_vars/all.yaml b/Ansible/Playbooks/Talos/inventory/group_vars/all.yaml new file mode 100644 index 0000000..403eaac --- /dev/null +++ b/Ansible/Playbooks/Talos/inventory/group_vars/all.yaml @@ -0,0 +1,27 @@ +os: "linux" +arch: "amd64" + +talos_version: v1.7.0 +talosctl_version: v1.7.5 +control_plane_ip: 192.168.200.61 + +control_plane_2: 192.168.200.62 +control_plane_3: 192.168.200.63 + +worker_1: 192.168.200.64 +worker_2: 192.168.200.65 + +config_directory: "/home/{{ ansible_user }}/.talos" +config_file: "/home/{{ ansible_user }}/.talos/talosconfig" + +kube_vip_version: "v0.8.0" +vip_interface: eth0 +vip: 192.168.3.50 + +metallb_version: v0.13.12 +lb_range: 192.168.3.80-192.168.3.90 +lb_pool_name: first-pool + +ansible_user: ubuntu +ansible_become: true +ansible_become_method: sudo diff --git a/Ansible/Playbooks/Talos/inventory/hosts.ini b/Ansible/Playbooks/Talos/inventory/hosts.ini new file mode 100644 index 0000000..0d5ca6a --- /dev/null +++ b/Ansible/Playbooks/Talos/inventory/hosts.ini @@ -0,0 +1,13 @@ +# Make sure Ansible host has access to these devices +# Good idea to snapshot all machines and deploy uing cloud-template +[ansible] +127.0.0.1 ansible_connection=local + +[servers] +server1 ansible_host=192.168.3.61 +server2 ansible_host=192.168.3.62 +server3 ansible_host=192.168.3.63 + +[agents] +agent1 ansible_host=192.168.3.64 +agent2 ansible_host=192.168.3.65 diff --git a/Ansible/Playbooks/Talos/roles/add-workers/tasks/main.yaml b/Ansible/Playbooks/Talos/roles/add-workers/tasks/main.yaml new file mode 100644 index 0000000..96996b1 --- /dev/null +++ b/Ansible/Playbooks/Talos/roles/add-workers/tasks/main.yaml @@ -0,0 +1,11 @@ +--- +# Generate Machine Configurations. This is using the qemu agent as per: https://www.talos.dev/v1.7/talos-guides/install/virtualized-platforms/proxmox/ +- name: Apply config to first worker + ansible.builtin.command: + cmd: talosctl apply-config --insecure --nodes {{ worker_1 }} --file {{ config_directory }}/worker.yaml + changed_when: true + +- name: Apply config to second worker + ansible.builtin.command: + cmd: talosctl apply-config --insecure --nodes {{ worker_2 }} --file {{ config_directory }}/worker.yaml + changed_when: true diff --git a/Ansible/Playbooks/Talos/roles/apply-config/tasks/main.yaml b/Ansible/Playbooks/Talos/roles/apply-config/tasks/main.yaml new file mode 100644 index 0000000..55dede7 --- /dev/null +++ b/Ansible/Playbooks/Talos/roles/apply-config/tasks/main.yaml @@ -0,0 +1,16 @@ +--- +# Generate Machine Configurations. This is using the qemu agent as per: https://www.talos.dev/v1.7/talos-guides/install/virtualized-platforms/proxmox/ +- name: Apply config to first node + ansible.builtin.command: + cmd: talosctl apply-config --insecure --nodes {{ control_plane_ip }} --file {{ config_directory }}/controlplane.yaml + changed_when: true + +- name: Apply config to second node + ansible.builtin.command: + cmd: talosctl apply-config --insecure --nodes {{ control_plane_2 }} --file {{ config_directory }}/controlplane.yaml + changed_when: true + +- name: Apply config to first node + ansible.builtin.command: + cmd: talosctl apply-config --insecure --nodes {{ control_plane_3 }} --file {{ config_directory }}/controlplane.yaml + changed_when: true diff --git a/Ansible/Playbooks/Talos/roles/configure-cluster/tasks/main.yaml b/Ansible/Playbooks/Talos/roles/configure-cluster/tasks/main.yaml new file mode 100644 index 0000000..fb03399 --- /dev/null +++ b/Ansible/Playbooks/Talos/roles/configure-cluster/tasks/main.yaml @@ -0,0 +1,11 @@ +--- +- name: Check that the config file doesn't already exist + ansible.builtin.stat: + path: "{{ config_file }}" + register: stat_result + +# Generate Machine Configurations. This is using the qemu agent as per: https://www.talos.dev/v1.7/talos-guides/install/virtualized-platforms/proxmox/ +- name: Generate config for cluster + when: "not stat_result.stat.exists" + ansible.builtin.command: talosctl gen config talos-proxmox-cluster https://{{ control_plane_ip }}:6443 --output-dir {{ config_directory }} --install-image factory.talos.dev/installer/ce4c980550dd2ab1b17bbf2b08801c7eb59418eafe8f279833297925d67c7515:{{ talos_version }} + changed_when: true diff --git a/Ansible/Playbooks/Talos/roles/configure-talosctl/tasks/main.yaml b/Ansible/Playbooks/Talos/roles/configure-talosctl/tasks/main.yaml new file mode 100644 index 0000000..b14ec7d --- /dev/null +++ b/Ansible/Playbooks/Talos/roles/configure-talosctl/tasks/main.yaml @@ -0,0 +1,26 @@ +--- +# Update TalosCTL +- name: Update TalosCTL configs + ansible.builtin.command: talosctl config endpoint {{ control_plane_ip }} --talosconfig {{ config_file }} + changed_when: true + +- name: Update TalosCTL configs + ansible.builtin.command: talosctl config node {{ control_plane_ip }} --talosconfig {{ config_file }} + changed_when: true + + ################################# + # WAIT FOR REBOOT & BOOTSTRAP # + ################################# +- name: Keep trying to bootstrap + ansible.builtin.command: + cmd: "talosctl bootstrap --talosconfig {{ config_file }}" + register: bootstrap_result + retries: 10 + delay: 30 + until: bootstrap_result.rc == 0 + changed_when: bootstrap_result.rc == 0 + +# Grab Kubeconfig +- name: Get Kubeconfig + ansible.builtin.command: talosctl kubeconfig . --talosconfig {{ config_file }} + changed_when: true diff --git a/Ansible/Playbooks/Talos/roles/install-talosctl/tasks/main.yaml b/Ansible/Playbooks/Talos/roles/install-talosctl/tasks/main.yaml new file mode 100644 index 0000000..d049a94 --- /dev/null +++ b/Ansible/Playbooks/Talos/roles/install-talosctl/tasks/main.yaml @@ -0,0 +1,12 @@ +--- +# Ansible Playbook to install Talos +- name: Download talosctl for Linux (amd64) + ansible.builtin.get_url: + url: https://github.com/siderolabs/talos/releases/download/{{ talosctl_version }}/talosctl-linux-amd64 + dest: /usr/local/bin/talosctl + mode: '0755' # Make the binary executable + register: download_result # Register the result for debugging or verification + +- name: Display download result + ansible.builtin.debug: + var: download_result # Display the result of the download task diff --git a/Ansible/Playbooks/Talos/site.yaml b/Ansible/Playbooks/Talos/site.yaml new file mode 100644 index 0000000..31e2477 --- /dev/null +++ b/Ansible/Playbooks/Talos/site.yaml @@ -0,0 +1,37 @@ +# Hello, thanks for using my playbook, hopefully you can help to improve it. + +# Install TalosCTL on Ansible node +- name: Install TalosCTL + hosts: ansible + gather_facts: true # enables us to gather lots of useful variables: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/setup_module.html + become: true + roles: + - install-talosctl + +# Configure Cluster Configuration +- name: Configure Cluster + hosts: ansible + gather_facts: true + roles: + - configure-cluster + +# Apply Cluster Configuration +- name: Configure Cluster + hosts: ansible + gather_facts: true + roles: + - apply-config + +# Configure TalosCTL +- name: Configure TalosCTL + hosts: ansible + gather_facts: true + roles: + - configure-talosctl + +# Add Workers +- name: Add Workers + hosts: ansible + gather_facts: true + roles: + - add-workers