Question:
I’m trying to install .Net Framework 4.6.1 using Ansible but until now I have no luck.
I’ve tried those methods:
- Running a win_package to install it, but it just hangs till infinity
123456- name: Install Microsoft NET Frameworkwin_package:path: "http://path/to/dotNetFramework4.6.1.exe"product_id: '{BD6F5371-DAC1-30F0-9DDE-CAC6791E28C3}'register: dotnetfx_exe - Run a PowerShell script to install it (first doesn’t work and second throws stack-overflow exception):
12Install-WindowsFeature Net-Framework-Core -source C:\temp\dotNetFramework4.6.1.exe
Or
12Start-Process -FilePath C:\temp\dotNetFramework4.6.1.exe -ArgumentList "/q /norestart" -Wait -Verb RunAs - I’ve tried to use win_feature to install it, but it just do nothing.
123456789- name: Install NET-Framework-Corewin_feature:name: NET-Framework-Corestate: presentsource: C:\temp\dotNetFramework4.6.1.exeinclude_sub_features: noinclude_management_tools: yesregister: result - Tried to run a batch script to install it, but no luck:
12start /wait c:\temp\dotNetFramework4.6.1.exe /q /norestart /log %TEMP%\dotNetFx4.6.1.log
Has anyone succeeded installing .Net Framework 4.6.1 using Ansible?
Could anyone share their task/role that installs it?
Answer:
We were calling Chocolatey via Ansible to install .NET 4.6.1, but ran into some complications with that. Instead I rewrote our playbook to do a “native” install. I imagine you ran into the same issues I did with trying to run the offline installer. This led me to your post and this thread. Here is what I had to do to get it working.
Extract the contents of the offline installer:
1 2 |
NDP461-KB3102436-x86-x64-AllOS-ENU.exe /s /x /b"C:\tmp\dotnet\dotnet461" /v"/qn" |
This command can uninstall .NET if it is already installed. I just ran it on a fresh vagrant VM instead of trying to get around that.
Zip up the contents of that folder, upload it to an internal host or network share, and then download/unzip/run it with your playbook.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
- name: Download Microsoft .NET Framework 4.6.1 installer win_get_url: url: http://www.path.to/package/dotnet461.zip dest: C:\tmp\dotnet\dotnet461.zip - name: Unzip Microsoft .NET Framework 4.6.1 installer win_unzip: src: C:\tmp\dotnet\dotnet461.zip dest: C:\tmp\dotnet rm: true - name: Run Microsoft .NET Framework 4.6.1 installer raw: C:\tmp\dotnet\dotnet461\Setup.exe /q /norestart /log C:\tmp\dotnet\dotnet461\log.txt /x86 /x64 /redist register: dotnet_install - name: Reboot as required by Microsoft .NET Framework 4.6.1 installer win_reboot: |
The arguments in the install command are important otherwise the installer will fail. You might be able to remove “/log C:\tmp\dotnet\dotnet461\log.txt”, but I’ll leave it to you to test that out 😀
Also this is not idempotent. The installer will execute every time. You can get around that by putting these tasks in a separate .yml file and doing a conditional include based on a registry check to see if it is installed.
Like this:
1 2 3 4 5 6 7 8 9 10 |
- name: Check for current Microsoft .NET Framework 4 version win_reg_stat: path: HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full name: Version register: dotnet_version - name: Install Microsoft .NET Framework 4.6.1 include: install_dotnet.yml when: dotnet_version.value | version_compare('4.6.01', '<', strict=True) |