# ec2\_win\_password unable to parse key file

**URL:** <https://forum.ansible.com/t/ec2-win-password-unable-to-parse-key-file/25560>\
**Category:** Ansible Project\
**Created:** [September 21, 2017, 4:17pm UTC](https://forum.ansible.com/t/ec2-win-password-unable-to-parse-key-file/25560 "2017-09-21T16:17:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Howe](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@Ryan\_Howe](https://forum.ansible.com/u/Ryan_Howe)\
**Post date:** [September 21, 2017, 4:17pm UTC](https://forum.ansible.com/t/ec2-win-password-unable-to-parse-key-file/25560/1 "2017-09-21T16:17:36Z")

</div>

Hello,

I’m trying to use the ec2\_win\_password module to retrieve the default Administrator password for an EC2 instance. I had a play working and then upgraded to Ansible 2.4. I added the cryptography module as the notes indicate. My play continually fails returning a message that it can’t parse the key file (and the key file is not encrypted).

I ran a test where I encrypted the key file and provided a passphrase in the play and things did work successfully.

Would anyone have any thoughts on why this might be failing with an unecrypted key and no password? Below is the debug output from the play.  
It kind of feels to me like it thinks a password is being given even though I don’t mention the parameter in the play. As such, it’s existing because the key is not encrypted.

Thank you  
Ryan

ansible-playbook 2.4.0.0  
config file = None  
configured module search path = [u’/Users/rhowe/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /Library/Python/2.7/site-packages/ansible  
executable location = /usr/local/bin/ansible-playbook  
python version = 2.7.10 (default, Feb 7 2017, 00:08:15) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]  
No config file found; using defaults  
setting up inventory plugins  
Parsed /etc/ansible/hosts inventory source with ini plugin  
Loading callback plugin default of type stdout, v2.0 from /Library/Python/2.7/site-packages/ansible/plugins/callback/ **init**.pyc

PLAYBOOK: 03\_retrieve\_admin\_password.yml \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
1 plays in 03\_retrieve\_admin\_password.yml

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
META: ran handlers

TASK [Get Administrator Password] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /Users/rhowe/ansible\_scripts/03\_retrieve\_admin\_password.yml:10  
Using module\_utils file /Library/Python/2.7/site-packages/ansible/module\_utils/\_text.py  
Using module\_utils file /Library/Python/2.7/site-packages/ansible/module\_utils/basic.py  
Using module\_utils file /Library/Python/2.7/site-packages/ansible/module\_utils/ec2.py  
Using module\_utils file /Library/Python/2.7/site-packages/ansible/module\_utils/six/ **init**.py  
Using module\_utils file /Library/Python/2.7/site-packages/ansible/module\_utils/parsing/convert\_bool.py  
Using module\_utils file /Library/Python/2.7/site-packages/ansible/module\_utils/parsing/ **init**.py  
Using module\_utils file /Library/Python/2.7/site-packages/ansible/module\_utils/pycompat24.py  
Using module\_utils file /Library/Python/2.7/site-packages/ansible/module\_utils/cloud.py  
Using module file /Library/Python/2.7/site-packages/ansible/modules/cloud/amazon/ec2\_win\_password.py  
\<127.0.0.1\> ESTABLISH LOCAL CONNECTION FOR USER: rhowe  
\<127.0.0.1\> EXEC /bin/sh -c ‘echo ~ && sleep 0’  
\<127.0.0.1\> EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo /Users/rhowe/.ansible/tmp/ansible-tmp-1506010305.03-241574263221967`” && echo ansible-tmp-1506010305.03-241574263221967=“`echo /Users/rhowe/.ansible/tmp/ansible-tmp-1506010305.03-241574263221967`” ) && sleep 0’  
\<127.0.0.1\> PUT /var/folders/92/sndgxv6s3dnfhpptzcbf98k80000gn/T/tmpwA8R2C TO /Users/rhowe/.ansible/tmp/ansible-tmp-1506010305.03-241574263221967/ec2\_win\_password.py  
\<127.0.0.1\> EXEC /bin/sh -c ‘chmod u+x /Users/rhowe/.ansible/tmp/ansible-tmp-1506010305.03-241574263221967/ /Users/rhowe/.ansible/tmp/ansible-tmp-1506010305.03-241574263221967/ec2\_win\_password.py && sleep 0’  
\<127.0.0.1\> EXEC /bin/sh -c ‘/usr/bin/python /Users/rhowe/.ansible/tmp/ansible-tmp-1506010305.03-241574263221967/ec2\_win\_password.py; rm -rf “/Users/rhowe/.ansible/tmp/ansible-tmp-1506010305.03-241574263221967/” \> /dev/null 2\>&1 && sleep 0’  
The full traceback is:  
File “/var/folders/92/sndgxv6s3dnfhpptzcbf98k80000gn/T/ansible\_vLagCP/ansible\_module\_ec2\_win\_password.py”, line 167, in main  
key = load\_pem\_private\_key(f.read(), b\_key\_passphrase, BACKEND)  
File “/Library/Python/2.7/site-packages/cryptography/hazmat/primitives/serialization.py”, line 20, in load\_pem\_private\_key  
return backend.load\_pem\_private\_key(data, password)  
File “/Library/Python/2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py”, line 1006, in load\_pem\_private\_key  
password,  
File “/Library/Python/2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py”, line 1231, in \_load\_key  
“Password was given but private key is not encrypted.”)

fatal: [localhost]: FAILED! =\> {  
“changed”: false,  
“failed”: true,  
“invocation”: {  
“module\_args”: {  
“aws\_access\_key”: “xxxxxxxxxxxx”,  
“aws\_region”: “us-east-1”,  
“aws\_secret\_key”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“ec2\_url”: null,  
“instance\_id”: “i-xxxxxxxx”,  
“key\_file”: “/Users/rhowe/Documents/ssh\_keys/KeyFileName.pem”,  
“key\_passphrase”: null,  
“profile”: null,  
“region”: “us-east-1”,  
“security\_token”: null,  
“validate\_certs”: true,  
“wait”: false,  
“wait\_timeout”: “120”  
}  
},  
“msg”: “unable to parse key file”  
}

---

<div class="post-metadata">

**Author:** ![Joey\_Brown](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@Joey\_Brown](https://forum.ansible.com/u/Joey_Brown)\
**Post date:** [October 2, 2017, 3:00am UTC](https://forum.ansible.com/t/ec2-win-password-unable-to-parse-key-file/25560/2 "2017-10-02T03:00:41Z")

</div>

I had the same problem in 2.4.

Downgraded to 2.3.2 and it works fine.
