Ansible, Windows and PowerShell: the Basics - Part 2, Install PowerShell Modules

In Part 2 of this series we’ll move on from the introductory topics and look at how we can use Ansible to prepare servers with any external PowerShell Modules they need from the PowerShell Gallery.

Our job template in AWX is _1_install-psmodule

The contents of _1_install-psmodule.yml are are follows:

We can use the native Ansible module win_psmodule to do the work for us. In addition, we can ensure multiple modules are installed without needing a separate task for each one by looping using with_items. This enables us to simply supply the names of the modules for the PowerShell Gallery that we need and Ansible will install both of them.

Looking at our vanilla Windows 2016 server, we can observe that prior to running the job template neither the PowervRA or PowervRO modules are installed.

Running a job from the _1_install-psmodule job template produces a successful result:

Checking our vanilla Windows 2016 server, we can now observe that both the PowervRA or PowervRO modules are installed and available for further automation.