-
Notifications
You must be signed in to change notification settings - Fork 168
mount: add swap management #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
mount: add swap management #135
Conversation
c20f3b5
to
d233f95
Compare
10c0fd1
to
281f1d2
Compare
* Declare functions swapon() & swapoff(), is_swap() & reswap(). * Apply swapon/swapoff for states mounted, unmounted, remounted and absent. * Override default opts and boot when fstype=swap. * Do not honor 'fstab' when fstype=swap (fail instead). * Also fail when fstype=swap and 'path' is not 'none' ('-' for Solaris). * Update module documentation accordingly. + Replace all platform.system() calls by a variable. refactor integration tests * Improve readability/understanding of what is tested, and what OS is targeted. * Move 'swap' related test cases into dedicated file (swap.yml). * Add new test cases about swap enabling/disabling. * Extend tests to FreeBSD when possible.
281f1d2
to
e627afa
Compare
@quidame Thanks for the contribution. Should we create a separate module to manage swap rather than bloating the mount module? |
needs_info |
Yes, we should, as suggested here: #106 (comment) |
@quidame Would you be interested in raising a PR for the new module? Thanks, |
Yes, I would. But it is not written yet. Should I open a PR as a kind of placeholder waiting for this module to be written ? |
@quidame you seem to have made up your mind already to create a new module. But honestly, "mounting" swap in regards to managing an fstab entry is not vastly different from other types of filesystems. Yes to actually mount swap via Anyways. In it's current state Ansible core / posix apparently does not have any support to mount swap ... apart from hacking along with |
Sorry to restart this thread after so much time, but I think this seems reasonable as proposed in this PR and I'm inclined to merge it. What's the concern @Akasurde ? |
@maxamillion I would love to see something like this in either ansible.builtin or ansible.posix. Swap is kind of a pain to manage with vanilla ansible atm. Just to be transparent, I work with @Nid04 , they're pretty brill and excited about making a contribution. |
version_added: "1.0.0" | ||
options: | ||
path: | ||
description: | ||
- Path to the mount point (e.g. C(/mnt/files)). | ||
- Path to the mount point (e.g. C(/mnt/files)). Must be C(none) (or C(-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Path to the mount point (e.g. C(/mnt/files)). Must be C(none) (or C(-) | |
- Path to the mount point (For example, C(/mnt/files)). Must be C(none) (or C(-) |
# based on the mount modules from salt and puppet | ||
# Copyright: (c) 2021, quidame <quidame@poivron.org> | ||
# Written by Seth Vidal, based on the mount modules from salt and puppet | ||
# Enhanced by quidame (swapon/swapoff support) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Enhanced by quidame (swapon/swapoff support) | |
# Copyright: Contributors to the Ansible project |
@@ -108,6 +117,11 @@ | |||
- Using C(remounted) with I(opts) set may create unexpected results based on | |||
the existing options already defined on mount, so care should be taken to | |||
ensure that conflicting options are not present before hand. | |||
- Support for swap spaces activation/deactivation as been added in version | |||
1.2.0 of C(ansible.posix). | |||
- Strictly speaking, swap filesystems can't be C(mounted), C(unmounted) or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Strictly speaking, swap filesystems can't be C(mounted), C(unmounted) or | |
- Strictly speaking, swap filesystems can not be C(mounted), C(unmounted) or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To handle translation better.
if SYSTEM == 'sunos': | ||
swap_bin = module.get_bin_path('swap', required=True) | ||
cmd = [swap_bin, '-a'] | ||
elif SYSTEM.endswith('bsd'): | ||
swapctl_bin = module.get_bin_path('swapctl', required=True) | ||
cmd = [swapctl_bin, '-a'] | ||
else: | ||
# swapon is supposed to be the standard command, isn't it ? | ||
swapon_bin = module.get_bin_path('swapon', required=True) | ||
cmd = [swapon_bin] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would query swap binary path before and attach it with the SYSTEM
variable so that it is not required to query each time.
SUMMARY
Apply swapon / swapoff system commands onto
swap
filesystems, to reach statesmounted
(i.e. configured in fstab + swapon), unmounted (swapoff), remounted (swapoff + swapon) and absent (unconfigured in fstab + swapoff).Fixes #106
ISSUE TYPE
COMPONENT NAME
mount
ADDITIONAL INFORMATION
This now works:
and gives: