# Not repeatable login error with winrm

**URL:** <https://forum.ansible.com/t/not-repeatable-login-error-with-winrm/26268>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [December 12, 2017, 10:23pm UTC](https://forum.ansible.com/t/not-repeatable-login-error-with-winrm/26268 "2017-12-12T22:23:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_M](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@Justin\_M](https://forum.ansible.com/u/Justin_M)\
**Post date:** [December 12, 2017, 10:23pm UTC](https://forum.ansible.com/t/not-repeatable-login-error-with-winrm/26268/1 "2017-12-12T22:23:31Z")

</div>

New to Ansbile and trying to do a POC and learn at the same time. I’m using centos for my ansbile server and using the local admin account on windows when running my remote tasks. I’m able to run a bunch of tasks like remotely installing MSIs and joining a domain and installing some features. The first time I attempt to copy a file I get the below error. (I used the -vvv option to get some more verbose output). What is weird is if I immediately run my playbook again it works and completes the rest of the tasks without issue. I don’t understand how this could be as this step is way after the domain join. Currently I join the domain, reboot, add some roles reboot, and add some features all before this step. I’m also not sure if the step that is failing is the win\_copy or the script. Either way it runs the second time. Any help would be appreciated.

Steps in config

- name: Setup IIS/Certificate  
win\_copy:  
src: files/certs/mycert\_2020.pfx  
dest: C:\scripts\
- script: files/certs/install\_cert.bat  
args:  
creates: c:\scripts\certinstalled.txt

\<10.152.2.137\> PUT “/etc/ansible/files/certs/mycert.pfx” TO “C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1513116318.66-1186697384671\source”  
Using module file /usr/lib/python2.7/site-packages/ansible/modules/windows/win\_copy.ps1  
EXEC (via pipeline wrapper)  
The full traceback is:  
Traceback (most recent call last):  
File “/usr/lib/python2.7/site-packages/ansible/executor/task\_executor.py”, line 125, in run  
res = self.\_execute()  
File “/usr/lib/python2.7/site-packages/ansible/executor/task\_executor.py”, line 521, in \_execute  
result = self.\_handler.run(task\_vars=variables)  
File “/usr/lib/python2.7/site-packages/ansible/plugins/action/win\_copy.py”, line 490, in run  
copy\_result = self.\_copy\_single\_file(file\_src, dest, file\_dest, task\_vars)  
File “/usr/lib/python2.7/site-packages/ansible/plugins/action/win\_copy.py”, line 281, in \_copy\_single\_file  
copy\_result = self.\_execute\_module(module\_name=“copy”, module\_args=copy\_args, task\_vars=task\_vars)  
File “/usr/lib/python2.7/site-packages/ansible/plugins/action/ **init**.py”, line 737, in \_execute\_module  
res = self.\_low\_level\_execute\_command(cmd, sudoable=sudoable, in\_data=in\_data)  
File “/usr/lib/python2.7/site-packages/ansible/plugins/action/ **init**.py”, line 886, in \_low\_level\_execute\_command  
rc, stdout, stderr = self.\_connection.exec\_command(cmd, in\_data=in\_data, sudoable=sudoable)  
File “/usr/lib/python2.7/site-packages/ansible/plugins/connection/winrm.py”, line 357, in exec\_command  
result = self.\_winrm\_exec(cmd\_parts[0], cmd\_parts[1:], from\_exec=True, stdin\_iterator=stdin\_iterator)  
File “/usr/lib/python2.7/site-packages/ansible/plugins/connection/winrm.py”, line 308, in \_winrm\_exec  
self.protocol.cleanup\_command(self.shell\_id, command\_id)  
File “/usr/lib/python2.7/site-packages/winrm/protocol.py”, line 314, in cleanup\_command  
res = self.send\_message(xmltodict.unparse(req))  
File “/usr/lib/python2.7/site-packages/winrm/protocol.py”, line 214, in send\_message  
return self.transport.send\_message(message)  
File “/usr/lib/python2.7/site-packages/winrm/transport.py”, line 229, in send\_message  
response = self.\_send\_message\_request(prepared\_request, message)  
File “/usr/lib/python2.7/site-packages/winrm/transport.py”, line 239, in \_send\_message\_request  
raise InvalidCredentialsError(“the specified credentials were rejected by the server”)  
InvalidCredentialsError: the specified credentials were rejected by the server

fatal: [10.152.2.137]: FAILED! =\> {  
“failed”: true,  
“msg”: “Unexpected failure during module execution.”,  
“stdout”: “”  
}  
to retry, use: --limit @/etc/ansible/ASGTEST.retry

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [December 13, 2017, 2:06am UTC](https://forum.ansible.com/t/not-repeatable-login-error-with-winrm/26268/2 "2017-12-13T02:06:08Z")

</div>

If the previous task before the copy one is to install some features and reboot then potentially the WinRM service comes back online but it reboots one more time that isn’t caught. What I would potentially do is

`

- name: install problematic features  
win\_feature:  
name: …  
register: feature\_install

- name: reboot after feature install  
win\_reboot:  
when: feature\_install.reboot\_required

- block:

- name: copy file  
win\_copy:  
src: files/certs/mycert\_2020.pfx  
dest: C:\scripts\

rescue:

- name: copy failed wait for connection to become stable  
wait\_for\_connection:

- name: copy the file again  
win\_copy:  
src: files/certs/mycert\_2020.pfx  
dest: C:\scripts\

- name: run setup script  
script: files/certs/install\_cert.bat  
args:  
creates: c:\scripts\certinstalled.txt

`

The block/rescue may not work as the failure happened in the connection plugin and not the module and this usually is a fatal exception that is not recoverable. But because win\_copy is an action plugin it may work I just can’t confirm right now. If it doesn’t work then you may need to look into the logs a bit more to see why it may be rejecting your credentials or as a precaution put a pause after the win\_reboot step and then wait\_for\_connection straight after to try and catch these exceptions.

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [December 13, 2017, 2:07am UTC](https://forum.ansible.com/t/not-repeatable-login-error-with-winrm/26268/3 "2017-12-13T02:07:59Z")

</div>

Actually after looking at the error it does still seem to be a fatal error so I don’t think the block/rescue will work in this case so I think putting wait\_for\_connection after your reboot stage might be best.
