# Looking for easy way to filter out windows versions below Server 2016

**URL:** <https://forum.ansible.com/t/looking-for-easy-way-to-filter-out-windows-versions-below-server-2016/29965>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [March 23, 2019, 1:01pm UTC](https://forum.ansible.com/t/looking-for-easy-way-to-filter-out-windows-versions-below-server-2016/29965 "2019-03-23T13:01:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![daemenseth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/daemenseth/32/677_2.png) [@daemenseth](https://forum.ansible.com/u/daemenseth)\
**Post date:** [March 23, 2019, 1:01pm UTC](https://forum.ansible.com/t/looking-for-easy-way-to-filter-out-windows-versions-below-server-2016/29965/1 "2019-03-23T13:01:58Z")

</div>

Is there a easy way to filter out older windows versions below 2016

For windows 7, windows 2008 etc I do other command in my playbook then for server 2016 and 2019 and windows 10.

I want to make one when statement instead of different ones.

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [March 25, 2019, 7:43pm UTC](https://forum.ansible.com/t/looking-for-easy-way-to-filter-out-windows-versions-below-server-2016/29965/2 "2019-03-25T19:43:57Z")

</div>

You can do this if fact gathering is enabled with the ‘ansible\_distribution\_version’ factor but if you don’t have that you could just gather that info like;

`

- name: skip using the built in facts  
debug:  
msg: Hello  
when: ansible\_distribution\_version is version\_compare(‘10.0’, ‘\>=’)

- name: get OS version manually  
win\_shell: (Get-Item -LiteralPath C:\Windows\System32\kernel32.dll).VersionInfo.ProductVersion  
changed\_when: False  
register: os\_version

- name: skip using the manually gathered OS version var  
debug:  
msg: World  
when: os\_version | trim is version\_compare(‘10.0’, ‘\>=’)

`

Both examples hinge on using the version\_compare (or version) test [1]. This allows you to compare version numbers and check if it is less, equal, greater, etc, than the one you specify. For Windows 10 or Server 2016 you want to test if it’s greater than 10.0. Here is a brief list of version numbers for Windows;

- Server 2008 - 6.0
- Server 2008 R2/Windows 7 - 6.1
- Server 2012 - 6.2
- Server 2012 R2/Windows 8.1 - 6.3
- Server 2016/Windows 10 - 10.0

[1] [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_tests.html#version-comparison](https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#version-comparison)

Thanks

Jordan

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [March 25, 2019, 7:45pm UTC](https://forum.ansible.com/t/looking-for-easy-way-to-filter-out-windows-versions-below-server-2016/29965/3 "2019-03-25T19:45:05Z")

</div>

`

`

- name: skip using the manually gathered OS version var  
debug:  
msg: World  
when: (os\_version.stdout | trim) is version\_compare(‘10.0’, ‘\>=’)

`

`

Minor edit to the last tasks’ when condition.

---

<div class="post-metadata">

**Author:** ![daemenseth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/daemenseth/32/677_2.png) [@daemenseth](https://forum.ansible.com/u/daemenseth)\
**Post date:** [March 27, 2019, 3:25pm UTC](https://forum.ansible.com/t/looking-for-easy-way-to-filter-out-windows-versions-below-server-2016/29965/4 "2019-03-27T15:25:42Z")

</div>

Thx Jordan Borean this was the information I was looking for.  
many thx
