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
Thanks
Jordan
--
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/ac38c7f7-a1f4-4a0c-82d4-03d74f6c376f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.