Vendor Galaxy Roles and Collections

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

View file

@ -0,0 +1,19 @@
debops.tzdata - Manage system time zone using Ansible
Copyright (C) 2020 Maciej Delmanowski <drybjed@gmail.com>
Copyright (C) 2020 DebOps <https://debops.org/>
SPDX-License-Identifier: GPL-3.0-only
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,70 @@
---
# .. vim: foldmarker=[[[,]]]:foldmethod=marker
# .. Copyright (C) 2020 Maciej Delmanowski <drybjed@gmail.com>
# .. Copyright (C) 2020 DebOps <https://debops.org/>
# .. SPDX-License-Identifier: GPL-3.0-only
# .. _tzdata__ref_defaults:
# debops.tzdata default variables
# ===============================
# .. contents:: Sections
# :local:
#
# .. include:: ../../../../includes/global.rst
# Global options [[[
# ------------------
# .. envvar:: tzdata__enabled [[[
#
# Enable or disable time zone management using the :ref:`debops.tzdata` role.
tzdata__enabled: True
# ]]]
# .. envvar:: tzdata__timezone [[[
#
# Specify timezone in the form of 'Area/Zone'. Use :command:`timedatectl
# list-timezones` to see a list of possible values. To set the UTC timezone,
# specify it as 'Etc/UTC'.
tzdata__timezone: '{{ ansible_local.tzdata.timezone | d("Etc/UTC") }}'
# ]]]
# ]]]
# APT packages [[[
# ----------------
# .. envvar:: tzdata__base_packages [[[
#
# List of the APT packages to install for time zone support.
tzdata__base_packages: [ 'tzdata' ]
# ]]]
# .. envvar:: tzdata__packages [[[
#
# List of additional APT packages to install with the ``tzdata`` package.
tzdata__packages: []
# ]]]
# ]]]
# Service restart [[[
# -------------------
# .. envvar:: tzdata__restart_default_services [[[
#
# List of the default :command:`systemd` service units which should be
# restarted when time zone is changed. Only currently active services will be
# restarted.
tzdata__restart_default_services:
- 'cron.service'
- 'rsyslog.service'
# ]]]
# .. envvar:: tzdata__restart_services [[[
#
# List of additional :command:`systemd` service units which should be restarted
# when time zone is changed.
tzdata__restart_services: []
# ]]]
# ]]]

View file

@ -0,0 +1,29 @@
---
# Copyright (C) 2020 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2020 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
# 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: 'Configure system time zone'
company: 'DebOps'
license: 'GPL-3.0-only'
min_ansible_version: '2.9.0'
platforms:
- name: Ubuntu
versions:
- all
- name: Debian
versions:
- all
galaxy_tags:
- timezone
- tzdata
- ntp

View file

@ -0,0 +1,62 @@
---
# Copyright (C) 2014-2017 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2017 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2014-2017 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
- name: Configure tzdata area in debconf
ansible.builtin.debconf:
name: 'tzdata'
question: 'tzdata/Areas'
vtype: 'select'
value: '{{ tzdata__timezone.split("/")[0] }}'
register: tzdata__register_debconf_set_area
notify: [ 'Refresh host facts' ]
when: tzdata__enabled | bool
- name: Configure tzdata zone in debconf
ansible.builtin.debconf:
name: 'tzdata'
question: 'tzdata/Zones/{{ tzdata__timezone.split("/")[0] }}'
vtype: 'select'
value: '{{ tzdata__timezone.split("/")[1] }}'
register: tzdata__register_debconf_set_zone
notify: [ 'Refresh host facts' ]
when: tzdata__enabled | bool
# tzdata ignores debconf answers when configured non-interactively
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=704089
- name: Configure timezone in /etc/timezone
ansible.builtin.copy:
content: '{{ tzdata__timezone }}'
dest: '/etc/timezone'
mode: '0644'
register: tzdata__register_etc_timezone
notify: [ 'Refresh host facts' ]
when: tzdata__enabled | bool
- name: Check if /etc/localtime is a symlink
ansible.builtin.stat:
path: '/etc/localtime'
register: tzdata__register_etc_localtime
when: tzdata__enabled | bool
- name: Symlink correct timezone as /etc/localtime
ansible.builtin.file: # noqa no-handler
path: '/etc/localtime'
src: '/usr/share/zoneinfo/{{ tzdata__timezone }}'
state: 'link'
mode: '0644'
notify: [ 'Refresh host facts' ]
when: (tzdata__enabled | bool and
tzdata__register_etc_timezone is changed and
tzdata__register_etc_localtime.stat.islnk | bool)
- name: Reconfigure tzdata
ansible.builtin.command: 'dpkg-reconfigure --frontend noninteractive tzdata' # noqa no-handler
register: tzdata__register_dpkg_reconfigure
changed_when: tzdata__register_dpkg_reconfigure.changed | bool
when: (tzdata__enabled | bool and
(tzdata__register_debconf_set_area is changed or
tzdata__register_debconf_set_zone is changed or
tzdata__register_etc_timezone is changed))

