除非状态已被禁用,否则我想在Windows客户端上禁用Windows Defender。
目前,我使用ansible的register命令将其分为2个任务
---
-hosts: all
become_method: runas
tasks:
- name: Check if WinDefend is running
win_shell: (Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender").DisableAntiSpyware
register: WinDefendStatus
become: yes
become_user: Administrator
- name: Turn off WinDefend
win_shell: New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender" -Name DisableAntiSpyware -Value 1 -PropertyType DWORD -Force
become: yes
become_user: Administrator
when: WinDefendStatus.stdout == "0" or ""
从技术上讲这可行,但我想在1个任务中完成。这些指南仅显示本地变量或本地存储的事实,而没有显示远程获取的值。
任何想法该怎么做?