Check for existing installed software

1,167 views
Skip to first unread message

Nitrous

unread,
Dec 20, 2021, 10:09:51 AM12/20/21
to Ansible Project

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.

Nitrous

unread,
Dec 21, 2021, 4:25:23 PM12/21/21
to Ansible Project
any suggestions?

Nitrous

unread,
Dec 29, 2021, 11:57:20 AM12/29/21
to Ansible Project
anyone with ideas?

Niek

unread,
Dec 30, 2021, 1:24:36 PM12/30/21
to Ansible Project
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 }}"

Op woensdag 29 december 2021 om 17:57:20 UTC+1 schreef Nitrous:

Niek

unread,
Dec 30, 2021, 1:25:32 PM12/30/21
to Ansible Project
Probably check: https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html

Op donderdag 30 december 2021 om 19:24:36 UTC+1 schreef Niek:

Nitrous

unread,
Jan 19, 2022, 1:33:41 PM1/19/22
to Ansible Project
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

Oleg Galushko

unread,
Jan 21, 2022, 3:51:09 PM1/21/22
to Ansible Project
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:

Nitrous

unread,
Feb 3, 2022, 5:09:06 PM2/3/22
to Ansible Project

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

Oleg Galushko

unread,
Feb 12, 2022, 11:01:55 PM2/12/22
to Ansible Project
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
and wrap all other installation tasks with block and when condition

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

Nitrous

unread,
Feb 25, 2022, 12:27:29 PM2/25/22
to Ansible Project
Thanks, mind showing me an example, on how to use the  win_reg_stat with register variable?

HAMIDOU OUARO

unread,
Feb 26, 2022, 7:11:37 AM2/26/22
to ansible...@googlegroups.com
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.

--
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/86401a66-10cf-42eb-af8b-4e897594bdden%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages