Compare commits

..

1 Commits

Author SHA1 Message Date
uumas
c06b228be6 Add systemd role for restarting multiple services in same transaction 2026-03-11 22:15:34 +02:00
20 changed files with 12 additions and 128 deletions

View File

@@ -2,7 +2,7 @@
namespace: uumas namespace: uumas
name: general name: general
description: General roles description: General roles
version: 0.5.20 version: 0.5.17
readme: README.md readme: README.md
authors: authors:
- uumas - uumas

View File

@@ -1,14 +1,4 @@
--- ---
- name: Set sysctl udp buffer sizes for caddy
ansible.posix.sysctl:
name: "{{ item.key }}"
value: "{{ item.value }}"
state: present
reload: true
with_dict:
net.core.rmem_max: "7500000"
net.core.wmem_max: "7500000"
- name: Ensure legacy caddy apt repository not present - name: Ensure legacy caddy apt repository not present
ansible.builtin.file: ansible.builtin.file:
path: /etc/apt/sources.list.d/caddy-stable.list path: /etc/apt/sources.list.d/caddy-stable.list

View File

@@ -4,10 +4,10 @@
msg: "{{ lookup('ansible.builtin.template', 'distroerror.j2').strip() }}" msg: "{{ lookup('ansible.builtin.template', 'distroerror.j2').strip() }}"
when: > when: >
_compatcheck_distro | length != 1 or ( _compatcheck_distro | length != 1 or (
ansible_facts.distribution_major_version != 'n/a' and ansible_distribution_major_version != 'n/a' and
_compatcheck_distro[0].version_min | default(0) > ansible_facts.distribution_major_version | int _compatcheck_distro[0].version_min | default(0) > ansible_distribution_major_version | int
) or ) or
_compatcheck_distro[0].version_max is defined and _compatcheck_distro[0].version_max < ansible_facts.distribution_major_version | int or _compatcheck_distro[0].version_max is defined and _compatcheck_distro[0].version_max < ansible_distribution_major_version | int or
ansible_facts.pkg_mgr not in _compatcheck_distro[0].package_managers | default([_compatcheck_default_package_manager]) ansible_pkg_mgr not in _compatcheck_distro[0].package_managers | default([_compatcheck_default_package_manager])
loop_control: loop_control:
loop_var: checkfailed loop_var: checkfailed

View File

