The error says:
Unable to detach root volume 'vol-0a75b01a93b9e6778' from instance
'i-065d2c70867a8f874'

Which makes sense.

Checking on 
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html:

"If an EBS volume is the root device of an instance, you must stop the
instance before you can detach the volume."


So, try stopping the instance first?

On Fri, 7 Feb 2020 at 08:13, Sandy Hung <[email protected]> wrote:
>
> dear all:
>
> please help me how to detach volume
>
>  - name: Detach a Volume
>      ec2_vol:
>        id: vol-0a75b01a93b9e6778
>        region: "{{ region }}"
>        instance: None
>
> PLAY [localhost] 
> *******************************************************************************************************
>
> TASK [Create Snapshot EC2] 
> *********************************************************************************************
> changed: [localhost]
>
> TASK [Create a Volume] 
> *************************************************************************************************
> [WARNING]: The value 1000 (type int) in a string field was converted to 
> u'1000' (type string). If this does not look
> like what you expect, quote the entire value to ensure it does not change.
>
> changed: [localhost]
>
> TASK [Detach a Volume] 
> *************************************************************************************************
> An exception occurred during task execution. To see the full traceback, use 
> -vvv. The error was: 
> <Response><Errors><Error><Code>IncorrectState</Code><Message>Unable to detach 
> root volume 'vol-0a75b01a93b9e6778' from instance 
> 'i-065d2c70867a8f874'</Message></Error></Errors><RequestID>3dbf5aee-9647-44de-8820-e8d6db1331d7</RequestID></Response>
> fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback 
> (most recent call last):\n  File 
> \"/root/.ansible/tmp/ansible-tmp-1581059554.97-79519864016870/AnsiballZ_ec2_vol.py\",
>  line 102, in <module>\n    _ansiballz_main()\n  File 
> \"/root/.ansible/tmp/ansible-tmp-1581059554.97-79519864016870/AnsiballZ_ec2_vol.py\",
>  line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, 
> ANSIBALLZ_PARAMS)\n  File 
> \"/root/.ansible/tmp/ansible-tmp-1581059554.97-79519864016870/AnsiballZ_ec2_vol.py\",
>  line 40, in invoke_module\n    
> runpy.run_module(mod_name='ansible.modules.cloud.amazon.ec2_vol', 
> init_globals=None, run_name='__main__', alter_sys=True)\n  File 
> \"/usr/lib/python2.7/runpy.py\", line 188, in run_module\n    fname, loader, 
> pkg_name)\n  File \"/usr/lib/python2.7/runpy.py\", line 82, in 
> _run_module_code\n    mod_name, mod_fname, mod_loader, pkg_name)\n  File 
> \"/usr/lib/python2.7/runpy.py\", line 72, in _run_code\n    exec code in 
> run_globals\n  File 
> \"/tmp/ansible_ec2_vol_payload_ULdCkg/ansible_ec2_vol_payload.zip/ansible/modules/cloud/amazon/ec2_vol.py\",
>  line 619, in <module>\n  File 
> \"/tmp/ansible_ec2_vol_payload_ULdCkg/ansible_ec2_vol_payload.zip/ansible/modules/cloud/amazon/ec2_vol.py\",
>  line 597, in main\n  File 
> \"/tmp/ansible_ec2_vol_payload_ULdCkg/ansible_ec2_vol_payload.zip/ansible/modules/cloud/amazon/ec2_vol.py\",
>  line 446, in detach_volume\n  File 
> \"/usr/local/lib/python2.7/dist-packages/boto/ec2/volume.py\", line 187, in 
> detach\n    dry_run=dry_run\n  File 
> \"/usr/local/lib/python2.7/dist-packages/boto/ec2/connection.py\", line 2420, 
> in detach_volume\n    return self.get_status('DetachVolume', params, 
> verb='POST')\n  File 
> \"/usr/local/lib/python2.7/dist-packages/boto/connection.py\", line 1227, in 
> get_status\n    raise self.ResponseError(response.status, response.reason, 
> body)\nboto.exception.EC2ResponseError: EC2ResponseError: 400 Bad 
> Request\n<?xml version=\"1.0\" 
> encoding=\"UTF-8\"?>\n<Response><Errors><Error><Code>IncorrectState</Code><Message>Unable
>  to detach root volume 'vol-0a75b01a93b9e6778' from instance 
> 'i-065d2c70867a8f874'</Message></Error></Errors><RequestID>3dbf5aee-9647-44de-8820-e8d6db1331d7</RequestID></Response>\n",
>  "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact 
> error", "rc": 1}
>
> PLAY RECAP 
> *************************************************************************************************************
> localhost                  : ok=2    changed=2    unreachable=0    failed=1   
>  skipped=0    rescued=0    ignored=0
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/ba64f1c6-397a-4c5d-8348-2e366b839577%40googlegroups.com.



-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwPspsGPhq5DfkO09fqakH1vXi6Zgu874PrpErpwMBBRYw%40mail.gmail.com.

Reply via email to