Ansible Pilot

Check Registry .NET Framework version on Windows-like systems - Ansible module win_reg_stat

How to automate the check of the .NET Framework version installed in the Windows-like machine using the Windows Registry with Ansible Playbook.

March 15, 2022
Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons

How to Check the .NET Framework version on Windows-like systems with Ansible?

The principle is to read the right Windows Registry key, store in a variable, and display it on the screen. I’m going to show you a live demo and some simple Ansible code. I’m Luca Berton and welcome to today’s episode of Ansible Pilot

Ansible read Windows Registry

Today we’re talking about the Ansible module win_reg_stat. The full name is ansible.windows.win_reg_stat, which means that is part of the collection of modules specialized to interact with Windows target host. It’s a module pretty stable and out for years. It works in Windows and Windows Server operating systems. It gets information about Windows registry keys.

Parameters & Return Values

Parameters

Main Return Values

The only mandatory parameter is “path” which is the full registry key path including the hive to search for. You probably would like to specify also the “name” of the key path including the hive to search for. The module returns multiple properties. The most useful are “exists” if the key/property exist in the registry, The value of the key is accessible via the “value” and “raw_value” attributes. Other useful attributes are “type” for the property type and “sub_key” for a list of all the subkeys of the key specified.

The Best Resources For Ansible

Certifications

Video Course

Printed Book

eBooks

demo

How to check the .NET Framework version on Windows-like systems accessing the Windows Registry with Ansible Playbook. Specifically, the Windows Registry key is “Version” located in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full.

code

---
- name: win_reg_stat module demo
  hosts: all
  tasks:
    - name: check .NET version
      ansible.windows.win_reg_stat:
        path: 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full'
        name: "Version"
      register: reg_val
    - name: print .NET version
      ansible.builtin.debug:
        msg: "{{ reg_val }}"

execution

ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory windows/printdotnet.yml
PLAY [win_reg_stat module demo] *************************************************************
TASK [Gathering Facts] **********************************************************************
ok: [WindowsServer]
TASK [check .NET version] *******************************************************************
ok: [WindowsServer]
TASK [print .NET version] *******************************************************************
ok: [WindowsServer] => {
    "msg": {
        "changed": false,
        "exists": true,
        "failed": false,
        "raw_value": "4.7.03190",
        "type": "REG_SZ",
        "value": "4.7.03190"
    }
}
PLAY RECAP **********************************************************************************
WindowsServer              : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ansible-pilot $

idempotency

ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory windows/printdotnet.yml
PLAY [win_reg_stat module demo] *************************************************************
TASK [Gathering Facts] **********************************************************************
ok: [WindowsServer]
TASK [check .NET version] *******************************************************************
ok: [WindowsServer]
TASK [print .NET version] *******************************************************************
ok: [WindowsServer] => {
    "msg": {
        "changed": false,
        "exists": true,
        "failed": false,
        "raw_value": "4.7.03190",
        "type": "REG_SZ",
        "value": "4.7.03190"
    }
}
PLAY RECAP **********************************************************************************
WindowsServer              : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ansible-pilot $

manual check

win_reg_stat Windows Registry

code with ❤️ in GitHub

Recap

Now you know how to check the Windows Registry .NET Framework version on Windows-like systems with Ansible.

Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.

Academy

Learn the Ansible automation technology with some real-life examples in my

My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps

BUY the Complete PDF BOOK to easily Copy and Paste the 250+ Ansible code

Want to keep this project going? Please donate

Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons
Follow me

Subscribe not to miss any new releases