Ansible Playbook – Install PowerShell 7 on Ubuntu Server 20.04

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.


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
     - name: Update packege lists 
        update_cache: yes
     - name: Download PGP security keys
        dest: /tmp/packages-microsoft-prod.deb
        force_basic_auth: yes
     - name: Register PGP security keys
        cmd: dpkg -i /tmp/packages-microsoft-prod.deb
     - name: Update packege lists
        update_cache: yes    
     - name: Install latest version of PowerShell 7
        name: powershell

After the task finished, PowerShell will be available on the servers. To start PowerShell 7, run the following command:


To uninstall PowerShell you can issue the following command.

apt-get remove powershell

For more Ansible articles visit the this page.

Success! You're on the list.