- name: Prerequisites
  include_tasks: prerequisites.yml


- name: Download k3s install script
  get_url:
    url: https://get.k3s.io
    dest: /tmp/install-k3s.sh
    mode: 0755


- name: Create k3s config file
  template:
    src: ../templates/config.yml.j2
    dest: "/home/{{ ansible_user }}/k3s_config.yml"


- name: Only run uninstall script if it exists
  become: true
  shell: /usr/local/bin/k3s-uninstall.sh
  args:
    removes: /usr/local/bin/k3s-uninstall.sh
  

- name: Execute k3s install script providing a config.yml
  shell: "/tmp/install-k3s.sh --config /home/{{ ansible_user }}/k3s_config.yml server"


- name: Copy kube config file back to local machine
  fetch:
    src: /etc/rancher/k3s/k3s.yaml
    dest: /home/remy/.kube/config-home
    flat: yes
  run_once: true