---

- set_fact: drbdtop_install_mode='none'
  tags: drbd

- name: Detect if drbd is installed
  stat: path=/usr/local/bin/drbdtop
  register: drbdtop_bin
  tags: drbd

- when: not drbdtop_bin.stat.exists
  set_fact: drbdtop_install_mode='install'
  tags: drbd

- when: drbdtop_bin.stat.exists
  block:
    - name: Detect installed version
      shell: /usr/local/bin/drbdtop -v 2>&1 | perl -pe 's/^[^\d]//'
      changed_when: False
      register: drbdtop_current_version
    - set_fact: drbdtop_current_version={{ drbdtop_current_version.stdout }}
  tags: drbd

- when: drbdtop_bin.stat.exists and drbdtop_current_version != drbdtop_version
  set_fact: drbdtop_install_mode='upgrade'
  tags: drbd

