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
3553 changed files with 387444 additions and 2 deletions

View file

@ -0,0 +1,19 @@
debops.machine - Manage local machine information and MOTD
Copyright (C) 2018 Maciej Delmanowski <drybjed@gmail.com>
Copyright (C) 2018 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,201 @@
---
# .. vim: foldmarker=[[[,]]]:foldmethod=marker
# .. Copyright (C) 2018 Maciej Delmanowski <drybjed@gmail.com>
# .. Copyright (C) 2018 DebOps <https://debops.org/>
# .. SPDX-License-Identifier: GPL-3.0-only
# .. _machine__ref_defaults:
# debops.machine default variables
# ================================
# .. contents:: Sections
# :local:
#
# .. include:: ../../../../includes/global.rst
# General configuration [[[
# -------------------------
# .. envvar:: machine__enabled [[[
#
# Enable or disable support for managing static machine information and MOTD.
machine__enabled: True
# ]]]
# .. envvar:: machine__packages [[[
#
# List of APT packages to install with the ``debops.machine`` role enabled.
machine__packages: []
# ]]]
# ]]]
# Machine information [[[
# -----------------------
# These variables manage contents of the :file:`/etc/machine-info`
# configuration file. See :manpage:`machine-info(5)` and
# :manpage:`hostnamectl(1)` for more details.
# .. envvar:: machine__organization [[[
#
# Human-readable name of the organization that's responsible for this machine.
machine__organization: '{{ ansible_domain.split(".")[0] | capitalize }}'
# ]]]
# .. envvar:: machine__contact [[[
#
# Human-readable contact information for this machine - e-mail, phone number or
# an URL to a web page about a person or team responsible for this host.
machine__contact: '{{ ansible_local.core.admin_public_email[0]
| d("root@" + ansible_domain) }}'
# ]]]
# .. envvar:: machine__pretty_hostname [[[
#
# Human-readable hostname for this machine.
machine__pretty_hostname: ''
# ]]]
# .. envvar:: machine__icon_name [[[
#
# Name of the icon to use for this machine.
machine__icon_name: ''
# ]]]
# .. envvar:: machine__chassis [[[
#
# Specify the machine type to override the autodetected value. Currently
# recognized chassis types: 'desktop', 'laptop', 'server', 'tablet', 'handset',
# 'watch', 'vm', 'container'.
machine__chassis: ''
# ]]]
# .. envvar:: machine__deployment [[[
#
# Define the system deployment environment. Suggested values:
# 'development', 'integration', 'staging', 'production'.
machine__deployment: 'production'
# ]]]
# .. envvar:: machine__location [[[
#
# Describe the physical location where a given system can be found, for example
# a city, or a rack in which the machine is located.
machine__location: ''
# ]]]
# ]]]
# Configuration of the :file:`/etc/motd` file [[[
# -----------------------------------------------
# .. envvar:: machine__motd [[[
#
# String or YAML text block with the welcome message stored in the
# :file:`/etc/motd` configuration file.
machine__motd: ''
# ]]]
# .. envvar:: machine__etc_motd_state [[[
#
# Specify the state of the :file:`/etc/motd` file, either ``present`` (the file
# exists) or ``absent`` (the file will be removed).
machine__etc_motd_state: '{{ "present" if machine__motd | d() else "absent" }}'
# ]]]
# .. envvar:: machine__motd_update_dir [[[
#
# Directory which contains scripts that generate the dynamic MOTD.
machine__motd_update_dir: '/etc/update-motd.d'
# ]]]
# ]]]
# Configuration of the :file:`/etc/issue` file [[[
# ------------------------------------------------
# .. envvar:: machine__etc_issue_state [[[
#
# This variable controls if the role should manage the :file:`/etc/issue`
# configuration file. If ``present``, the role will divert the distribution file
# and generate a custom one; if ``absent``, the role will revert the diverted
# version and will not modify it.
machine__etc_issue_state: 'present'
# ]]]
# .. envvar:: machine__etc_issue_template [[[
#
# Path to the Jinja2 template used to generate the :file:`/etc/issue`
# configuration file, relative to the :file:`templates/` directory of this role.
machine__etc_issue_template: 'etc/issue.j2'
# ]]]
# ]]]
# Dynamic Message Of The Day [[[
# ------------------------------
# These variables control the shell scripts that generate the dynamic MOTD.
# See :ref:`machine__ref_motd_scripts` for more details.
# .. envvar:: machine__motd_default_scripts [[[
#
# The list of the default MOTD scripts managed by the role.
machine__motd_default_scripts:
# This file comes with the 'base-files' APT package on Debian
- name: 'uname'
filename: '10-uname'
divert: True
content: |
#!/bin/sh
uname -snrvm
state: 'init'
- name: 'ansible'
weight: 50
src: 'etc/update-motd.d/ansible'
state: 'present'
- name: 'tail'
weight: 90
content: |
#!/bin/sh
if [ -f /etc/motd.tail ] ; then
cat /etc/motd.tail
fi
state: 'present'
- name: 'fortune'
weight: 95
src: 'etc/update-motd.d/fortune'
state: 'init'
# ]]]
# .. envvar:: machine__motd_scripts [[[
#
# The list of the MOTD scripts which should be present on all hosts in the
# Ansible inventory.
machine__motd_scripts: []
# ]]]
# .. envvar:: machine__motd_group_scripts [[[
#
# The list of the MOTD scripts which should be present on hosts in a specific
# Ansible inventory group.
machine__motd_group_scripts: []
# ]]]
# .. envvar:: machine__motd_host_scripts [[[
#
# The list of the MOTD scripts which should be present on specific hosts in the
# Ansible inventory.
machine__motd_host_scripts: []
# ]]]
# .. envvar:: machine__motd_combined_scripts [[[
#
# The list which combines configuration of the MOTD scripts which is passed to
# the Ansible tasks.
machine__motd_combined_scripts: '{{ machine__motd_default_scripts
+ machine__motd_scripts
+ machine__motd_group_scripts
+ machine__motd_host_scripts }}'
# ]]]
# ]]]

