---
- hosts: localhost
  connection: local
  tasks:
    - fail:
        msg: "Profile ID must be passed in as profile_id"
      when: profile_id is not defined or profile_id == ""

    - fail:
        msg: "Volume Name must be passed in as volume_name"
      when: volume_name is not defined or volume_name == ""

    - fail:
        msg: "Volume Size must be passed in as volume_size"
      when: volume_size is not defined or volume_size == ""

    - fail:
        msg: "Girder Volume ID must be passed in as girder_volume_id"
      when: girder_volume_id is not defined or girder_volume_id == ""


    - ec2_vol:
        name: "ec2_{{ profile_id }}_{{ volume_name }}"
        volume_size: "{{ volume_size }}"
        region: "{{ volume_zone[:-1] }}"
        zone: "{{ volume_zone }}"
      register: vol

    - ec2_tag:
        resource: "{{ vol.volume_id }}"
        region: "{{ volume_zone[:-1] }}"
        state: present
        tags:
          profile_id: "{{ profile_id }}"

    # Patch the volume ID back to girder
    - girder:
        apiUrl: "{{ girder_api_url }}"
        token: "{{ girder_token }}"
        patch:
          path: "volumes/{{ girder_volume_id }}"
          data:
            ec2:
              id: "{{ vol.volume_id }}"
              status: "{{ vol.status }}"
      when: girder_api_url is defined and girder_token is defined

---
- hosts: localhost
  connection: local
  tasks:
    - fail:
        msg: "Profile ID must be passed in as profile_id"
      when: profile_id is not defined or profile_id == ""

    - fail:
        msg: "Volume Name must be passed in as volume_name"
      when: volume_name is not defined or volume_name == ""

    - fail:
        msg: "Volume Size must be passed in as volume_size"
      when: volume_size is not defined or volume_size == ""

    - fail:
        msg: "Girder Volume ID must be passed in as girder_volume_id"
      when: girder_volume_id is not defined or girder_volume_id == ""


    - ec2_vol:
        name: "ec2_{{ profile_id }}_{{ volume_name }}"
        volume_size: "{{ volume_size }}"
        region: "{{ volume_zone[:-1] }}"
        zone: "{{ volume_zone }}"
      register: vol

    - ec2_tag:
        resource: "{{ vol.volume_id }}"
        region: "{{ volume_zone[:-1] }}"
        state: present
        tags:
          profile_id: "{{ profile_id }}"

    # Patch the volume ID back to girder
    - girder:
        apiUrl: "{{ girder_api_url }}"
        token: "{{ girder_token }}"
        patch:
          path: "volumes/{{ girder_volume_id }}"
          data:
            ec2:
              id: "{{ vol.volume_id }}"
              status: "{{ vol.volume.status }}"
      when: girder_api_url is defined and girder_token is defined

Fix bug with patching volume status after attach
Fix bug with patching volume status after attach
