- name: Install packages
  package:
    name:
      - kubectl
      - jq # for decrypt_k8s_secret
      - helm
      - sops # Encrypt secrets
      - cfssl # For generating certs for self-hosted cluster
    state: present

# TODO: Make a FreeBSD package for kubeswitch or kubectx
# TODO: Make a FreeBSD package for stern

- name: Install scripts
  copy:
    src: "files/{{ item.src }}"
    dest: "{{ item.dest }}"
    mode: 0755
    owner: root
    group: wheel
  loop:
    - src: k
      dest: /usr/local/bin/k
    - src: ka
      dest: /usr/local/bin/ka
    - src: kd
      dest: /usr/local/bin/kd
    - src: kdel
      dest: /usr/local/bin/kdel
    - src: klog
      dest: /usr/local/bin/klog
    - src: ks
      dest: /usr/local/bin/ks
    - src: kshell
      dest: /usr/local/bin/kshell
    - src: kx
      dest: /usr/local/bin/kx
    - src: decrypt_k8s_secret
      dest: /usr/local/bin/decrypt_k8s_secret
    - src: k8s_delete_pipeline_runs
      dest: /usr/local/bin/

- import_tasks: tasks/freebsd.yaml
  when: 'os_flavor == "freebsd"'

- import_tasks: tasks/linux.yaml
  when: 'os_flavor == "linux"'

- include_tasks:
    file: tasks/peruser.yaml
    apply:
      become: yes
      become_user: "{{ initialize_user }}"
  loop: "{{ users | dict2items | community.general.json_query('[?value.initialize==`true`].key') }}"
  loop_control:
    loop_var: initialize_user