View file

@ -0,0 +1,25 @@
#!/bin/sh
# Copyright (C) 2018 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2018 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
# shellcheck disable=SC2034
BLACK='\033[49;30m'
BLACKB='\033[49;90m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[94;49m'
MAGENTA='\033[0;35m'
CYAN='\033[36;49m'
WHITE='\033[0;37m'
BOLD='\033[1m'
RESET='\033[0m'
if [ -d "/etc/ansible/facts.d" ] ; then
printf "${BLACKB}%70s${RESET}\\n" | tr ' ' -
# shellcheck disable=SC2059
printf " ${CYAN}This system is managed by ${BOLD}Ansible${RESET}${CYAN}, manual changes will be lost${RESET}\\n"
printf "${BLACKB}%70s${RESET}\\n" | tr ' ' -
fi

View file

@ -0,0 +1,15 @@
#!/bin/sh
# Copyright (C) 2018 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2018 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
# shellcheck disable=SC1091
. /etc/default/locale
export LANG
export PATH="/usr/local/games:/usr/games:$PATH"
if [ -x /usr/games/fortune ] ; then
/usr/games/fortune -s
fi

View file

@ -0,0 +1,32 @@
---
# Copyright (C) 2018 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2018-2022 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: 'Manage local machine information and MOTD'
company: 'DebOps'
license: 'GPL-3.0-only'
min_ansible_version: '2.4.0'
platforms:
- name: 'Ubuntu'
versions: [ 'all' ]
- name: 'Debian'
versions: [ 'all' ]
galaxy_tags:
- system
- motd
- issue
- login

View file

