This post will show you how to install PowerShell 7 on Ubuntu server 20.04 using an Ansible Playbook.
Using an Ansible Playbook to install PowerShell 7 helps us make the installation process consistent accross all servers and also save a lot of time.
Playbook
Below is the playbook that will install the latest PowerShell 7 version. The Playbook has four tasks. The first three tasks prepare the server for the installation, and the last task will install the latest PowerShell 7 version (7.1.3).
--- - hosts: servers tasks: - name: Update packege lists apt: update_cache: yes - name: Download PGP security keys get_url: url: https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb dest: /tmp/packages-microsoft-prod.deb force_basic_auth: yes - name: Register PGP security keys command: cmd: dpkg -i /tmp/packages-microsoft-prod.deb - name: Update packege lists apt: update_cache: yes - name: Install latest version of PowerShell 7 apt: name: powershell
After the task finished, PowerShell will be available on the servers. To start PowerShell 7, run the following command:
pwsh
To uninstall PowerShell you can issue the following command.
apt-get remove powershell
For more Ansible articles visit the this page.