Ansible, Windows and PowerShell: the Basics – Part 13, Environment Variables
In Part 13 of this series we’ll continue our journey with Ansible, Windows and PowerShell and look at how to handle environment variables in Windows.
In this example we’ll look at a common scenario where you need to manually create the JAVA_HOME environment variable and add it to the existing PATH environment variable because the application install does not complete that for you. We will use a combination of the win_environment and win_path Ansible modules.
Our current environment variables are as below with no entries for JAVA_HOME:
Our job template in AWX is _12_environment_variables:
The contents of _12_environment_variables.yml are as follows:
Running a job from the _12_environment_variables job template produces the following result:
Our server now has both the JAVA_HOME environment variable and it has been added to PATH:
- 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