Installing Windows Management Framework 5 with Chocolatey via Ansible

You want to install WMF5 so you can manage your Windows machine with Ansible and the win_chocolatey package manager. Here’s a bit of a missing detail:

You have to “become” the SYSTEM user in order to install hotfix install files via Chocolatey. Like this (in a playbook:

– name: Install WMF5 and Powershell5… Note, we have to runas SYSTEM account in order to install hotfixes, like this ( in full playbook form):


– name: Ensure Windows Management Framework v5 is installed, along with Powershell 5
hosts: all
gather_facts: no

tasks:

– name: Install WMF5 and Powershell5… Note, we have to runas SYSTEM account in order to install hotfixes
win_chocolatey:
name: powershell
state: present
register: install_response
become: yes
become_user: SYSTEM
become_method: runas

– name: Reboot the machine if it just installed WMF5, since it requires a reboot after installation
win_reboot:
reboot_timeout: 180
when: install_response.changed == true and install_response.rc == 3010

Here’s the issue thread that filled in that detail for me:
https://github.com/ansible/ansible/issues/39384