Ansible, Windows and PowerShell: the Basics – Part 3, Windows Roles and Features

In Part 3 of this series we’ll continue our journey with Ansible, Windows and PowerShell and look at how we can use Ansible to prepare servers with Windows Roles and Features.

The PowerShell story around support for Windows Roles and Features can be a little confusing, since there are two different sets of PowerShell cmdlets as well as the cmdline tools dism.exe and pkgmgr.exe. So knowing which tool to use to start with requires some effort itself. I’ve briefly mentioned it before in a previous post, but the most useful source of comparison I’ve found between the different options is this site.

It’s a similar story when we turn to Ansible support for Windows Roles and Features since there are two modules to achieve similar outcomes, win_feature and win_optional_feature. The difference between them appears to arise from which PowerShell cmdlets the modules are using under the hood:

In the main both of them should get you to the same end result, so the choice is yours. In this post, we’ll be concentrating on the win_feature Ansible module.

Our job template in AWX is _2_install-windowsfeature

The contents of _2_install-windowsfeature.yml are are follows:

The first task installs Remote-Desktop-Services including the management tools and the second task removes Print-Services.

Before running any job, looking at our vanilla Windows 2016 server below, we can observe that Remote-Desktop-Services is not present, but Print-Services is there.

Running a job from the _2_install-windowsfeature job template produces a successful result:

Checking our vanilla Windows 2016 server, we can now observe that Remote-Desktop-Services is present and Print-Services has been removed.