diff --git a/playbook.yml b/playbook.yml index d9b0c01..1047265 100644 --- a/playbook.yml +++ b/playbook.yml @@ -100,33 +100,36 @@ - cluster.k3s.yml tasks: - - name: Install K3s binary (initial node) - ansible.builtin.shell: - cmd: "curl -sfL https://get.k3s.io | sh -s - server --cluster-init --disable local-storage,traefik --tls-san {{ cluster.virtualip | ansible.utils.ipaddr('address') }}" + - name: Initial node + block: + + - name: Install K3s binary + ansible.builtin.shell: + cmd: "curl -sfL https://get.k3s.io | sh -s - server --cluster-init --disable local-storage,traefik --tls-san {{ cluster.virtualip | ansible.utils.ipaddr('address') }}" + + - name: Retrieve token + ansible.builtin.slurp: + src: /var/lib/rancher/k3s/server/token + register: k3s_token + + - name: Store in dictionary + ansible.builtin.set_fact: + cluster: "{{ cluster | combine( { 'token': ( k3s_token.content | b64decode | trim ) } ) }}" + when: inventory_hostname == ansible_play_hosts[0] - - name: Retrieve token (from initial node) - ansible.builtin.slurp: - src: /var/lib/rancher/k3s/server/token - register: k3s_token - when: inventory_hostname == ansible_play_hosts[0] - - - ansible.builtin.debug: - var: k3s_token - - ansible.builtin.debug: - var: cluster - - - name: Store in dictionary - ansible.builtin.set_fact: - cluster: "{{ cluster | combine( { 'token': ( k3s_token.content | b64decode | trim ) } ) }}" - ansible.builtin.debug: var: cluster - - name: Install K3s binary (additional nodes) - ansible.builtin.shell: - cmd: "curl -sfL https://get.k3s.io | sh -s - server --disable local-storage,traefik" - environment: - K3S_TOKEN: "{{ cluster.token }}" - K3S_URL: "{{ 'https://' + ( cluster.virtualip | ansible.utils.ipaddr('address') ) + ':6443' }}" + - name: Additional nodes + block: + + - name: Install K3s binary + ansible.builtin.shell: + cmd: "curl -sfL https://get.k3s.io | sh -s - server --disable local-storage,traefik" + environment: + K3S_TOKEN: "{{ cluster.token }}" + K3S_URL: "{{ 'https://' + ( cluster.virtualip | ansible.utils.ipaddr('address') ) + ':6443' }}" + when: inventory_hostname != ansible_play_hosts[0]