---
- name: install coverity-required debian packages
  apt:
    name:
      - curl
  tags: [coverity]

- name: check if coverity needs to be installed
  stat:
    path: "/opt/coverity/{{ coverity_version }}/"
  register: coverity_stat
  tags: [coverity]

- name: install coverity if required
  when: coverity_stat.stat.exists == False
  tags: [coverity]
  block:
    - name: copy coverity installer
      copy:
        src: "{{ coverity_installer_file }}"
        dest: "/tmp/{{ coverity_installer_file }}"
        mode: 0750
      register: coverity_copy
      ignore_errors: yes

    - name: coverity download hint
      ansible.builtin.fail:
        msg: "Login and download {{ coverity_installer_file }} from https://scan.coverity.com/download (Linux64) and put it into osmo-ci/ansible/files."
      when: coverity_copy.failed == True

    - name: create /opt/coverity/{{ coverity_version }}/
      file:
        path: /opt/coverity/{{ coverity_version }}/
        state: directory

    - name: unpack coverity
      unarchive:
        src: "/tmp/{{ coverity_installer_file }}"
        dest: /opt/coverity/{{ coverity_version }}
        remote_src: yes

    - name: create link /opt/coverity/current
      shell: rm -vf /opt/coverity/current && ln -svf /opt/coverity/{{ coverity_version }}/* /opt/coverity/current