View file

@ -0,0 +1,74 @@
---
# Copyright (C) 2020 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2020 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
- name: Import DebOps global handlers
ansible.builtin.import_role:
name: 'global_handlers'
- name: Install required packages
ansible.builtin.package:
name: '{{ q("flattened", tzdata__base_packages + tzdata__packages) }}'
state: '{{ "present"
if ((ansible_local.tzdata.configured | d()) | bool)
else "latest" }}'
register: tzdata__register_packages
until: tzdata__register_packages is succeeded
when: tzdata__enabled | bool
- name: Make sure that Ansible local facts directory exists
ansible.builtin.file:
path: '/etc/ansible/facts.d'
state: 'directory'
mode: '0755'
when: tzdata__enabled | bool and not ansible_local | d()
- name: Save tzdata local facts
ansible.builtin.template:
src: 'etc/ansible/facts.d/tzdata.fact.j2'
dest: '/etc/ansible/facts.d/tzdata.fact'
mode: '0755'
notify: [ 'Refresh host facts' ]
when: tzdata__enabled | bool
tags: [ 'meta::facts' ]
- name: Update Ansible facts if they were modified
ansible.builtin.meta: 'flush_handlers'
- name: Configure the time zone
community.general.timezone:
name: '{{ tzdata__timezone }}'
register: tzdata__register_timezone
notify: [ 'Refresh host facts' ]
when: (tzdata__enabled | bool and ansible_service_mgr == "systemd" and
(ansible_local.tzdata.timezone | d('Etc/UTC')) != tzdata__timezone)
- name: Execute legacy timezone tasks
ansible.builtin.include_tasks: 'legacy.yml'
when: (tzdata__enabled | bool and ansible_service_mgr != "systemd" and
(ansible_local.tzdata.timezone | d('Etc/UTC')) != tzdata__timezone)
- name: Update Ansible facts if time zone was modified
ansible.builtin.meta: 'flush_handlers'
- name: Get list of currently running systemd services
ansible.builtin.shell: set -o nounset -o pipefail -o errexit &&
systemctl list-units --state active | awk 'match($1, /\./) {print $1}'
args: # noqa no-handler
executable: 'bash'
register: tzdata__register_services
changed_when: tzdata__register_services.changed | bool
when: (tzdata__enabled | bool and ansible_service_mgr == 'systemd' and
tzdata__register_timezone is changed)
- name: Request restart of services affected by time zone modification
ansible.builtin.systemd: # noqa no-handler
name: '{{ item }}'
state: 'restarted'
no_block: True
loop: '{{ q("flattened", (tzdata__restart_default_services
+ tzdata__restart_services)) }}'
when: (tzdata__enabled | bool and ansible_service_mgr == 'systemd' and
tzdata__register_timezone is changed and
item in tzdata__register_services.stdout_lines)

View file

@ -0,0 +1,30 @@
#!{{ ansible_python['executable'] }}
# -*- coding: utf-8 -*-
# Copyright (C) 2020 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2020 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
# {{ ansible_managed }}
from __future__ import print_function
from json import loads, dumps
import subprocess
import os
timezone_file = '/etc/timezone'
output = loads('''{{ {"configured": True,
"enabled": tzdata__enabled | bool
} | to_nice_json }}''')
if os.path.exists(timezone_file) and os.path.isfile(timezone_file):
try:
with open(timezone_file, 'r') as f:
for line in f:
output.update({'timezone': line.strip()})
except Exception:
pass
print(dumps(output, sort_keys=True, indent=4))