Issues Installing SCVMM via Ansible and PowerShell


While working on a scenario where I needed to automate the installation of SCVMM 2019, firstly via PowerShell scripts and then those scripts plugged into an Ansible playbook, I encountered some failures during the Ansible execution of the PowerShell scripts. These same scripts had worked fine when run locally on the Windows 2016 Server designated to run SCVMM.

The PowerShell scripts automated the install of three components; SQL, ADK and SCVMM. They were based on the examples you can find below:

https://github.com/microsoft/WSLab/blob/master/Tools/1_SQL_Install.ps1

https://github.com/microsoft/WSLab/blob/master/Tools/2_ADK_Install.ps1

https://github.com/microsoft/WSLab/blob/master/Tools/3_SCVMM_Install.ps1

When executed locally on the same Windows 2016 server all was good, the components were successfully installed. However, when running an Ansible job which included copying those scripts to the same server and executing them in the same order it would fail part the way through the install of SCVMM with winrm issues. It was also possible to re-produce similar winrm issues by executing the scripts from a remote PowerShell session with Invoke-Command, instead of executing them from Ansible.

Another alternative we tried was to create local scheduled task on the Windows Server which would execute the install script for SCVMM and run the scheduled task from an Ansible job. We discovered that the scheduled task would keep running and could be returned to in order to observe the result (which was a successful install), however we still received a winrm issue to the Ansible job:

This started to lead us to the actual answer, that some part of the SCVMM installation process was interrupting the winrm connection. The answer could be found in these two links for Ansible and pywinrm:

https://github.com/diyan/pywinrm/pull/174/files

https://github.com/ansible/ansible/issues/25532

They described the exact same issue we had with installing SCVMM from Ansible, with some operations causing winrm to become unavailable, and a proposed fix by adding some retries to the winrm session. Hoping that this gets merged to pywinrm, in the meantime I have separate Ansible playbooks to kick off the scheduled task and then check its status later.



Source link