This role manages APT repositories on Debian-based systems by replacing the default
sources.list, adding custom repositories, and managing GPG keys.
| defaults | ||
| handlers | ||
| meta | ||
| tasks | ||
| templates/sources.list.d | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
manage_repositories Role
This role manages APT repositories on Debian-based systems by replacing the default sources.list, adding custom repositories, and managing GPG keys.
Description
The manage_repositories role provides a modular way to manage APT repositories. It allows you to replace the default sources.list, validate repository definitions, add or remove repositories, and manage GPG keys for secure package installation. The role is designed to be flexible and reusable for various repository management tasks.
Installation
- Ensure that Ansible is installed on your system. The recommended version is at least
2.17. - Clone this repository or add the role to your existing project.
- Ensure that the target system meets the following requirements:
- Debian-based operating system (e.g., Ubuntu, Debian)
- Access to the internet for downloading GPG keys and repository metadata
Variables
The role uses the following variables:
manage_repositories_mirror_urlThe base URL for the main Debian package mirror.
Example:http://ftp.de.debian.orgmanage_repositories_security_urlThe base URL for the Debian security updates repository.
Example:http://security.debian.orgmanage_repositories_distributionThe Debian distribution codename to use (e.g.,bookworm,bullseye).
Example:bookwormmanage_repositories_componentsSpace-separated list of Debian repository components to include.
Default:contrib non-free non-free-firmwaremanage_repositories_backportsWhether to add the backports repository for the specified distribution.
Default:falsemanage_repositories_repos
A list of repositories to be managed. Each repository should include the following keys:name: The name of the repository (used for the.listfile).keyrings_url: URL to the GPG key for the repository.keyrings_format: Format of the GPG key, eitherasciiorbinary.keyrings_file: Destination filename for the GPG key (placed in/etc/apt/keyrings/).repo_url: The repository's full URL and distribution/component string (e.g.,https://deb.nodesource.com/node_20.x nodistro main).state(optional): Whether the repository should bepresentorabsent.
Default:presentupdate_cache(optional): Whether to update the APT cache after adding the repository.
Default:truerecreate_source(optional): Whether to remove and recreate the existing repository file.
Default:false
Usage
Example Playbook
- name: Update sources.list
ansible.builtin.include_role:
name: manage_repositories
vars:
manage_repositories_mirror_url: 'http://ftp.de.debian.org'
manage_repositories_security_url: 'http://security.debian.org'
manage_repositories_distribution: 'bookworm'
manage_repositories_components: 'contrib non-free non-free-firmware'
manage_repositories_backports: true
- name: Update repo
ansible.builtin.include_role:
name: manage_repositories
vars:
manage_repositories_repos:
- name: nodejs
keyrings_url: 'https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key'
keyrings_format: 'ascii'
keyrings_file: 'nodesource.gpg'
repo_url: 'https://deb.nodesource.com/node_20.x nodistro main'
state: present
update_cache: true
recreate_source: false
Features
- Replace
sources.list: Replaces the default APT sources list with a custom template. - Validate Repository Definitions: Ensures that all required variables for repositories are defined.
- Add or Remove Repositories: Dynamically manages repository files based on the provided configuration.
- Manage GPG Keys: Downloads and installs GPG keys for secure repository access.
- APT Cache Management: Updates the APT cache when necessary.
- Modular Design: Tasks are split into logical components for better maintainability.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your changes.
- Submit a pull request describing your changes.
License
This project is licensed under the MIT License. For more information, see the LICENSE file.