---

- name: Ensure ldap2pg package is removed
  package: name=ldap2pg state=absent
  tags: pg

- when: ldap2pg_install_mode != 'none'
  block:
    - name: Download ldap2pg binary
      get_url:
        url: "{{ ldap2pg_archive_url }}"
        dest: /tmp/ldap2pg.tar.gz
        checksum: "sha256:{{ ldap2pg_archive_sha256 }}"

    - name: Extract ldap2pg archive
      unarchive:
        src: /tmp/ldap2pg.tar.gz
        dest: /usr/local/bin
        include:
          - ldap2pg
        owner: root
        group: root
        mode: 755
        remote_src: True

  tags: pg

- name: Install systemd unit
  template: src=ldap2pg.{{ item }}.j2 dest=/etc/systemd/system/ldap2pg.{{ item }}
  loop:
    - service
    - timer
  notify:
    - restart ldap2pg.service
    - restart ldap2pg.timer
  register: ldap2pg_units
  tags: pg

- name: Reload systemd
  systemd: daemon_reload=True
  when: ldap2pg_units.results | selectattr('changed','equalto',True) | list | length > 0
  tags: pg
