Ansible: need help uninstalling Windows software via playbook

245 views
Skip to first unread message

Gerry Maddock

unread,
Oct 22, 2020, 4:54:39 PM10/22/20
to ansible...@googlegroups.com
Hello,

I would greatly appreciate any help/input to help me get this playbook working. I have been trying with win_package (win_package states the program is uninstalled, but its not). I have even tried powershell via win_shell. I think I'm really close to resolving this issue, but would love some help or input. Thanks in advance!


I'm running the playbook via:
ansible-playbook Uninstall_tst.yml --limit WJUMPV1T.contesso.com --extra-vars "var1=WinPcap" --ask-vault-pass


Below is my playbook:

---

# Powershell commands to uninstall software in windows (passed by Variables: --extra-vars "var1=Putty" would uninstall putty)

- name: Uninstall Program of your choice
  hosts: dev
  gather_facts: false
  tasks:
    - name: Get uninstall info for {{ var1 }}
      win_command: powershell.exe -
      args:
        stdin: Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where-Object {$_.DisplayName -like '{{ var1 }}*'} | Select-Object DisplayName | foreach { $_.DisplayName }
        #stdin: Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where-Object {$_.DisplayName -like '{{ var1 }}*'} | Select-Object Uninstallstring | foreach { $_.UninstallString }
      register: prodid

    - debug:
       var: prodid.stdout_lines

    - name: Get uninstall info for {{ var1 }}
      win_command: powershell.exe -
      args:
        stdin: Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where-Object {$_.DisplayName -like '{{ var1 }}*'} | Select-Object Uninstallstring | foreach { $_.UninstallString }
      register: undir

    - debug:
       var: undir.stdout_lines

    - name: Uninstall {{ var1 }}
      win_package:
        product_id:  prodid.stdout_lines
        path: undir.stdout_lines
        arguments: /S
        state: absent


#    - name: Uninstall {{ var1 }}
#      win_command: powershell.exe -
#      args:
#        stdin: MsiExec.exe /uninstall /quiet {{ var1 }}
Reply all
Reply to author
Forward
0 new messages