Install IIS sub_features via win_feature module (but not ALL sub features)

1,100 views
Skip to first unread message

jiri....@apollogames.com

unread,
Dec 12, 2015, 12:11:52 PM12/12/15
to Ansible Project
Hello,

I have question if there is possibility via Ansible to install only particular IIS Web Server sub feature - not ALL sub features like now with property setup "include_sub_features: yes". (I'm using Windows Server 2012 R2 Datacenter)

For example I want in "Common HTTP Features" of Web Server only install Default Document and Directory Browsing. NOT HTTP Error, Static Content etc.
I want use native Ansible command, for sure there is way to execute power shell script if Ansible don't provide any API for this.

Thank you for reply

Trond Hindenes

unread,
Dec 12, 2015, 1:34:39 PM12/12/15
to Ansible Project
Absolutely. WIndows Features are a bit weird in that some have "subfeatures" and some don't. Web-Server is an example of a windows feature with tons of subfeatures, so when you ask to install that feature, Microsoft decides the "typical" subfeatures that get included. You can verify this by using the GUI wizard. So, in order to install only the features you want, you need to figure out exactly what they are, and just install those. 

The easiest way of doing that is probably to do a GUI-based install to make sure everything is exactly as you want, and then "record" the installed features by using PowerShell:
Get-WindowsFeature|where {$_.Installed -eq $true} | where {$_.SubFeatures.count -eq 0} | select -expand name

That gives you the name of the enabled features on your box which don't have subfeatures (e.g. the "leaf" features).

Say that this list gave you 5 features, you can easily use them with win_features as such:
- name: Install IIS
  hosts: all
  gather_facts: false
  tasks:
    - name: Install IIS
      win_feature:
        name: "feature1,feature2,feature3"
        state: present
        restart: no
        include_sub_features: no
        include_management_tools: yes

This will give you 100% control of exactly what gets installed. This is the recommended way to use win_features (instead of with_items) as all required features will be installed in one go, which is significantly faster.
Reply all
Reply to author
Forward
0 new messages