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:
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:
- Ansible, Windows and PowerShell: the Basics – Introduction
- Ansible, Windows and PowerShell: the Basics - Part 1, Windows Services
- Ansible, Windows and PowerShell: the Basics - Part 2, Install PowerShell Modules
- Ansible, Windows and PowerShell: the Basics – Part 3, Windows Roles and Features
- Ansible, Windows and PowerShell: the Basics – Part 4, Invoking PowerShell Code
- Ansible, Windows and PowerShell: the Basics – Part 5, Example PowerShell Error Handling
- Ansible, Windows and PowerShell: the Basics – Part 6, Displaying Output from PowerShell Code
- Ansible, Windows and PowerShell: the Basics – Part 7, Utilising PowerShell DSC
- Ansible, Windows and PowerShell: the Basics – Part 8, Rebooting & Waiting
- Ansible, Windows and PowerShell: the Basics – Part 9, Disk Creation
- Ansible, Windows and PowerShell: the Basics – Part 10, Local Users
- Ansible, Windows and PowerShell: the Basics – Part 11, Local Groups
- Ansible, Windows and PowerShell: the Basics – Part 12, Set TimeZone
- Ansible, Windows and PowerShell: the Basics – Part 13, Environment Variables
- Ansible, Windows and PowerShell: the Basics – Part 14, Registry Entries
- Ansible, Windows and PowerShell: the Basics – Part 15, Install Chocolatey Packages