---

### tags:
###   base

- name: Install dependencies
  ansible.builtin.package:
    name: "{{ item }}"
    state: present
  loop:
    - python3-pip=20.0.2-5ubuntu1.6
  when:
  - "'kube_control_plane' in group_names"
  tags:
    - base

- name: Install pip dependencies
  ansible.builtin.pip:
    name: "{{ item }}"
  loop:
    - kubernetes
  when:
  - "'kube_control_plane' in group_names"
  tags:
    - base

- name: Install Helm plugins
  become: yes
  kubernetes.core.helm_plugin:
    plugin_path: "{{ item }}"
    state: present
  loop:
    - https://github.com/databus23/helm-diff
  when:
  - "'kube_control_plane' in group_names"
  tags:
    - base

- name: Install k9s on 1st k8s master
  ansible.builtin.get_url:
    url: 'https://github.com/derailed/k9s/releases/download/{{ kubernetes_tools_k9s_version | default("v0.25.18") }}/k9s_Linux_x86_64.tar.gz'
    dest: '/tmp/k9s_Linux_x86_64_{{ kubernetes_tools_k9s_version | default("v0.25.18") }}.tar.gz'
  when:
  - "'kube_control_plane' in group_names"
  tags:
    - base

- name: Extract k9s binary
  ansible.builtin.unarchive:
    src: '/tmp/k9s_Linux_x86_64_{{ kubernetes_tools_k9s_version | default("v0.25.18") }}.tar.gz'
    dest: "/tmp/"
    remote_src: yes
  when:
  - "'kube_control_plane' in group_names"
  tags:
    - base

- name: Move extracted k9s binary
  ansible.builtin.copy:
    src: /tmp/k9s
    dest: /usr/bin/k9s
    mode: 0755
    owner: root
    group: root
    remote_src: yes
  become: yes
  when:
  - "'kube_control_plane' in group_names"
  tags:
    - base

- name: "Enable PodSecurity"
  include_tasks: podsecurity.yml
  args:
    apply:
      tags:
        - base
  tags:
    - base
