---

- block:
  - name: Create DDS Install Directory
    file:
      path: "{{ dds_install_dir }}"
      state: directory
      mode: 0755

  - name: Download RTI DDS License
    get_url:
      url: "{{ dds_license_url }}"
      dest: "{{ dds_license_dest }}"
      checksum: "sha1:{{ dds_license_sha1sum }}"
      use_proxy: no
    register: dds_license_downloaded
    retries: 2
    delay: 10
    until: dds_license_downloaded is succeeded

  - name: Download RTI DDS
    get_url:
      url: "{{ dds_package_url }}"
      dest: "{{ dds_package_dest }}"
      checksum: "sha1:{{ dds_package_sha1sum }}"
      use_proxy: no
    register: dds_downloaded
    retries: 2
    delay: 10
    until: dds_downloaded is succeeded

  - name: Unarchived installed version directory
    stat:
      path: "{{ dds_install_dir }}/{{ dds_version }}"
    register: dds_untar_dir

  - name: Install RTI DDS
    unarchive:
      src: "{{ dds_package_dest }}"
      dest: "{{ dds_install_dir }}"
    when: dds_downloaded.changed or dds_untar_dir.stat.isdir is not defined
    register: dds_installed

  - name: Create rtiddsgen symlink
    file:
      src: "{{ dds_install_dir }}/{{ dds_version }}/bin/rtiddsgen"
      dest: "{{ dds_install_dir }}/{{ dds_version }}/bin/rtiddsgen.sh"
      state: link
    when: dds_installed.changed

  become: yes
