# Check for existing installed software

**URL:** <https://forum.ansible.com/t/check-for-existing-installed-software/36135>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [December 20, 2021, 3:09pm UTC](https://forum.ansible.com/t/check-for-existing-installed-software/36135 "2021-12-20T15:09:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nitrous](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@Nitrous](https://forum.ansible.com/u/Nitrous)\
**Post date:** [December 20, 2021, 3:09pm UTC](https://forum.ansible.com/t/check-for-existing-installed-software/36135/1 "2021-12-20T15:09:51Z")

</div>

How can I incorporate this registry check before my playbook runs to install .net 4.8:

(Get-ItemProperty “HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full”).version -lt 4.8

The above should only run my playbook, if 4.8 isnt installed. If version is less than 4.8 run the below playbook, else skip

My playbook to install .net 4.8:

- name: Copy .net 4.8 Files  
ansible.windows.win\_copy:  
src: /etc/ansible/roles/net481/files/ndp48-x86-x64-allos-enu.exe  
dest: C:\Scripts  
state: present

- name: Install .net 4.8  
ansible.builtin.script: /etc/ansible/roles/onprembaseline/files/net48.ps1  
register: script\_run

- name: Reboot after .NET 4.8 Install

ansible.windows.win\_reboot:

Thanks.

---

<div class="post-metadata">

**Author:** ![Nitrous](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@Nitrous](https://forum.ansible.com/u/Nitrous)\
**Post date:** [December 21, 2021, 9:25pm UTC](https://forum.ansible.com/t/check-for-existing-installed-software/36135/2 "2021-12-21T21:25:23Z")

</div>

any suggestions?

---

<div class="post-metadata">

**Author:** ![Nitrous](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@Nitrous](https://forum.ansible.com/u/Nitrous)\
**Post date:** [December 29, 2021, 4:57pm UTC](https://forum.ansible.com/t/check-for-existing-installed-software/36135/3 "2021-12-29T16:57:20Z")

</div>

anyone with ideas?

---

<div class="post-metadata">

**Author:** ![Niek](https://avatars.discourse-cdn.com/v4/letter/n/e95f7d/32.png) [@Niek](https://forum.ansible.com/u/Niek)\
**Post date:** [December 30, 2021, 6:24pm UTC](https://forum.ansible.com/t/check-for-existing-installed-software/36135/4 "2021-12-30T18:24:36Z")

</div>

Not a ansible hero here, but i think you can do something with the when: command in your playbook.

So somewhere in de the task where you check the version you will do a  
register: dotnet\_version

And in the taks where you execute it:  
when: “‘4.8’ in {{ dotnet\_version }}”

---

<div class="post-metadata">

**Author:** ![Niek](https://avatars.discourse-cdn.com/v4/letter/n/e95f7d/32.png) [@Niek](https://forum.ansible.com/u/Niek)\
**Post date:** [December 30, 2021, 6:25pm UTC](https://forum.ansible.com/t/check-for-existing-installed-software/36135/5 "2021-12-30T18:25:32Z")

</div>

Probably check: [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_conditionals.html](https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html)

---

<div class="post-metadata">

**Author:** ![Nitrous](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@Nitrous](https://forum.ansible.com/u/Nitrous)\
**Post date:** [January 19, 2022, 6:33pm UTC](https://forum.ansible.com/t/check-for-existing-installed-software/36135/6 "2022-01-19T18:33:41Z")

</div>

This is what I get:

TASK [net481 : Check if .net 4.8 is installed] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /etc/ansible/roles/net481/tasks/main.yml:1  
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: ‘4.8’ in {{ script\_run }}  
fatal: [xxxxx]: FAILED! =\> {  
“msg”: “The conditional check ‘‘4.8’ in {{ script\_run }}’ failed. The error was: error while evaluating conditional (‘4.8’ in {{ script\_run }}): ‘script\_run’ is undefined\n\nThe error appears to be in ‘/etc/ansible/roles/net481/tasks/main.yml’: line 1, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Check if .net 4.8 is installed\n ^ here\n”  
}

Role is this:

- import\_role:  
name: net481  
when: “‘4.8’ in {{ script\_run }}”

Task Ran:

- name: Check if .net 4.8 is installed  
ansible.windows.win\_shell:  
(Get-ItemProperty “HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full”).version -lt 4.8  
register: script\_run - name: Install .net 4.8, if not installed

ansible.builtin.script: /etc/ansible/roles/onprembaseline/files/net48.ps1  
register: script\_run

---

<div class="post-metadata">

**Author:** ![Oleg\_Galushko](https://avatars.discourse-cdn.com/v4/letter/o/e274bd/32.png) [@Oleg\_Galushko](https://forum.ansible.com/u/Oleg_Galushko)\
**Post date:** [January 21, 2022, 8:51pm UTC](https://forum.ansible.com/t/check-for-existing-installed-software/36135/7 "2022-01-21T20:51:09Z")

</div>

Use idempotent way. It will be installed if it has not already been installed

- ansible.windows.win\_package:  
path: ‘c:\path\to\ndp48-x86-x64-allos-enu.exe’  
product\_id: “{BAAF5851-0759-422D-A1E9-90061B597188}”  
arguments: “/q /norestart”

среда, 19 января 2022 г. в 21:33:41 UTC+3, Nitrous:

---

<div class="post-metadata">

**Author:** ![Nitrous](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@Nitrous](https://forum.ansible.com/u/Nitrous)\
**Post date:** [February 3, 2022, 10:09pm UTC](https://forum.ansible.com/t/check-for-existing-installed-software/36135/8 "2022-02-03T22:09:06Z")

</div>

Thanks.

I have a pretask before installing, where it copies files to the target server, and then run your idempotent way.

How can I do a check, before copying the .net 4.8 exe, if 4.8 exists, and only run the copy/install if .net 4.8 isnt installed/exists.

If it exists, then skip.

Thanks

---

<div class="post-metadata">

**Author:** ![Oleg\_Galushko](https://avatars.discourse-cdn.com/v4/letter/o/e274bd/32.png) [@Oleg\_Galushko](https://forum.ansible.com/u/Oleg_Galushko)\
**Post date:** [February 13, 2022, 4:01am UTC](https://forum.ansible.com/t/check-for-existing-installed-software/36135/9 "2022-02-13T04:01:55Z")

</div>

hm. try to use win\_reg\_stat with register variable to determine what version your need is installed/not installed [https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#use-registry-editor](https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#use-registry-editor)  
and wrap all other installation tasks with block and when condition

пятница, 4 февраля 2022 г. в 01:09:06 UTC+3, Nitrous:

---

<div class="post-metadata">

**Author:** ![Nitrous](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@Nitrous](https://forum.ansible.com/u/Nitrous)\
**Post date:** [February 25, 2022, 5:27pm UTC](https://forum.ansible.com/t/check-for-existing-installed-software/36135/10 "2022-02-25T17:27:28Z")

</div>

Thanks, mind showing me an example, on how to use the win\_reg\_stat with register variable?

---

<div class="post-metadata">

**Author:** ![HAMIDOU\_OUARO](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@HAMIDOU\_OUARO](https://forum.ansible.com/u/HAMIDOU_OUARO)\
**Post date:** [February 26, 2022, 12:10pm UTC](https://forum.ansible.com/t/check-for-existing-installed-software/36135/11 "2022-02-26T12:10:57Z")

</div>

Bonjour. je suis nouveau dans l’utilisation de ansible. Besoin d’aide  
Comment pointer sur la nouvelle version de ansible puisqu’on me dit que ansible2.7.10 est dépassé.  
voici le message d’erreur. Je vous remercie.  
/home/user-ansible/ansible2.7.10/local/lib/python2.7/site-packages/ansible/parsing/vault/ **init**.py:41: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.  
from cryptography.exceptions import InvalidSignature  
ERROR! - the directory ./apache already exists.you can use --force to re-initialize this directory,  
however it will reset any main.yml files that may have  
been modified there already.
