Ansible: How to install Bitwarden as Chrome managed extension

In our previous postAnsible: How to install Chrome managed bookmarks we showed how to configure managed bookmarks for Google Chrome using Ansible. In this post, we will extend that configuration to include the Bitwarden password manager as a managed extension.

This is the managed_extensions.json file that you will need to create or update in the same directory as your Ansible playbook:

{
  "ExtensionInstallForcelist": [
    "nngceckbapebfimnlniiiahkandclblb"  // Bitwarden
  ]
}

Here’s the Ansible playbook (managed bookmarks removed for brevity, in case you want to keep them, refer to the previous post):

- name: Install Google Chrome
  become: true
  hosts: all
  tasks:
    - name: Add Google Chrome repository key
      ansible.builtin.apt_key:
        url: https://dl.google.com/linux/linux_signing_key.pub
        state: present

    - name: Add Google Chrome repository
      ansible.builtin.apt_repository:
        repo: deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main
        filename: google-chrome
        state: present

    - name: Install Google Chrome
      ansible.builtin.apt:
        name: google-chrome-stable
        update_cache: yes
        state: present

    - name: Ensure Chrome managed policy directory exists
      file:
        path: "/etc/opt/chrome/policies/managed"
        state: directory
        mode: '0755'

    - name: Copy managed extensions file
      copy:
        src: "managed_extensions.json"
        dest: "/etc/opt/chrome/policies/managed/managed_extensions.json"
        mode: '0644'