---
- name: Check if crictl is installed
  ignore_errors: true
  command: crictl --version
  register: crictl_install_version

- name: Install crictl
  when: or (.crictl_install_version.error | empty | not) (.crictl_install_version.stdout | ne (printf "crictl version %s" .crictl_version))
  block:
    - name: Sync crictl binary to remote
      copy:
        src: >-
          {{ .binary_dir }}/crictl/{{ .crictl_version }}/{{ .binary_type }}/crictl-{{ .crictl_version }}-linux-{{ .binary_type }}.tar.gz
        dest: >-
          {{ .tmp_dir }}/crictl-{{ .crictl_version }}-linux-{{ .binary_type }}.tar.gz
    - name: Unpackage crictl binary
      command: |
        tar -xvf {{ .tmp_dir }}/crictl-{{ .crictl_version }}-linux-{{ .binary_type }}.tar.gz -C /usr/local/bin/
    - name: Generate crictl config file
      template:
        src: crictl.config
        dest: /etc/crictl.yaml
