---
- block:
    - name: Install the production gcube keys into the dataminer webapp
      get_url: url={{ item.url }} dest={{ smartgears_instance_path }}/webapps/{{ dataminer_wps_name }}/ecocfg/PARALLEL_PROCESSING/{{ item.name }} owner={{ smartgears_user }} group={{ smartgears_user }} mode=0600
      with_items: '{{ gcube_production_security_keys }}'
      notify: Restart smartgears
      when: install_gcube_prod_key

    - name: Remove the production gcube keys from the dataminer webapp
      file: dest={{ smartgears_instance_path }}/webapps/{{ dataminer_wps_name }}/ecocfg/PARALLEL_PROCESSIN/{{ item.name }} state=absent
      with_items: '{{ gcube_production_security_keys }}'
      notify: Restart smartgears 
      when: not install_gcube_prod_key

    - name: Install the devel gcube keys into the dataminer webapp
      get_url: url={{ item.url }} dest={{ smartgears_instance_path }}/webapps/{{ dataminer_wps_name }}/ecocfg/PARALLEL_PROCESSING/{{ item.name }} owner={{ smartgears_user }} group={{ smartgears_user }} mode=0600
      with_items: '{{ gcube_dev_security_keys }}'
      notify: Restart smartgears
      when: install_gcube_dev_key

    - name: Remove the devel gcube keys from the dataminer webapp
      file: dest={{ smartgears_instance_path }}/webapps/{{ dataminer_wps_name }}/ecocfg/PARALLEL_PROCESSING/{{ item.name }} state=absent
      with_items: '{{ gcube_dev_security_keys }}'
      notify: Restart smartgears 
      when: not install_gcube_dev_key

    - name: Install the preprod gcube keys into the dataminer webapp
      get_url: url={{ item.url }} dest={{ smartgears_instance_path }}/webapps/{{ dataminer_wps_name }}/ecocfg/PARALLEL_PROCESSING/{{ item.name }} owner={{ smartgears_user }} group={{ smartgears_user }} mode=0600
      with_items: '{{ gcube_preprod_security_keys }}'
      notify: Restart smartgears
      when: install_gcube_preprod_key

    - name: Remove the preprod gcube keys from the dataminer webapp
      file: dest={{ smartgears_instance_path }}/webapps/{{ dataminer_wps_name }}/ecocfg/PARALLEL_PROCESSING/{{ item.name }} state=absent
      with_items: '{{ gcube_preprod_security_keys }}'
      notify: Restart smartgears 
      when: not install_gcube_preprod_key

    - name: Remove obsolete or expired gcube keys from the dataminer webapp
      file: dest={{ smartgears_instance_path }}/webapps/{{ dataminer_wps_name }}/ecocfg/PARALLEL_PROCESSING/{{ item.name }} state=absent
      with_items: '{{ gcube_old_security_keys }}'
      notify: Restart smartgears 
      when: not install_gcube_preprod_key

  become: True
  become_user: '{{ smartgears_user }}'
  tags: [ 'dataminer', 'gcube_key', 'wps' ]