Last active
October 27, 2024 14:39
-
-
Save roib20/27fde10af195cee1c1f8ac5f68be7e9b to your computer and use it in GitHub Desktop.
Example usages of the new `deb822_repository` Ansible module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
connection: local | |
gather_facts: true | |
tasks: | |
- name: Add APT repositories | |
when: ansible_os_family == 'Debian' | |
become: true | |
block: | |
- name: Add VSCode APT repository | |
ansible.builtin.deb822_repository: | |
name: vscode | |
types: [deb] | |
uris: "https://packages.microsoft.com/repos/code" | |
signed_by: "https://packages.microsoft.com/keys/microsoft.asc" | |
suites: [stable] | |
components: [main] | |
state: present | |
enabled: yes | |
- name: Add google APT repository | |
ansible.builtin.deb822_repository: | |
name: google | |
types: [deb] | |
uris: | |
- "http://dl.google.com/linux/chrome/deb" | |
- "http://dl.google.com/linux/earth/deb" | |
signed_by: "https://dl.google.com/linux/linux_signing_key.pub" | |
suites: [stable] | |
components: [main] | |
state: present | |
enabled: yes | |
- name: Add Kubernetes APT repository | |
ansible.builtin.deb822_repository: | |
name: kubernetes | |
types: [deb] | |
uris: "https://apt.kubernetes.io" | |
signed_by: "https://packages.cloud.google.com/apt/doc/apt-key.gpg" | |
suites: [kubernetes-xenial] | |
components: [main] | |
state: present | |
enabled: yes | |
- name: Add google-cloud-cli APT repository | |
ansible.builtin.deb822_repository: | |
name: google-cloud-cli | |
types: [deb] | |
uris: "https://packages.cloud.google.com/apt" | |
signed_by: "https://packages.cloud.google.com/apt/doc/apt-key.gpg" | |
suites: [cloud-sdk] | |
components: [main] | |
state: present | |
enabled: yes | |
- name: Add Microsoft prod APT repository (Debian) | |
when: ansible_distribution == 'Debian' | |
ansible.builtin.deb822_repository: | |
name: packages-microsoft-com-prod | |
types: [deb] | |
uris: "https://packages.microsoft.com/{{ ansible_distribution|lower }}/{{ ansible_distribution_major_version }}/prod" | |
signed_by: "https://packages.microsoft.com/keys/microsoft.asc" | |
suites: ["{{ ansible_distribution_release|lower }}"] | |
components: [main] | |
state: present | |
enabled: yes | |
- name: Add Microsoft prod APT repository (Ubuntu) | |
when: ansible_distribution == 'Ubuntu' | |
ansible.builtin.deb822_repository: | |
name: packages-microsoft-com-prod | |
types: [deb] | |
uris: "https://packages.microsoft.com/{{ ansible_distribution|lower }}/{{ ansible_distribution_version }}/prod" | |
signed_by: "https://packages.microsoft.com/keys/microsoft.asc" | |
suites: ["{{ ansible_distribution_release|lower }}"] | |
components: [main] | |
state: present | |
enabled: yes | |
- name: Add Tailscale stable APT repository | |
ansible.builtin.deb822_repository: | |
name: tailscale-stable | |
types: [deb] | |
uris: "https://pkgs.tailscale.com/stable/{{ ansible_distribution|lower }}" | |
signed_by: "https://pkgs.tailscale.com/stable/{{ ansible_distribution|lower }}/{{ ansible_distribution_release|lower }}.asc" | |
suites: ["{{ ansible_distribution_release|lower }}"] | |
components: [main] | |
state: present | |
enabled: yes | |
- name: Add Hashicorp Stable APT repository | |
ansible.builtin.deb822_repository: | |
name: hashicorp | |
types: [deb] | |
uris: "https://apt.releases.hashicorp.com" | |
signed_by: "https://apt.releases.hashicorp.com/gpg" | |
suites: ["{{ ansible_distribution_release|lower }}"] | |
components: [main] | |
state: present | |
enabled: yes |
A few more examples with mozilla, spotify, tableplus and mongoDB 8.0:
- name: Add Mozilla APT repository
ansible.builtin.deb822_repository:
name: mozilla
types: [deb]
uris: https://packages.mozilla.org/apt
signed_by: https://packages.mozilla.org/apt/repo-signing-key.gpg
suites: [mozilla]
components: [main]
enabled: true
- name: Add Spotify APT repository
ansible.builtin.deb822_repository:
name: spotify
types: [deb]
uris: http://repository.spotify.com
signed_by: https://download.spotify.com/debian/pubkey_6224F9941A8AA6D1.gpg
suites: [stable]
components: [non-free]
enabled: true
- name: Add TablePlus APT repository
ansible.builtin.deb822_repository:
name: tableplus
types: [deb]
uris: "https://deb.tableplus.com/debian/{{ ansible_distribution_major_version }}"
signed_by: https://deb.tableplus.com/apt.tableplus.com.gpg.key
suites: [tableplus]
components: [main]
enabled: true
- name: Add MongoDB 8.0 repository
ansible.builtin.deb822_repository:
name: mongodb-org-8.0
types: [deb]
uris: "https://repo.mongodb.org/apt/{{ ansible_distribution|lower }}"
signed_by: https://www.mongodb.org/static/pgp/server-8.0.asc
suites: ["{{ ansible_distribution_release|lower }}/mongodb-org/8.0"]
components: [multiverse]
enabled: true
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that the
deb822_repository
module requires thepython3-debian
package to be installed. This can be installed in a virtual environment withpip install python-debian
.The
deb822
format allows signing keys to be included in the same.source
file rather than added to the/etc/apt/trusted.gpg.d
folder. This is a better approach because the signing key will be associated only with it's own repository, and not with all repositories globally. This will give a result as close as possible to the nativeadd-apt-repository
: