aboutsummaryrefslogtreecommitdiff
path: root/personal_infra/playbooks/roles/talos/tasks/main.yaml
diff options
context:
space:
mode:
authoralex <alex@pdp7.net>2023-02-19 02:59:35 +0100
committeralex <alex@pdp7.net>2023-02-19 03:13:56 +0100
commitfe18b2fb5283ff46aa8b66d9ffb317e18523be36 (patch)
tree6e83cdbbffbec093420b36952e1f58d0264397b1 /personal_infra/playbooks/roles/talos/tasks/main.yaml
parent9b3e07f3f5ace3ff339dc1f79734373f161b5620 (diff)
Add Talos support
Diffstat (limited to 'personal_infra/playbooks/roles/talos/tasks/main.yaml')
-rw-r--r--personal_infra/playbooks/roles/talos/tasks/main.yaml91
1 files changed, 91 insertions, 0 deletions
diff --git a/personal_infra/playbooks/roles/talos/tasks/main.yaml b/personal_infra/playbooks/roles/talos/tasks/main.yaml
new file mode 100644
index 00000000..bd294acb
--- /dev/null
+++ b/personal_infra/playbooks/roles/talos/tasks/main.yaml
@@ -0,0 +1,91 @@
+---
+- name: check node ready
+ k8s_info:
+ context: admin@{{ talos_host.talos_cluster }}
+ kind: Node
+ wait: true
+ wait_condition:
+ status: True
+ type: Ready
+ delegate_to: 127.0.0.1
+ register: nodes
+ ignore_errors: true
+
+- name: setup proxmox hosts
+ import_tasks: proxmox.yml
+ when: "'k8s_proxmox' in group_names and not 'resources' in nodes or nodes.resources|length == 0"
+
+- name: generate controlplane patch
+ copy:
+ content: |
+ machine:
+ install:
+ disk: {{ talos_host.install_disk }}
+ network:
+ hostname: {{ inventory_hostname }}
+ nameservers:
+ - {{ hostvars[proxmox.host].network.self_internal_ip }}
+ interfaces:
+ - interface: eth0
+ addresses:
+ - {{ network.ip }}/24
+ routes:
+ - network: 0.0.0.0/0
+ gateway: {{ hostvars[proxmox.host].network.self_internal_ip }}
+ dest: "{{ inventory_dir }}/talos/host-{{ inventory_hostname }}.patch"
+ delegate_to: 127.0.0.1
+ when: "not 'resources' in nodes or nodes.resources|length == 0"
+
+- name: generate controlplane config
+ shell:
+ cmd: talosctl gen config -t controlplane -o talos/host-{{ inventory_hostname }}.yaml --with-secrets <(ansible-vault view talos/secrets.yaml) --config-patch-control-plane @talos/host-{{ inventory_hostname }}.patch {{ talos_host.talos_cluster }} {{ talos_clusters[talos_host.talos_cluster].endpoint }}
+ chdir: "{{ inventory_dir }}"
+ delegate_to: 127.0.0.1
+ when: "not 'resources' in nodes or nodes.resources|length == 0"
+
+- name: apply config
+ command:
+ cmd: talosctl apply-config --insecure --nodes {{ ip.stdout }} --file talos/host-{{ inventory_hostname }}.yaml
+ chdir: "{{ inventory_dir }}"
+ delegate_to: 127.0.0.1
+ when: "not 'resources' in nodes or nodes.resources|length == 0"
+
+- name: generate talosconfig
+ shell:
+ cmd: talosctl gen config -t talosconfig -o talos/talosconfig-{{ talos_host.talos_cluster }} --with-secrets <(ansible-vault view talos/secrets.yaml) {{ talos_host.talos_cluster }} {{ talos_clusters[talos_host.talos_cluster].endpoint }}
+ chdir: "{{ inventory_dir }}"
+ delegate_to: 127.0.0.1
+ when: "not 'resources' in nodes or nodes.resources|length == 0"
+
+- name: bootstrap cluster
+ command:
+ cmd: talosctl bootstrap --nodes {{ inventory_hostname }} --talosconfig talos/talosconfig-{{ talos_host.talos_cluster }} -e {{ inventory_hostname }}
+ chdir: "{{ inventory_dir }}"
+ delegate_to: 127.0.0.1
+ register: bootstrap
+ until: bootstrap.rc == 0
+ retries: 8
+ delay: 1
+ when: "not 'resources' in nodes or nodes.resources|length == 0"
+
+- name: get kubeconfig
+ command:
+ cmd: talosctl kubeconfig --talosconfig talos/talosconfig-{{ talos_host.talos_cluster }} --nodes {{ inventory_hostname }} -e {{ inventory_hostname }} --force-context-name {{ talos_host.talos_cluster }}@admin
+ chdir: "{{ inventory_dir }}"
+ delegate_to: 127.0.0.1
+ when: "not 'resources' in nodes or nodes.resources|length == 0"
+
+- name: wait node ready
+ k8s_info:
+ context: admin@{{ talos_host.talos_cluster }}
+ kind: Node
+ wait: true
+ wait_condition:
+ status: True
+ type: Ready
+ delegate_to: 127.0.0.1
+ register: nodes
+ until: nodes.resources|length > 0
+ retries: 20
+ delay: 1
+ when: "not 'resources' in nodes or nodes.resources|length == 0"