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:
- The code for the win_feature module is using cmdlets from the PowerShell ServerManager module
- The code for the win_optional_feature is cmdlets from the PowerShell Dism module
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.
- Ansible, Windows and PowerShell: the Basics – Introduction
- Ansible, Windows and PowerShell: the Basics - Part 1, Windows Services
- Ansible, Windows and PowerShell: the Basics - Part 2, Install PowerShell Modules
- Ansible, Windows and PowerShell: the Basics – Part 3, Windows Roles and Features
- Ansible, Windows and PowerShell: the Basics – Part 4, Invoking PowerShell Code
- Ansible, Windows and PowerShell: the Basics – Part 5, Example PowerShell Error Handling
- Ansible, Windows and PowerShell: the Basics – Part 6, Displaying Output from PowerShell Code
- Ansible, Windows and PowerShell: the Basics – Part 7, Utilising PowerShell DSC
- Ansible, Windows and PowerShell: the Basics – Part 8, Rebooting & Waiting
- Ansible, Windows and PowerShell: the Basics – Part 9, Disk Creation
- Ansible, Windows and PowerShell: the Basics – Part 10, Local Users
- Ansible, Windows and PowerShell: the Basics – Part 11, Local Groups
- Ansible, Windows and PowerShell: the Basics – Part 12, Set TimeZone
- Ansible, Windows and PowerShell: the Basics – Part 13, Environment Variables
- Ansible, Windows and PowerShell: the Basics – Part 14, Registry Entries
- Ansible, Windows and PowerShell: the Basics – Part 15, Install Chocolatey Packages