# Ansible ec2 module for adhoc terminate...

**URL:** <https://forum.ansible.com/t/ansible-ec2-module-for-adhoc-terminate/22846>\
**Category:** Ansible Project\
**Created:** [October 20, 2016, 9:22pm UTC](https://forum.ansible.com/t/ansible-ec2-module-for-adhoc-terminate/22846 "2016-10-20T21:22:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sonny\_Chee](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@Sonny\_Chee](https://forum.ansible.com/u/Sonny_Chee)\
**Post date:** [October 20, 2016, 9:22pm UTC](https://forum.ansible.com/t/ansible-ec2-module-for-adhoc-terminate/22846/1 "2016-10-20T21:22:07Z")

</div>

Hey Guys,

I am having problems terminating ec2 instances with the following invocation:

$ AWS\_PROFILE=npu-root ansible -i ec2.py -u ec2-user --private-key ~/.ssh/BeteNar.pem tag\_db\_postgres -m ec2 -a ‘state=absent region=us-east-1’ -vvv

Which yielded the following, which seemed to imply there was an issue with my creds… however I can manually successfully ssh to each instance with ec2-user with the BeteNar.pem private key… Any help would be greatly appreciated.

Using /etc/ansible/ansible.cfg as config file  
\<[ec2-54-226-249-100.compute-1.amazonaws.com](http://ec2-54-226-249-100.compute-1.amazonaws.com)\> ESTABLISH SSH CONNECTION FOR USER: ec2-user  
\<[ec2-54-146-228-170.compute-1.amazonaws.com](http://ec2-54-146-228-170.compute-1.amazonaws.com)\> ESTABLISH SSH CONNECTION FOR USER: ec2-user  
\<[ec2-54-159-45-6.compute-1.amazonaws.com](http://ec2-54-159-45-6.compute-1.amazonaws.com)\> ESTABLISH SSH CONNECTION FOR USER: ec2-user  
\<[ec2-54-226-249-100.compute-1.amazonaws.com](http://ec2-54-226-249-100.compute-1.amazonaws.com)\> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o ‘IdentityFile=“/home/sonnychee/.ssh/BeteNar.pem”’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 -o ControlPath=/home/sonnychee/.ansible/cp/%h-%p-%r [ec2-54-226-249-100.compute-1.amazonaws.com](http://ec2-54-226-249-100.compute-1.amazonaws.com) ‘/bin/sh -c ‘"’"’( umask 77 && mkdir -p “`echo $HOME/.ansible/tmp/ansible-tmp-1476998334.12-260908329559293`” && echo ansible-tmp-1476998334.12-260908329559293=“`echo $HOME/.ansible/tmp/ansible-tmp-1476998334.12-260908329559293`” ) && sleep 0’“'”‘’  
\<[ec2-54-159-45-6.compute-1.amazonaws.com](http://ec2-54-159-45-6.compute-1.amazonaws.com)\> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o ‘IdentityFile=“/home/sonnychee/.ssh/BeteNar.pem”’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 -o ControlPath=/home/sonnychee/.ansible/cp/%h-%p-%r [ec2-54-159-45-6.compute-1.amazonaws.com](http://ec2-54-159-45-6.compute-1.amazonaws.com) ‘/bin/sh -c ‘"’"’( umask 77 && mkdir -p “`echo $HOME/.ansible/tmp/ansible-tmp-1476998334.12-91272603271631`” && echo ansible-tmp-1476998334.12-91272603271631=“`echo $HOME/.ansible/tmp/ansible-tmp-1476998334.12-91272603271631`” ) && sleep 0’“'”‘’  
\<[ec2-54-146-228-170.compute-1.amazonaws.com](http://ec2-54-146-228-170.compute-1.amazonaws.com)\> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o ‘IdentityFile=“/home/sonnychee/.ssh/BeteNar.pem”’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 -o ControlPath=/home/sonnychee/.ansible/cp/%h-%p-%r [ec2-54-146-228-170.compute-1.amazonaws.com](http://ec2-54-146-228-170.compute-1.amazonaws.com) ‘/bin/sh -c ‘"’"’( umask 77 && mkdir -p “`echo $HOME/.ansible/tmp/ansible-tmp-1476998334.12-151598906640500`” && echo ansible-tmp-1476998334.12-151598906640500=“`echo $HOME/.ansible/tmp/ansible-tmp-1476998334.12-151598906640500`” ) && sleep 0’“'”‘’  
\<[ec2-54-226-249-100.compute-1.amazonaws.com](http://ec2-54-226-249-100.compute-1.amazonaws.com)\> PUT /tmp/tmpAFySYk TO /home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-260908329559293/ec2  
\<[ec2-54-226-249-100.compute-1.amazonaws.com](http://ec2-54-226-249-100.compute-1.amazonaws.com)\> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o ‘IdentityFile=“/home/sonnychee/.ssh/BeteNar.pem”’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 -o ControlPath=/home/sonnychee/.ansible/cp/%h-%p-%r ‘[[ec2-54-226-249-100.compute-1.amazonaws.com](http://ec2-54-226-249-100.compute-1.amazonaws.com)]’  
\<[ec2-54-159-45-6.compute-1.amazonaws.com](http://ec2-54-159-45-6.compute-1.amazonaws.com)\> PUT /tmp/tmpeI7RXc TO /home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-91272603271631/ec2  
\<[ec2-54-159-45-6.compute-1.amazonaws.com](http://ec2-54-159-45-6.compute-1.amazonaws.com)\> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o ‘IdentityFile=“/home/sonnychee/.ssh/BeteNar.pem”’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 -o ControlPath=/home/sonnychee/.ansible/cp/%h-%p-%r ‘[[ec2-54-159-45-6.compute-1.amazonaws.com](http://ec2-54-159-45-6.compute-1.amazonaws.com)]’  
\<[ec2-54-146-228-170.compute-1.amazonaws.com](http://ec2-54-146-228-170.compute-1.amazonaws.com)\> PUT /tmp/tmpsnzihx TO /home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-151598906640500/ec2  
\<[ec2-54-146-228-170.compute-1.amazonaws.com](http://ec2-54-146-228-170.compute-1.amazonaws.com)\> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o ‘IdentityFile=“/home/sonnychee/.ssh/BeteNar.pem”’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 -o ControlPath=/home/sonnychee/.ansible/cp/%h-%p-%r ‘[[ec2-54-146-228-170.compute-1.amazonaws.com](http://ec2-54-146-228-170.compute-1.amazonaws.com)]’  
\<[ec2-54-226-249-100.compute-1.amazonaws.com](http://ec2-54-226-249-100.compute-1.amazonaws.com)\> ESTABLISH SSH CONNECTION FOR USER: ec2-user  
\<[ec2-54-226-249-100.compute-1.amazonaws.com](http://ec2-54-226-249-100.compute-1.amazonaws.com)\> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o ‘IdentityFile=“/home/sonnychee/.ssh/BeteNar.pem”’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 -o ControlPath=/home/sonnychee/.ansible/cp/%h-%p-%r [ec2-54-226-249-100.compute-1.amazonaws.com](http://ec2-54-226-249-100.compute-1.amazonaws.com) ‘/bin/sh -c ‘"’“‘chmod u+x /home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-260908329559293/ /home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-260908329559293/ec2 && sleep 0’”’“‘’  
\<[ec2-54-159-45-6.compute-1.amazonaws.com](http://ec2-54-159-45-6.compute-1.amazonaws.com)\> ESTABLISH SSH CONNECTION FOR USER: ec2-user  
\<[ec2-54-159-45-6.compute-1.amazonaws.com](http://ec2-54-159-45-6.compute-1.amazonaws.com)\> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile=”/home/sonnychee/.ssh/BeteNar.pem"’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 -o ControlPath=/home/sonnychee/.ansible/cp/%h-%p-%r [ec2-54-159-45-6.compute-1.amazonaws.com](http://ec2-54-159-45-6.compute-1.amazonaws.com) ‘/bin/sh -c ‘"’“‘chmod u+x /home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-91272603271631/ /home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-91272603271631/ec2 && sleep 0’”’“‘’  
\<[ec2-54-226-249-100.compute-1.amazonaws.com](http://ec2-54-226-249-100.compute-1.amazonaws.com)\> ESTABLISH SSH CONNECTION FOR USER: ec2-user  
\<[ec2-54-226-249-100.compute-1.amazonaws.com](http://ec2-54-226-249-100.compute-1.amazonaws.com)\> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile=”/home/sonnychee/.ssh/BeteNar.pem"’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 -o ControlPath=/home/sonnychee/.ansible/cp/%h-%p-%r -tt [ec2-54-226-249-100.compute-1.amazonaws.com](http://ec2-54-226-249-100.compute-1.amazonaws.com) ‘/bin/sh -c ‘"’“‘LANG=en\_US.UTF-8 LC\_ALL=en\_US.UTF-8 LC\_MESSAGES=en\_US.UTF-8 /usr/bin/python /home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-260908329559293/ec2; rm -rf “/home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-260908329559293/” \> /dev/null 2\>&1 && sleep 0’”’“‘’  
\<[ec2-54-146-228-170.compute-1.amazonaws.com](http://ec2-54-146-228-170.compute-1.amazonaws.com)\> ESTABLISH SSH CONNECTION FOR USER: ec2-user  
\<[ec2-54-146-228-170.compute-1.amazonaws.com](http://ec2-54-146-228-170.compute-1.amazonaws.com)\> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile=”/home/sonnychee/.ssh/BeteNar.pem"’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 -o ControlPath=/home/sonnychee/.ansible/cp/%h-%p-%r [ec2-54-146-228-170.compute-1.amazonaws.com](http://ec2-54-146-228-170.compute-1.amazonaws.com) ‘/bin/sh -c ‘"’“‘chmod u+x /home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-151598906640500/ /home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-151598906640500/ec2 && sleep 0’”’“‘’  
\<[ec2-54-159-45-6.compute-1.amazonaws.com](http://ec2-54-159-45-6.compute-1.amazonaws.com)\> ESTABLISH SSH CONNECTION FOR USER: ec2-user  
\<[ec2-54-159-45-6.compute-1.amazonaws.com](http://ec2-54-159-45-6.compute-1.amazonaws.com)\> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile=”/home/sonnychee/.ssh/BeteNar.pem"’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 -o ControlPath=/home/sonnychee/.ansible/cp/%h-%p-%r -tt [ec2-54-159-45-6.compute-1.amazonaws.com](http://ec2-54-159-45-6.compute-1.amazonaws.com) ‘/bin/sh -c ‘"’“‘LANG=en\_US.UTF-8 LC\_ALL=en\_US.UTF-8 LC\_MESSAGES=en\_US.UTF-8 /usr/bin/python /home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-91272603271631/ec2; rm -rf “/home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-91272603271631/” \> /dev/null 2\>&1 && sleep 0’”’“‘’  
\<[ec2-54-146-228-170.compute-1.amazonaws.com](http://ec2-54-146-228-170.compute-1.amazonaws.com)\> ESTABLISH SSH CONNECTION FOR USER: ec2-user  
\<[ec2-54-146-228-170.compute-1.amazonaws.com](http://ec2-54-146-228-170.compute-1.amazonaws.com)\> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile=”/home/sonnychee/.ssh/BeteNar.pem"’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 -o ControlPath=/home/sonnychee/.ansible/cp/%h-%p-%r -tt [ec2-54-146-228-170.compute-1.amazonaws.com](http://ec2-54-146-228-170.compute-1.amazonaws.com) ‘/bin/sh -c ‘"’“‘LANG=en\_US.UTF-8 LC\_ALL=en\_US.UTF-8 LC\_MESSAGES=en\_US.UTF-8 /usr/bin/python /home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-151598906640500/ec2; rm -rf “/home/ec2-user/.ansible/tmp/ansible-tmp-1476998334.12-151598906640500/” \> /dev/null 2\>&1 && sleep 0’”’"‘’  
[ec2-54-226-249-100.compute-1.amazonaws.com](http://ec2-54-226-249-100.compute-1.amazonaws.com) | FAILED! =\> {  
“changed”: false,  
“failed”: true,  
“invocation”: {  
“module\_args”: {  
“assign\_public\_ip”: false,  
“aws\_access\_key”: null,  
“aws\_secret\_key”: null,  
“count”: 1,  
“count\_tag”: null,  
“ebs\_optimized”: false,  
“ec2\_url”: null,  
“exact\_count”: null,  
“group”: null,  
“group\_id”: null,  
“id”: null,  
“image”: null,  
“instance\_ids”: null,  
“instance\_profile\_name”: null,  
“instance\_tags”: null,  
“instance\_type”: null,  
“kernel”: null,  
“key\_name”: null,  
“monitoring”: false,  
“network\_interfaces”: null,  
“placement\_group”: null,  
“private\_ip”: null,  
“profile”: null,  
“ramdisk”: null,  
“region”: “us-east-1”,  
“security\_token”: null,  
“source\_dest\_check”: true,  
“spot\_launch\_group”: null,  
“spot\_price”: null,  
“spot\_type”: “one-time”,  
“spot\_wait\_timeout”: “600”,  
“state”: “absent”,  
“tenancy”: “default”,  
“termination\_protection”: false,  
“user\_data”: null,  
“validate\_certs”: true,  
“volumes”: null,  
“vpc\_subnet\_id”: null,  
“wait”: false,  
“wait\_timeout”: “300”,  
“zone”: null  
},  
“module\_name”: “ec2”  
},  
“msg”: “No handler was ready to authenticate. 1 handlers were checked. [‘HmacAuthV4Handler’] Check your credentials”  
}  
[ec2-54-159-45-6.compute-1.amazonaws.com](http://ec2-54-159-45-6.compute-1.amazonaws.com) | FAILED! =\> {  
“changed”: false,  
“failed”: true,  
“invocation”: {  
“module\_args”: {  
“assign\_public\_ip”: false,  
“aws\_access\_key”: null,  
“aws\_secret\_key”: null,  
“count”: 1,  
“count\_tag”: null,  
“ebs\_optimized”: false,  
“ec2\_url”: null,  
“exact\_count”: null,  
“group”: null,  
“group\_id”: null,  
“id”: null,  
“image”: null,  
“instance\_ids”: null,  
“instance\_profile\_name”: null,  
“instance\_tags”: null,  
“instance\_type”: null,  
“kernel”: null,  
“key\_name”: null,  
“monitoring”: false,  
“network\_interfaces”: null,  
“placement\_group”: null,  
“private\_ip”: null,  
“profile”: null,  
“ramdisk”: null,  
“region”: “us-east-1”,  
“security\_token”: null,  
“source\_dest\_check”: true,  
“spot\_launch\_group”: null,  
“spot\_price”: null,  
“spot\_type”: “one-time”,  
“spot\_wait\_timeout”: “600”,  
“state”: “absent”,  
“tenancy”: “default”,  
“termination\_protection”: false,  
“user\_data”: null,  
“validate\_certs”: true,  
“volumes”: null,  
“vpc\_subnet\_id”: null,  
“wait”: false,  
“wait\_timeout”: “300”,  
“zone”: null  
},  
“module\_name”: “ec2”  
},  
“msg”: “No handler was ready to authenticate. 1 handlers were checked. [‘HmacAuthV4Handler’] Check your credentials”  
}  
[ec2-54-146-228-170.compute-1.amazonaws.com](http://ec2-54-146-228-170.compute-1.amazonaws.com) | FAILED! =\> {  
“changed”: false,  
“failed”: true,  
“invocation”: {  
“module\_args”: {  
“assign\_public\_ip”: false,  
“aws\_access\_key”: null,  
“aws\_secret\_key”: null,  
“count”: 1,  
“count\_tag”: null,  
“ebs\_optimized”: false,  
“ec2\_url”: null,  
“exact\_count”: null,  
“group”: null,  
“group\_id”: null,  
“id”: null,  
“image”: null,  
“instance\_ids”: null,  
“instance\_profile\_name”: null,  
“instance\_tags”: null,  
“instance\_type”: null,  
“kernel”: null,  
“key\_name”: null,  
“monitoring”: false,  
“network\_interfaces”: null,  
“placement\_group”: null,  
“private\_ip”: null,  
“profile”: null,  
“ramdisk”: null,  
“region”: “us-east-1”,  
“security\_token”: null,  
“source\_dest\_check”: true,  
“spot\_launch\_group”: null,  
“spot\_price”: null,  
“spot\_type”: “one-time”,  
“spot\_wait\_timeout”: “600”,  
“state”: “absent”,  
“tenancy”: “default”,  
“termination\_protection”: false,  
“user\_data”: null,  
“validate\_certs”: true,  
“volumes”: null,  
“vpc\_subnet\_id”: null,  
“wait”: false,  
“wait\_timeout”: “300”,  
“zone”: null  
},  
“module\_name”: “ec2”  
},  
“msg”: “No handler was ready to authenticate. 1 handlers were checked. [‘HmacAuthV4Handler’] Check your credentials”  
}
