I am installing (about 30) and removing (about 40) required windows features on a 2012 R2 box. My playbook looks like this:
---
- name: Installing features
win_feature:
name: '{{ item }}'
state: Present
with_items:
'{{ features_to_install }}'
- name: Removing features
win_feature:
name: '{{ item }}'
state: Absent
with_items:
'{{ features_to_remove }}'
I then have my vars in a separate file which look like this:
---
features_to_install: [FileAndStorage-Services,File-Services,.....]
features_to_remove: [AD-Certificate,ADCS-Cert-Authority.....]
All in all, everything works well. But it is too slow as I have to run it over and over again as I make changes. I want to introduce conditionals where it "skips" if a feature is already installed or is not present.
I am trying to register the output from a powershell script converted to Json and then compare with features_to_install but cannot seem to get it right. The script that Im using:
Get-WindowsFeature | ? {$_.Installed -match "True"} | Select -exp Name | ConvertTo-Json
Here's what Im working with so far. Any direction/help would be greatly appreciated:
- name: Copy powershell script to list windows features
win_copy:
src: '{{ Directory }}/tools/ListWindowsFeatures.ps1'
dest: '{{ Powershell }}'
- name: run powershell
win_shell: '{{ Powershell }}/ListWindowsFeatures.ps1'
register: presentfeatures
- name: Installing features
win_feature:
name: File-Services
state: Present
with_items:
'{{ features_to_install }}'
when: presentfeatures != features_to_install