I'm writing an ansible playbook to look in the Windows registry, the "uninstall" command for a given software. That command is saved in a registry key named "UninstallString".
I'm having some problems to extract that particular value. The idea is to later use an exec from the very same ansible playbook and uninstall that software.
In this code, I'm trying to do that for the software "7-Zip". Later in the playbook I'll use a variable, but for testing purposes I'm hardcoding "Zip".
tasks:
- win_reg_stat:
path: HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall
register: lista64
- win_reg_stat:
path: HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\{{ item }}
name: UninstallString
with_items: "{{ lista64.sub_keys | select('match','.*Zip.*') | list }}"
register: desinstala
- debug:
msg: "{{ desinstala.results }}"
This code returns this output:
ok: [172.16.1.25] => {
"msg": [
{
"_ansible_ignore_errors": null,
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": false,
"exists": true,
"failed": false,
"item": "7-Zip",
"raw_value": "C:\\Program Files\\7-Zip\\Uninstall.exe",
"type": "REG_SZ",
"value": "C:\\Program Files\\7-Zip\\Uninstall.exe"
}
]
}
How could I save "C:\Program Files\7-Zip\Uninstall.exe" into a variable that I could use later on the playbook? I tried with things like "{{ desinstala.results.value }}" or "{{ desinstala.results | select... }}" but I just can't find the way to do it.
Any help is very welcome :)