Automatically install Firefox extensions

This commit is contained in:
2026-11-28 16:18:32 +00:00
parent d20cba3e15
commit bda2cb18c4
9 changed files with 145 additions and 54 deletions

View File

@@ -12,6 +12,7 @@
roles:
- role: mas
- role: firefox
- role: hiddenbar
- role: iterm
- role: kitty

View File

@@ -0,0 +1,28 @@
---
- name: install homebrew package
homebrew_cask:
name: firefox
state: latest
- name: set enterprise policies
set_fact:
firefox_darwin_policies: >-
{{ (lookup('template', 'policies.json.j2') | from_json).policies
| combine({'EnterprisePoliciesEnabled': true}) }}
- name: read current enterprise policies
command: plutil -convert json -o - /Library/Preferences/org.mozilla.firefox.plist
register: firefox_current_policies
changed_when: false
failed_when: false
- name: install enterprise policies
when: >-
firefox_current_policies.rc != 0 or
firefox_current_policies.stdout | from_json != firefox_darwin_policies
become: true
shell: >-
plutil -convert xml1 -o - - |
defaults import /Library/Preferences/org.mozilla.firefox -
args:
stdin: '{{ firefox_darwin_policies | to_json }}'

View File

@@ -0,0 +1,44 @@
---
- include_tasks: Ubuntu.yaml
when: ansible_distribution == 'Ubuntu'
- name: create keyrings directory
become: true
file:
path: /etc/apt/keyrings
mode: '755'
state: directory
- name: install mozilla repo keyring
become: true
get_url:
url: https://packages.mozilla.org/apt/repo-signing-key.gpg
dest: /etc/apt/keyrings/packages.mozilla.org.asc
environment: '{{proxy_environment}}'
- name: add mozilla apt repo
become: true
copy:
content: >-
deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc]
https://packages.mozilla.org/apt mozilla main
dest: /etc/apt/sources.list.d/mozilla.list
- name: pin mozilla package
become: true
copy:
content: |
Package: *
Pin: origin packages.mozilla.org
Pin-Priority: 1000
dest: /etc/apt/preferences.d/mozilla
- name: install mozilla package
become: true
apt:
name: firefox
state: latest
allow_downgrade: true
update_cache: true
- include_tasks: Linux.yaml

View File

@@ -0,0 +1,21 @@
---
- name: install gnome shell integration
when: "'GNOME' in ansible_env.XDG_CURRENT_DESKTOP | default('')"
become: true
package:
name: gnome-browser-connector
state: latest
- name: create policies directory
become: true
file:
path: /etc/firefox/policies
mode: '755'
state: directory
- name: install enterprise policies
become: true
template:
src: policies.json.j2
dest: /etc/firefox/policies/policies.json
mode: '644'

View File

@@ -0,0 +1,8 @@
---
- name: install dnf package
become: true
dnf:
name: firefox
state: latest
- include_tasks: Linux.yaml

View File

@@ -4,49 +4,3 @@
snap:
name: firefox
state: absent
- name: create keyrings directory
become: true
file:
path: /etc/apt/keyrings
mode: '755'
state: directory
- name: install mozilla repo keyring
become: true
get_url:
url: https://packages.mozilla.org/apt/repo-signing-key.gpg
dest: /etc/apt/keyrings/packages.mozilla.org.asc
environment: '{{proxy_environment}}'
- name: add mozilla apt repo
become: true
copy:
content: >-
deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc]
https://packages.mozilla.org/apt mozilla main
dest: /etc/apt/sources.list.d/mozilla.list
- name: pin mozilla package
become: true
copy:
content: |
Package: *
Pin: origin packages.mozilla.org
Pin-Priority: 1000
dest: /etc/apt/preferences.d/mozilla
- name: install mozilla package
become: true
apt:
name: firefox
state: latest
allow_downgrade: true
update_cache: true
- name: install gnome shell integration
when: "'GNOME' in ansible_env.XDG_CURRENT_DESKTOP"
become: true
apt:
name: chrome-gnome-shell
state: latest

View File

@@ -8,7 +8,12 @@
/NoAutoUpdate
state: latest
# - TODO: create extensions directory
# file:
# path: '{{ansible_env.ProgramFiles}}/Mozilla Firefox/distribution/extensions'
# state: directory
- name: create distribution directory
win_file:
path: '{{ansible_env.ProgramFiles}}\Mozilla Firefox\distribution'
state: directory
- name: install enterprise policies
win_template:
src: policies.json.j2
dest: '{{ansible_env.ProgramFiles}}\Mozilla Firefox\distribution\policies.json'

View File

@@ -1,5 +1,23 @@
---
- include_tasks: Windows.yaml
when: ansible_os_family == 'Windows'
- include_tasks: Ubuntu.yaml
when: ansible_distribution == 'Ubuntu'
# Extensions installed via Firefox enterprise policies on every platform.
# id: the extension's ID (about:support -> Add-ons, or AMO API)
# slug: the addons.mozilla.org URL name, used to fetch the latest release
- name: set extensions to install
set_fact:
firefox_extensions:
- id: '{d634138d-c276-4fc8-924b-40a0ea21d284}'
slug: 1password-x-password-manager
- id: '{74145f27-f039-47ce-a470-a662b129930a}'
slug: clearurls
- id: gdpr@cavi.au.dk
slug: consent-o-matic
- id: '@contain-facebook'
slug: facebook-container
- id: movetabs.virtual438@aleeas.com
slug: move-tabs-and-groups
- id: uBlock0@raymondhill.net
slug: ublock-origin
- id: '{aecec67f-0d10-4fa7-b7c7-609a2db280cf}'
slug: violentmonkey
- include_tasks: '{{ansible_os_family}}.yaml'

View File

@@ -0,0 +1,12 @@
{
"policies": {
"ExtensionSettings": {
{% for extension in firefox_extensions %}
{{ extension.id | to_json }}: {
"installation_mode": "normal_installed",
"install_url": {{ ('https://addons.mozilla.org/firefox/downloads/latest/' ~ extension.slug ~ '/latest.xpi') | to_json }}
}{{ ',' if not loop.last else '' }}
{% endfor %}
}
}
}