Ver Fonte

updated ansbile bootstrap

Breandan Dezendorf há 2 anos atrás
pai
commit
cbb34dac3a

+ 6 - 0
homelab/ansible/install_k3s_wrapper.sh

@@ -0,0 +1,6 @@
+#!/bin/bash
+
+TOKEN=$(cat /tmp/node-token)
+URL='https://192.168.1.87:6443'
+
+K3S_TOKEN=${TOKEN} K3S_URL=${URL} /bin/sh /tmp/k3s.sh

+ 4 - 4
homelab/ansible/inventory

@@ -1,9 +1,9 @@
 [nodes]
-#thin1.dezendorf.net
-#thin2.dezendorf.net
-#thin3.dezendorf.net
+thin1.dezendorf.net
+thin2.dezendorf.net
+thin3.dezendorf.net
 thick1.dezendorf.net
-#thick2.dezendorf.net
+thick2.dezendorf.net
 
 [master]
 tesseract.dezendorf.net

+ 1 - 0
homelab/ansible/node-token/tesseract.dezendorf.net/var/lib/rancher/k3s/server/node-token

@@ -0,0 +1 @@
+K10b8bfa0853d1649d1b8714633cc78258241dc04d1dd6ca0784721c01c3c90621b::server:034cc872238e43e4b45eea19b1b999eb

+ 24 - 13
homelab/ansible/setup.yaml

@@ -11,25 +11,34 @@
     become: true
 
 - name: Get k3s bits
-  hosts: all
+  hosts: master
   remote_user: bwdezend
   vars:
     node_token: ""
   tasks:
   - name: get agent token
-    slurp:
+    fetch:
       src: '/var/lib/rancher/k3s/server/node-token'
-    register: node_token
+      dest: 'node-token'
     become: true
-    when: inventory_hostname in groups['master']
 
-  - name: Install agent
-    command: curl -sfL https://get.k3s.io --output /tmp/k3s.sh
-    become: true
-    args:
-      creates: /tmp/k3s.sh
-    when: inventory_hostname in groups['nodes']
+- name: Install k3s if not present
+  hosts: nodes
+  vars:
+    node_token: "{{ lookup('file', 'node-token/tesseract.dezendorf.net/var/lib/rancher/k3s/server/node-token') }}"
+  tasks:
+  - name: add node-token
+    copy:
+      dest: "/tmp/node-token"
+      content: |
+        "{{ node_token }}"
 
+  - name: get k3s installer
+    get_url:
+      dest: /tmp/k3s.sh
+      url: https://get.k3s.io
+      mode: '0775'
+    become: true
 
   - name: Fix DNS
     copy:
@@ -39,11 +48,13 @@
     become: true
 
   - name: install
-    command: /bin/sh /tmp/k3s.sh
+    ansible.builtin.shell: /tmp/k3s.sh
     environment:
-      K3S_URL: https://192.168.1.87:6443
+      K3S_URL: "https://192.168.1.87:6443"
       K3S_TOKEN: "{{ node_token }}"
+    when: inventory_hostname in groups['nodes']
     args:
       creates: /var/lib/rancher/k3s/agent
-    when: inventory_hostname in groups['nodes']
+
+