@@ -15,4 +15,4 @@
{{ distros.append(distro_name ~ distro_package_managers_str) }} {{ distros.append(distro_name ~ distro_package_managers_str) }}
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
This role only supports {{ distros | join(', ') }} (You are running {{ ansible_facts.distribution }} {{ ansible_facts.distribution_major_version }} ({{ ansible_facts.pkg_mgr }}) This role only supports {{ distros | join(', ') }} (You are running {{ ansible_distribution }} {{ ansible_distribution_major_version }} ({{ ansible_pkg_mgr }})

View File

@@ -1,9 +1,9 @@
--- ---
_compatcheck_distro: "{{ compatcheck_supported_distributions | selectattr('name', 'equalto', ansible_facts.distribution | lower) }}" _compatcheck_distro: "{{ compatcheck_supported_distributions | selectattr('name', 'equalto', ansible_distribution | lower) }}"
_compatcheck_default_package_managers: _compatcheck_default_package_managers:
debian: apt debian: apt
ubuntu: apt ubuntu: apt
fedora: dnf fedora: dnf
archlinux: pacman archlinux: pacman
macosx: homebrew macosx: homebrew
_compatcheck_default_package_manager: "{{ _compatcheck_default_package_managers[ansible_facts.distribution | lower] }}" _compatcheck_default_package_manager: "{{ _compatcheck_default_package_managers[ansible_distribution | lower] }}"

View File

@@ -1,5 +1,5 @@
--- ---
- name: Restart ssh service - name: Restart sshd
ansible.builtin.systemd_service: ansible.builtin.systemd_service:
name: "{{ _ssh_service_name }}" name: sshd.service
state: restarted state: restarted

View File

@@ -6,13 +6,8 @@
line: "{{ item.key }} {{ item.value }}" line: "{{ item.key }} {{ item.value }}"
state: present state: present
validate: '/usr/sbin/sshd -t -f %s' validate: '/usr/sbin/sshd -t -f %s'
notify: Restart ssh service notify: Restart sshd
with_dict: with_dict:
PermitRootLogin: "prohibit-password" PermitRootLogin: "prohibit-password"
PasswordAuthentication: "{{ 'yes' if ssh_password_auth else 'no' }}" PasswordAuthentication: "{{ 'yes' if ssh_password_auth else 'no' }}"
X11Forwarding: "no" X11Forwarding: "no"
- name: Ensure ssh service is enabled
ansible.builtin.systemd_service:
name: "{{ _ssh_service_name }}"
enabled: true

View File

@@ -1,2 +0,0 @@
---
_ssh_service_name: "{{ 'ssh.service' if ansible_facts.os_family == 'Debian' else 'sshd.service' }}"

View File

@@ -1,9 +0,0 @@
Adds systemd-related notifiable handlers
- Reload systemd daemon
- Reloads all systemd unit files
- Apply systemd unit restarts
- Restarts multiple systemd units in a single transaction
- Units to be restarted are defined in the `systemd_restart_units` variable of type list
- The variable should be set using `ansible.builtin.set_fact`, with `# noqa: var-naming[no-role-prefix]`
- The list must not be overridden, but appended (`systemd_restart_units: "{{ systemd_restart_units + ['restartme.service'] }}"`

View File

@@ -9,6 +9,6 @@
changed_when: true changed_when: true
- name: Reset systemd restart units - name: Reset systemd restart units
listen: Apply systemd unit restarts listen: Apply systemd units restart
ansible.builtin.set_fact: ansible.builtin.set_fact:
systemd_restart_units: [] systemd_restart_units: []

View File

@@ -1 +0,0 @@
Adds a systemd socket for a service

View File

@@ -1,2 +0,0 @@
---
systemd_socket_requires: []

View File

@@ -1,6 +0,0 @@
---
- name: Restart socket {{ systemd_socket_name }}
ansible.builtin.set_fact:
systemd_restart_units: "{{ systemd_restart_units + [systemd_socket_name ~ '.socket'] }}" # noqa: var-naming[no-role-prefix]
changed_when: true
notify: Apply systemd unit restarts

View File

@@ -1,16 +0,0 @@
---
argument_specs:
main:
description:
- Adds a systemd socket for a service
options:
systemd_socket_name:
description: Name of the socket. The socket will be created at /run/<systemd_socket_name>.sock
type: str
required: true
systemd_socket_requires:
description: List of units this socket depends on.
type: list
required: false
default: []
elements: str

View File

@@ -1,3 +0,0 @@
---
dependencies:
- role: systemd

View File

@@ -1,9 +0,0 @@
---
- name: Socket {{ systemd_socket_name }}
ansible.builtin.template:
src: socket.j2
dest: /etc/systemd/system/{{ systemd_socket_name }}.socket
mode: "0644"
notify:
- Reload systemd daemon
- Restart socket {{ systemd_socket_name }}

View File

@@ -1,9 +0,0 @@
# {{ ansible_managed }}
[Unit]
Description={{ systemd_socket_name }} socket
{% for item in systemd_socket_requires %}
Requires={{ item }}
{% endfor %}
[Socket]
ListenStream=/run/{{ systemd_socket_name }}.sock

View File

@@ -247,26 +247,6 @@ argument_specs:
type: dict type: dict
required: false required: false
default: {} default: {}
match_query:
description: Query to match
type: list
elements: dict
required: false
default: []
options:
key:
description: Query key to match
type: str
required: true
value:
description: Query value to match. Matches any if unset.
type: str
required: false
reverse:
description: If true, matches request without matching key/value
type: bool
required: false
default: false
type: type:
type: str type: str
@@ -675,26 +655,6 @@ argument_specs:
type: dict type: dict
required: false required: false
default: {} default: {}
match_query:
description: Query to match
type: list
elements: dict
required: false
default: []
options:
key:
description: Query key to match
type: str
required: true
value:
description: Query value to match. Matches any if unset.
type: str
required: false
reverse:
description: If true, matches request without matching key/value
type: bool
required: false
default: false
type: type:
type: str type: str

View File

@@ -10,9 +10,6 @@
{% for matcher in location.matchers %} {% for matcher in location.matchers %}
{% if matcher.name != '' %} {% if matcher.name != '' %}
@{{ matcher.name }} { @{{ matcher.name }} {
{% for query in matcher.match_query | default([]) %}
{{ 'not ' if query.reverse else '' }}query {{ query.key }}={{ query.value | default('*') }}
{% endfor %}
{% if matcher.match_methods | default([]) | length > 0 %} {% if matcher.match_methods | default([]) | length > 0 %}
method {{ matcher.match_methods | join(' ') }} method {{ matcher.match_methods | join(' ') }}
{% endif %} {% endif %}

View File

@@ -2,7 +2,6 @@
_vhost_matcher_defaults: _vhost_matcher_defaults:
match_headers: {} match_headers: {}
match_methods: [] match_methods: []
match_query: []
_vhost_matchers: >- _vhost_matchers: >-
{{ {{
vhost_matchers vhost_matchers