Ansible, Windows and PowerShell: the Basics – Part 15, Install Chocolatey Packages

In Part 15 of this series we’ll continue our journey with Ansible, Windows and PowerShell and look at how to install software packages via Chocolatey.

In this example we’ll demonstrate how to install Visual Studio Code and PowerShell 7.0 Preview using the win_chocolatey Ansible module.

This module will first of all install chocolatey if it is not present on the system. You’ll receive a warning during playbook execution if Chocolatey was installed. Of course you could instead include Chocolatey as part of your Windows base image.

Our server currently has no applications installed:

Our job template in AWX is _14_install_chocolatey_packages:

The contents of _14_install_chocolatey_packages.yml are as follows:

Note that the first step involves installing some supporting Chocolatey extensions, chocolatey-core.extension and chocolatey-windowsupdate.extension . How did I know these were required to install first? Well, mostly because neither VS Code nor PowerShell Preview installed at first.

A combination of looking through the logs of the playbook which complained about various things missing……

….plus on the Chocolatey site dependencies are listed for each application:

VS Code:


Adding the dependencies listed in step 1 and changing the application to install from vscode to vscode.install in step 2 resolved the issues.

Then running a job from the _14_install_chocolatey_packages job template produces the following result:

Observe VS Code and PowerShell 7 Preview have both been installed: