Walking the registry, searching DisplayName, removing matching packages?

674 views
Skip to first unread message

b...@tanners.org

unread,
Apr 18, 2018, 6:51:04 PM4/18/18
to Ansible Project
I'd like to remove all the "Slack Machine-Wide Installer" packages. My approach is listed below. I'm wondering if there's an easier way to do this?

My approach.

Trying to use Ansible to uninstall packages; with a twist.

Control Panel shows this


Multiple versions of the Slack Machine-Wide Installer. Looking in the registry I find this key (as well as the other guids for the Slack Machine-Wide Installer):

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{81805212-8267-41AE-8F1E-979055EC5DF2}

I'd like to walk the Uninstall registry key, searching the DisplayName for "Slack Machine-Wide Installer" and remove that package.

I can get the Uninstall registry using this task.

- name: get uninstall registry key
win_reg_stat:
path: HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
register: uninstall_registry

The uninstall_registry.sub_keys contains the list I would like to query for the DisplayName, the below task lets me get the DisplayName of each key

- name: get properties of uninstall registry key
win_reg_stat:
path: HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{ item }}
name: DisplayName
register: display_name
with_items:
- "{{ uninstall_registry.sub_keys }}"

After this I kind of stuck. How do I get just the DisplayName?

- debug:
msg: "{{ item }}"
with_items:
- "{{ display_name.results }}"

Displays a lot more information then I need. How do I get just the DisplayName?


 





Karl Auer

unread,
Apr 18, 2018, 7:54:36 PM4/18/18
to ansible...@googlegroups.com
Look at the debug output and "walk" the structure to what you need, then put that into whatever needs it.

For example, when I create an AWS EC2 instance, the result variable contains a list of instances, with a table of attributes for each one. So to get to (say) the instance ID of the first instance in the list, I have to refer to results.instances[0].id

Your results variable is almost certainly structured, so look into that structure, figure out which bit you need, and refer to it using similar syntax.

Regards, K.


--
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 ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/db9f39ff-2a6a-49de-ae4f-89c1cf88effd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Karl Auer

Email  : ka...@2pisoftware.com
Website: 
http://2pisoftware.com

GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA

Reply all
Reply to author
Forward
Message has been deleted
0 new messages