# Trying to use Packer Provisioner for Ansible, Winrm connections to Windows 2019 server

**URL:** <https://forum.ansible.com/t/trying-to-use-packer-provisioner-for-ansible-winrm-connections-to-windows-2019-server/33915>\
**Category:** Ansible Project\
**Tags:** windows, aws\
**Created:** [September 28, 2020, 11:17pm UTC](https://forum.ansible.com/t/trying-to-use-packer-provisioner-for-ansible-winrm-connections-to-windows-2019-server/33915 "2020-09-28T23:17:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![i255d](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@i255d](https://forum.ansible.com/u/i255d)\
**Post date:** [September 28, 2020, 11:17pm UTC](https://forum.ansible.com/t/trying-to-use-packer-provisioner-for-ansible-winrm-connections-to-windows-2019-server/33915/1 "2020-09-28T23:17:35Z")

</div>

I have been working on this for days, and I feel like I am close. Any ideas what is causing this???

amazon-ebs: PLAYBOOK: playbook.yml \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
amazon-ebs: 1 plays in /codebuild/output/src610977066/src/git.nylcloud.com/Cloud-Team/packer-aws-nyl-win2016/playbook.yml  
amazon-ebs:  
amazon-ebs: PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
amazon-ebs:  
amazon-ebs: TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
amazon-ebs: task path: /codebuild/output/src610977066/src/git.nylcloud.com/Cloud-Team/packer-aws-nyl-win2016/playbook.yml:2  
amazon-ebs: redirecting (type: modules) ansible.builtin.setup to ansible.windows.setup  
amazon-ebs: Using module file /root/.pyenv/versions/3.8.3/lib/python3.8/site-packages/ansible\_collections/ansible/windows/plugins/modules/setup.ps1  
amazon-ebs: Pipelining is enabled.  
amazon-ebs: \<10.184.21.20\> ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5986 TO 10.184.21.20  
amazon-ebs: EXEC (via pipeline wrapper)  
amazon-ebs: [WARNING]: ERROR DURING WINRM SEND INPUT - attempting to recover: WinRMError  
amazon-ebs: The pipe is being closed. (extended fault data: {‘transport\_message’: ‘Bad  
amazon-ebs: HTTP response returned from server. Code 500’, ‘http\_status\_code’: 500,  
amazon-ebs: ‘wsmanfault\_code’: ‘232’, ‘fault\_code’: ‘s:Receiver’, ‘fault\_subcode’:  
amazon-ebs: ‘w:InternalError’})  
amazon-ebs: fatal: [default]: FAILED! =\> {00s\u0000t\u0000a\u0000l\u0000l\u0000e\u0000d\u0000.\u0000\r\u0000\n\u0000"  
amazon-ebs: }  
amazon-ebs:  
amazon-ebs: PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
amazon-ebs: default : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0  
amazon-ebs:

---

<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:** [September 29, 2020, 3:27am UTC](https://forum.ansible.com/t/trying-to-use-packer-provisioner-for-ansible-winrm-connections-to-windows-2019-server/33915/2 "2020-09-29T03:27:54Z")

</div>

There is an error when trying to execute PowerShell causing the process to stop and subsequently close the stdin pipe that Ansible is writing to. Can you run with a higher verbosity so that Ansible shows the full stdout and stderr from the process (-vvvvvv). That will output the full error message which you can then subsequently remove the \u0000 as the text is UTF-16 encoded. This should give you a reason as to why the process has failed.

---

<div class="post-metadata">

**Author:** ![i255d](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@i255d](https://forum.ansible.com/u/i255d)\
**Post date:** [September 30, 2020, 5:11am UTC](https://forum.ansible.com/t/trying-to-use-packer-provisioner-for-ansible-winrm-connections-to-windows-2019-server/33915/3 "2020-09-30T05:11:17Z")

</div>

[https://gist.github.com/i255d/5d4d2a831b9519d0a669ab947c6c255c](https://gist.github.com/i255d/5d4d2a831b9519d0a669ab947c6c255c)

---

<div class="post-metadata">

**Author:** ![i255d](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@i255d](https://forum.ansible.com/u/i255d)\
**Post date:** [September 30, 2020, 2:26pm UTC](https://forum.ansible.com/t/trying-to-use-packer-provisioner-for-ansible-winrm-connections-to-windows-2019-server/33915/4 "2020-09-30T14:26:26Z")

</div>

One of the Ansible engineers is suggesting the Packer may be doing something with an environmental variables ‘POWERSHELL\_VERSION’ that may be causing this issue. 14:30 \<@jborean93\> i255d: [https://github.com/ansible/ansible/blob/8f02819db02459ed144e131db3808dee0a7356db/lib/ansible/plugins](https://github.com/ansible/ansible/blob/8f02819db02459ed144e131db3808dee0a7356db/lib/ansible/plugins)… you have `POWERSHELL_VERSION` set in an env var which is causing the trouble

---

<div class="post-metadata">

**Author:** ![i255d](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@i255d](https://forum.ansible.com/u/i255d)\
**Post date:** [September 30, 2020, 4:02pm UTC](https://forum.ansible.com/t/trying-to-use-packer-provisioner-for-ansible-winrm-connections-to-windows-2019-server/33915/5 "2020-09-30T16:02:44Z")

</div>

added now: I have a $PSversiontable in the powershell provisioner that shows it is version 5.1, when I switch the OS from 2019 to 2016, and the when the Ansible part runs is says this: amazon-ebs: \<10.184.21.18\> WINRM EXEC ‘PowerShell’ [‘-Version’, ‘6.2.6’, ‘-NoProfile’, ‘-NonInteractive’, ‘-ExecutionPolicy’, ‘Unrestricted’, ‘-EncodedCommand’,  
I am pretty sure the version 6.2.6 is the issue.
