up vote
down votefavorite 
<https://stackoverflow.com/questions/45968747/conditional-run-of-win-feature-with-ansible#>

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

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7f1a2060-26af-46d3-aff1-a876f181c56c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to