Skip to content

Instantly share code, notes, and snippets.

@gravcat
Created February 22, 2018 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gravcat/a20417e772661b63d6fc2cc0e1c6b3d0 to your computer and use it in GitHub Desktop.
Save gravcat/a20417e772661b63d6fc2cc0e1c6b3d0 to your computer and use it in GitHub Desktop.
via Ansible, check whether or not a Windows feature is in an "Enabled" state. Conditional to enable feature if it is determined to not be in an Enabled state
---
- hosts: all
tasks:
- name: Check for WSL feature enablement
win_shell: "(Get-WindowsOptionalFeature -Online -FeatureName 'Microsoft-Windows-Subsystem-Linux').State"
register: wsl_check
- name: Install WSL Feature
win_shell: "{{ item }}"
with_items:
- "Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName Microsoft-Windows-Subsystem-Linux"
- "Start-Sleep -s 10"
when: wsl_check.stdout_lines != "Enabled"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment