Vendor Galaxy Roles and Collections
Some checks failed
/ Ansible Lint (push) Failing after 5m45s
/ Ansible Lint (pull_request) Failing after 4m59s

This commit is contained in:
Stefan Bethke 2026-02-06 22:07:16 +01:00
commit 2aed20393f
6 changed files with 387444 additions and 2 deletions

View file

@ -0,0 +1,19 @@
debops.extrepo - Manage external APT sources using Ansible
Copyright (C) 2021 Maciej Delmanowski <drybjed@gmail.com>
Copyright (C) 2021 DebOps <https://debops.org/>
SPDX-License-Identifier: GPL-3.0-or-later
This Ansible role is part of DebOps.
DebOps is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3, as
published by the Free Software Foundation.
DebOps is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DebOps. If not, see https://www.gnu.org/licenses/.

View file

@ -0,0 +1,128 @@
---
# .. vim: foldmarker=[[[,]]]:foldmethod=marker
# .. Copyright (C) 2021 Maciej Delmanowski <drybjed@gmail.com>
# .. Copyright (C) 2021 DebOps <https://debops.org/>
# .. SPDX-License-Identifier: GPL-3.0-or-later
# .. _extrepo__ref_defaults:
# debops.extrepo default variables
# ================================
# .. contents:: Sections
# :local:
#
# .. include:: ../../../../includes/global.rst
# Installation and packages [[[
# -----------------------------
# .. envvar:: extrepo__enabled [[[
#
# Enable or disable configuration of external APT repositories using the
# :command:`extrepo` command.
extrepo__enabled: '{{ False
if (ansible_distribution != "Debian" or
ansible_distribution_release in ["stretch"])
else True }}'
# ]]]
# .. envvar:: extrepo__base_packages [[[
#
# List of the default APT packages to install for :command:`extrepo` support.
# On Debian Buster, the ``extrepo`` package is available via the
# ``buster-backports`` repository.
extrepo__base_packages: [ 'extrepo' ]
# ]]]
# .. envvar:: extrepo__packages [[[
#
# List of additional packages to install with :command:`extrepo`.
extrepo__packages: []
# ]]]
# ]]]
# Main configuration file [[[
# ---------------------------
# These variables define the contents of the :file:`/etc/extrepo/config.yaml`
# configuration file. See :ref:`extrepo__ref_configuration` for more details.
# .. envvar:: extrepo__default_configuration [[[
#
# The list with default contents of the configuration file defined by the role.
extrepo__default_configuration:
- name: 'defaults'
config:
url: 'https://extrepo-team.pages.debian.net/extrepo-data'
dist: '{{ ansible_distribution | lower }}'
version: '{{ ansible_distribution_release }}'
- name: 'policies'
config:
enabled_policies: '{{ ansible_local.apt.components | d(["main"]) }}'
# ]]]
# .. envvar:: extrepo__configuration [[[
#
# List of custom contents of the configuration file defined by the user.
extrepo__configuration: []
# ]]]
# .. envvar:: extrepo__combined_configuration [[[
#
# The variable which combines the lists of configuration file contents and is
# used in role tasks and templates.
extrepo__combined_configuration: '{{ extrepo__default_configuration
+ extrepo__configuration }}'
# ]]]
# ]]]
# External APT sources [[[
# ------------------------
# These lists define what external APT sources should be enabled on a given
# host. You can find a list of available APT sources by running the
# :command:`extrepo search` command.
#
# See :ref:`extrepo__ref_sources` for more details.
# .. envvar:: extrepo__sources [[[
#
# List of the external APT sources which should be enabled on all hosts in the
# Ansible inventory.
extrepo__sources: []
# ]]]
# .. envvar:: extrepo__group_sources [[[
#
# List of the external APT sources which should be enabled on hosts in
# a specific Ansible inventory group.
extrepo__group_sources: []
# ]]]
# .. envvar:: extrepo__host_sources [[[
#
# List of the external APT sources which should be enabled on specific hosts in
# the Ansible inventory.
extrepo__host_sources: []
# ]]]
# .. envvar:: extrepo__dependent_sources [[[
#
# List of the external APT sources defined by other Ansible roles via role
# dependent variables.
extrepo__dependent_sources: []
# ]]]
# .. envvar:: extrepo__combined_sources [[[
#
# Variable which combines all lists of external APT sources and is used in role
# tasks and templates.
extrepo__combined_sources: '{{ extrepo__dependent_sources
+ extrepo__sources
+ extrepo__group_sources
+ extrepo__host_sources }}'
# ]]]
# ]]]

View file

@ -0,0 +1,31 @@
---
# Copyright (C) 2021 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2021-2022 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-or-later
# Ensure that custom Ansible plugins and modules included in the main DebOps
# collection are available to roles in other collections.
collections: [ 'debops.debops' ]
dependencies: []
galaxy_info:
author: 'Maciej Delmanowski'
description: 'Manage external APT sources using extrepo'
company: 'DebOps'
license: 'GPL-3.0-or-later'
min_ansible_version: '2.9.0'
platforms:
- name: 'Ubuntu'
versions: [ 'all' ]
- name: 'Debian'
versions: [ 'all' ]
galaxy_tags:
- system
- packages
- apt

View file

@ -0,0 +1,98 @@
---
# Copyright (C) 2021 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2021 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Import custom Ansible plugins
ansible.builtin.import_role:
name: 'ansible_plugins'
- name: Import DebOps global handlers
ansible.builtin.import_role:
name: 'global_handlers'
- name: Install required packages
ansible.builtin.package:
name: '{{ q("flattened", (extrepo__base_packages
+ extrepo__packages)) }}'
state: 'present'
register: extrepo__register_packages
until: extrepo__register_packages is succeeded
when: extrepo__enabled | bool
- name: Make sure that Ansible local facts directory exists
ansible.builtin.file:
path: '/etc/ansible/facts.d'
state: 'directory'
mode: '0755'
- name: Save extrepo local facts
ansible.builtin.template:
src: 'etc/ansible/facts.d/extrepo.fact.j2'
dest: '/etc/ansible/facts.d/extrepo.fact'
mode: '0755'
notify: [ 'Refresh host facts' ]
tags: [ 'meta::facts' ]
- name: Update Ansible facts if they were modified
ansible.builtin.meta: 'flush_handlers'
- name: Divert original extrepo configuration
debops.debops.dpkg_divert:
path: '/etc/extrepo/config.yaml'
state: 'present'
when: extrepo__enabled | bool and ansible_pkg_mgr == 'apt'
- name: Generate extrepo configuration file
ansible.builtin.template:
src: 'etc/extrepo/config.yaml.j2'
dest: '/etc/extrepo/config.yaml'
mode: '0644'
register: extrepo__register_config
when: extrepo__enabled | bool
- name: Update external APT sources if required
ansible.builtin.command: 'extrepo update {{ item.name }}' # noqa no-handler
loop: '{{ q("flattened", extrepo__combined_sources) | debops.debops.parse_kv_config }}'
loop_control:
label: '{{ {"name": item.name, "state": item.state} }}'
register: extrepo__register_updated_sources
changed_when: extrepo__register_updated_sources.changed | bool
when: extrepo__enabled | bool and item.name in ansible_local.extrepo.sources | d() and
item.state | d('present') not in ['absent', 'init', 'ignore'] and
extrepo__register_config is changed
- name: Remove external APT sources when requested
ansible.builtin.file:
path: '{{ "/etc/apt/sources.list.d/extrepo_" + item.name + ".sources" }}'
state: 'absent'
loop: '{{ q("flattened", extrepo__combined_sources) | debops.debops.parse_kv_config }}'
loop_control:
label: '{{ {"name": item.name, "state": item.state} }}'
register: extrepo__register_removed_sources
changed_when: extrepo__register_removed_sources.changed | bool
when: extrepo__enabled | bool and item.name and item.state | d('present') == 'absent'
- name: Enable external APT sources
ansible.builtin.command: 'extrepo enable {{ item.name }}'
loop: '{{ q("flattened", extrepo__combined_sources) | debops.debops.parse_kv_config }}'
loop_control:
label: '{{ {"name": item.name, "state": item.state} }}'
register: extrepo__register_enabled_sources
changed_when: extrepo__register_enabled_sources.changed | bool
when: extrepo__enabled | bool and item.name not in ansible_local.extrepo.sources | d() and
item.state | d('present') not in ['absent', 'init', 'ignore']
- name: Update APT cache if required
ansible.builtin.apt: # noqa no-handler
update_cache: True
notify: [ 'Refresh host facts' ]
register: extrepo__register_apt_cache
until: extrepo__register_apt_cache is succeeded
when: (extrepo__enabled | bool and
(extrepo__register_updated_sources is changed or
extrepo__register_removed_sources is changed or
extrepo__register_enabled_sources is changed))
- name: Update Ansible facts if APT cache was modified
ansible.builtin.meta: 'flush_handlers'

View file

@ -0,0 +1,53 @@
#!{{ ansible_python['executable'] }}
# -*- coding: utf-8 -*-
# Copyright (C) 2021 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2021-2023 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-or-later
# {{ ansible_managed }}
from __future__ import print_function
import json
import subprocess
import os
def cmd_exists(cmd):
return any(
os.access(os.path.join(path, cmd), os.X_OK)
for path in os.environ["PATH"].split(os.pathsep)
)
output = {'installed': cmd_exists('extrepo')}
try:
version_stdout = subprocess.check_output(
["dpkg-query", "-W", "-f=${Version}",
"extrepo"]).decode('utf-8').split('~')[0]
output['version'] = version_stdout
except Exception:
pass
sources_path = '/etc/apt/sources.list.d'
sources_files = [sources_path + "/" + f for f in os.listdir(sources_path)
if os.path.isfile(os.path.join(sources_path, f))]
sources = []
for item in sources_files:
with open(item, mode="r") as fd:
lines = fd.readlines()
# Missing, or 'Enabled: yes\n' means enabled
disabled = 'Enabled: no\n' in lines
if not disabled:
item = os.path.basename(item)
if item.startswith('extrepo_') and item.endswith('.sources'):
sources.append(item[8:-8])
output['sources'] = sources
print(json.dumps(output, sort_keys=True, indent=4))

View file

@ -0,0 +1,14 @@
---
{# Copyright (C) 2021 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2021 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-or-later
#}
# {{ ansible_managed }}
{% set extrepo__tpl_configuration = {} %}
{% for element in extrepo__combined_configuration | debops.debops.parse_kv_items %}
{% if element.state | d('present') not in [ 'absent', 'init', 'ignore' ] %}
{% set combined_config = extrepo__tpl_configuration | combine(element.config, recursive=True) %}
{% set _ = extrepo__tpl_configuration.update(combined_config) %}
{% endif %}
{% endfor %}
{{ extrepo__tpl_configuration | to_nice_yaml }}