@ -0,0 +1,156 @@
---
# Copyright (C) 2018 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2018 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
- 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 requested packages
ansible.builtin.package:
name: '{{ q("flattened", machine__packages) }}'
state: 'present'
register: machine__register_packages
until: machine__register_packages is succeeded
when: machine__enabled | bool
- name: Generate machine-info config file
ansible.builtin.template:
src: 'etc/machine-info.j2'
dest: '/etc/machine-info'
owner: 'root'
group: 'root'
mode: '0644'
when: machine__enabled | bool
- name: Add/remove diversion of /etc/issue
debops.debops.dpkg_divert:
path: '/etc/issue'
state: '{{ "present"
if machine__etc_issue_state | d("present") != "absent"
else "absent" }}'
delete: True
when: machine__enabled | bool
- name: Configure /etc/issue file
ansible.builtin.template:
src: '{{ machine__etc_issue_template }}'
dest: '/etc/issue'
owner: 'root'
group: 'root'
mode: '0644'
when: machine__enabled | bool and machine__etc_issue_state | d('present') != 'absent'
- name: Remove static /etc/motd file if requested
ansible.builtin.file:
path: '/etc/motd'
state: 'absent'
when: machine__enabled | bool and machine__etc_motd_state == 'absent'
- name: Generate static /etc/motd file
ansible.builtin.copy:
content: "{{ machine__motd }}"
dest: '/etc/motd'
owner: 'root'
group: 'root'
mode: '0644'
when: machine__enabled | bool and machine__etc_motd_state | d('present') != 'absent' and
machine__motd | d()
- name: Ensure that required directories exist
ansible.builtin.file:
path: '{{ machine__motd_update_dir }}'
state: 'directory'
owner: 'root'
group: 'root'
mode: '0755'
when: machine__enabled | bool
- name: Create /run/motd.dynamic symlink
ansible.builtin.meta: 'flush_handlers'
- name: Add/remove diversion of packaged MOTD scripts
vars:
machine__var_divert_path: '{{ "/etc/update-motd.d/"
+ item.filename | d(("%02d" | format(item.weight | int)) | string + "-" + item.name) }}'
debops.debops.dpkg_divert:
path: '{{ machine__var_divert_path }}'
divert: '{{ machine__var_divert_path + ".disabled" }}'
state: '{{ "present"
if (machine__enabled | bool and
item.state | d("present") not in ["absent", "revert"])
else "absent" }}'
delete: True
loop: '{{ machine__motd_combined_scripts | debops.debops.parse_kv_items }}'
loop_control:
label: '{{ item.filename | d(item.name) }}'
when: item.filename | d(item.name) and item.divert | d(False) | bool
- name: Remove dynamic MOTD scripts
ansible.builtin.file:
path: '{{ machine__motd_update_dir + "/"
+ (item.filename | d(("%02d" | format(item.weight | int)) | string + "-" + item.name)) }}'
state: 'absent'
loop: '{{ q("flattened", machine__motd_combined_scripts) | debops.debops.parse_kv_items }}'
register: machine__register_motd_scripts_removed
when: (machine__enabled | bool and
item.filename | d(item.name) and
item.state | d('present') == 'absent' and not item.divert | d(False) | bool)
- name: Install dynamic MOTD scripts
ansible.builtin.copy:
src: '{{ item.src | d(omit) }}'
content: '{{ item.content | d(omit) }}'
dest: '{{ machine__motd_update_dir + "/"
+ (item.filename | d(("%02d" | format(item.weight | int)) | string + "-" + item.name)) }}'
owner: 'root'
group: 'root'
mode: '0755'
loop: '{{ machine__motd_combined_scripts | debops.debops.parse_kv_items }}'
loop_control:
label: '{{ item.filename | d() or item.name }}'
register: machine__register_motd_scripts_created
when: (machine__enabled | bool and
item.filename | d(item.name) and
item.src | d(item.content) and
item.state | d('present') not in ['init', 'absent', 'ignore', 'divert', 'revert'])
- name: Remove unknown MOTD scripts
ansible.builtin.shell: find /etc/update-motd.d -maxdepth 1 -type f
-name '*-{{ item.item.name }}'
! -name '{{ ("%02d" | format((item.item.weight | d("0")) | int)) | string + "-" + item.item.name }}'
-exec rm -vf {} +
loop: '{{ machine__register_motd_scripts_removed.results
+ machine__register_motd_scripts_created.results }}'
loop_control:
label: '{{ item.item.name }}'
register: machine__register_remove_unknown
changed_when: machine__register_remove_unknown.changed | bool
when: (item.item.name | d() and not item.item.divert | d(False) | bool and
item.item.filename is undefined and item is changed)
- name: Make sure that Ansible local facts directory exists
ansible.builtin.file:
path: '/etc/ansible/facts.d'
state: 'directory'
owner: 'root'
group: 'root'
mode: '0755'
- name: Save machine local facts
ansible.builtin.template:
src: 'etc/ansible/facts.d/machine.fact.j2'
dest: '/etc/ansible/facts.d/machine.fact'
owner: 'root'
group: 'root'
mode: '0755'
notify: [ 'Refresh host facts' ]
tags: [ 'meta::facts' ]
- name: Update Ansible facts if they were modified
ansible.builtin.meta: 'flush_handlers'

View file

@ -0,0 +1,28 @@
#!{{ ansible_python['executable'] }}
# -*- coding: utf-8 -*-
# Copyright (C) 2018 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2018 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
# {{ ansible_managed }}
from __future__ import print_function
from json import loads, dumps
from sys import exit
import os
output = loads('''{{ {'configured': True,
'enabled': machine__enabled | bool
} | to_nice_json }}''')
machine_info = '/etc/machine-info'
if os.path.exists(machine_info) and os.path.isfile(machine_info):
with open(machine_info, "r") as f:
for line in f:
if not line.startswith('#') and '=' in line:
line = line.strip().split('=')
output.update({str(line[0]).lower(): str(line[1]).strip('"')})
print(dumps(output, sort_keys=True, indent=4))

View file

@ -0,0 +1,10 @@
{# Copyright (C) 2018 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2018 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
#}
 /\\ \n.\O
 / \\ {{ machine__organization }}
 DebOps
 \\ / \l / \U
 \\/ \s \r

View file

@ -0,0 +1,27 @@
{# Copyright (C) 2018 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2018 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
#}
# {{ ansible_managed }}
{% if machine__organization | d() %}
ORGANIZATION="{{ machine__organization }}"
{% endif %}
{% if machine__contact | d() %}
CONTACT="{{ machine__contact }}"
{% endif %}
{% if machine__pretty_hostname | d() %}
PRETTY_HOSTNAME="{{ machine__pretty_hostname }}"
{% endif %}
{% if machine__icon_name | d() %}
ICON_NAME="{{ machine__icon_name }}"
{% endif %}
{% if machine__chassis | d() %}
CHASSIS="{{ machine__chassis }}"
{% endif %}
{% if machine__deployment | d() %}
DEPLOYMENT="{{ machine__deployment }}"
{% endif %}
{% if machine__location | d() %}
LOCATION="{{ machine__location }}"
{% endif %}