---
- name: Packages
  hosts: nodes
  remote_user: bwdezend

  tasks:
  - name: Install nfs-common
    apt:
      name: nfs-common
      state: present
    become: true

  - name: Install open-iscsi
    apt:
      name: open-iscsi
      state: present
    become: true

- name: Get k3s bits
  hosts: master
  remote_user: bwdezend
  vars:
    node_token: ""
  tasks:
  - name: get agent token
    fetch:
      src: '/var/lib/rancher/k3s/server/node-token'
      dest: 'node-token'
    become: true

- 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:
      src: resolv.conf
      dest: /etc/resolv.conf
    when: inventory_hostname in groups['nodes']
    become: true

  - name: install
    ansible.builtin.shell: /tmp/k3s.sh
    environment:
      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



