---

- name: Set default install mode
  set_fact: ldap2pg_install_mode='none'
  tags: pg

- name: Check if ldap2pg is installed
  stat: path=/usr/local/bin/ldap2pg
  register: ldap2pg_bin
  tags: pg

- name: Check installed version
  shell: ldap2pg -V | head -1 | sed -E 's/ldap2pg v(\d+)/\1/'
  register: ldap2pg_current_version
  when: ldap2pg_bin.stat.exists
  changed_when: False
  tags: pg

- name: Set install mode
  set_fact: ldap2pg_install_mode='install'
  when: not ldap2pg_bin.stat.exists
  tags: pg

- name: Set install_mode to upgrade
  set_fact: ldap2pg_install_mode='upgrade'
  when: ldap2pg_bin.stat.exists and ldap2pg_current_version.stdout != ldap2pg_version
  tags: pg
