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

View file

@ -0,0 +1,20 @@
debops.swapfile - Configure one or multiple swap files on a Linux system
Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
Copyright (C) 2015-2016 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,54 @@
---
# .. vim: foldmarker=[[[,]]]:foldmethod=marker
# .. Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# .. Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# .. Copyright (C) 2015-2016 DebOps <https://debops.org/>
# .. SPDX-License-Identifier: GPL-3.0-only
# .. _swapfile__ref_defaults:
# debops.swapfile default variables [[[
# =====================================
# .. contents:: Sections
# :local:
#
# .. include:: ../../../../includes/global.rst
# Swap file configuration [[[
# ---------------------------
# .. envvar:: swapfile__size [[[
#
# Default size of swap files, in MB.
swapfile__size: '{{ ((ansible_memtotal_mb | int * 2)
if (ansible_memtotal_mb | int <= 2048)
else "512") }}'
# ]]]
# .. envvar:: swapfile__priority [[[
#
# Default swap file priority, from ``-1`` to ``32767``.
# Higher numbers indicate higher priority.
# Refer to :manpage:`swapon(8)` for details.
swapfile__priority: '-1'
# ]]]
# .. envvar:: swapfile__use_dd [[[
#
# By default ``debops.swapfile`` uses the ``fallocate`` command to create the swap
# files. If you use unsupported filesystems (``ext4`` is supported) you can
# enable this variable to use ``dd`` command to create the files.
swapfile__use_dd: False
# ]]]
# .. envvar:: swapfile__files [[[
#
# List of swap files. Specify either a path to a file on a filesystem, or
# a YAML dict. See :ref:`swapfile__files` for more details.
swapfile__files: [ '/swapfile' ]
# ]]]
# ]]]
# ]]]

View file

@ -0,0 +1,30 @@
---
# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2015-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:
company: 'DebOps'
author: 'Maciej Delmanowski, Robin Schneider'
description: 'Configure one or multiple swap files on a Linux system'
license: 'GPL-3.0-only'
min_ansible_version: '2.1.0'
platforms:
- name: 'Ubuntu'
versions: [ 'all' ]
- name: 'Debian'
versions: [ 'all' ]
galaxy_tags:
- system

View file

@ -0,0 +1,93 @@
---
# Copyright (C) 2015-2016 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2016 Robin Schneider <ypid@riseup.net>
# Copyright (C) 2015-2016 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
- name: Disable swap files when requested
ansible.builtin.shell: test -f {{ item.path | d(item) }} && swapoff {{ item.path | d(item) }} || true
changed_when: False
with_items: '{{ swapfile__files }}'
when: (item.state | d("present") == 'absent' and
((ansible_system_capabilities_enforced | d()) | bool and
"cap_sys_admin" in ansible_system_capabilities) or
not (ansible_system_capabilities_enforced | d(True)) | bool)
- name: Create swap files
ansible.builtin.command: |
{% if swapfile__use_dd | bool %}
dd if=/dev/zero of={{ item.path | d(item) }} bs=1M count={{ item.size | d(swapfile__size) }}
{% else %}
fallocate -l {{ ((item.size | d(swapfile__size)) | int * 1024 * 1024) }} {{ item.path | d(item) }}
{% endif %}
args:
creates: '{{ item.path | d(item) }}'
register: swapfile__register_allocation
with_items: '{{ swapfile__files }}'
when: (item.state | d("present") != 'absent')
- name: Enforce permissions
ansible.builtin.file:
path: '{{ item.path | d(item) }}'
state: 'file'
owner: 'root'
group: 'root'
mode: '0600'
with_items: '{{ swapfile__files }}'
when: (item.state | d("present") != 'absent' and not ansible_check_mode)
- name: Initialize swap files
ansible.builtin.command: 'mkswap {{ item.item.path | d(item.item) }}' # noqa no-handler
register: swapfile__register_init
changed_when: swapfile__register_init.changed | bool
with_items: '{{ swapfile__register_allocation.results | d([]) }}'
when: (item is changed and item.state | d("present") != 'absent')
- name: Enable swap files
ansible.builtin.command: 'swapon -p {{ item.item.priority | d(swapfile__priority) }} {{ item.item.path | d(item.item) }}' # noqa no-handler
with_items: '{{ swapfile__register_allocation.results | d([]) }}'
register: swapfile__register_swapon
changed_when: swapfile__register_swapon.changed | bool
when: (
(item is changed and item.state | d("present") != 'absent') and
((
(ansible_system_capabilities_enforced | d()) | bool and
"cap_sys_admin" in ansible_system_capabilities
) or not (ansible_system_capabilities_enforced | d(True)) | bool )
)
- name: Disable swap files
ansible.builtin.shell: 'test -f {{ item.path | d(item) }} && swapoff -v {{ item.path | d(item) }} || true' # noqa no-handler
with_items: '{{ swapfile__files }}'
register: swapfile__register_swapoff
changed_when: swapfile__register_swapoff.stdout == ('swapoff ' + item.path | d(item))
when: (
(item.state | d("present") == 'absent') and
((
(ansible_system_capabilities_enforced | d()) | bool and
"cap_sys_admin" in ansible_system_capabilities
) or not (ansible_system_capabilities_enforced | d(True)) | bool )
)
- name: Manage swap files in /etc/fstab
ansible.posix.mount:
src: '{{ item.path | d(item) }}'
name: 'none'
fstype: 'swap'
opts: 'sw,nofail,pri={{ item.priority | d(swapfile__priority) }}'
dump: '0'
passno: '0'
state: '{{ item.state | d("present") }}'
with_items: '{{ swapfile__files }}'
- name: Remove swap files
ansible.builtin.file:
path: '{{ item.path | d(item) }}'
state: 'absent'
with_items: '{{ swapfile__files }}'
when: (item.state | d("present") == 'absent')
- name: Remove legacy kernel parameters file
ansible.builtin.file:
path: '{{ swapfile__sysctl_file | d("/etc/sysctl.d/30-debops.swapfile.conf") }}'
state: 'absent'