8000 mount: add swap management by quidame · Pull Request #135 · ansible-collections/ansible.posix · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

quidame
Copy link
Contributor
@quidame quidame commented Feb 13, 2021
SUMMARY

Apply swapon / swapoff system commands onto swap filesystems, to reach states mounted (i.e. configured in fstab + swapon), unmounted (swapoff), remounted (swapoff + swapon) and absent (unconfigured in fstab + swapoff).

Fixes #106

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

mount

ADDITIONAL INFORMATION

This now works:

- name: enable swap LV
  ansible.posix.mount:
    path: none
    fstype: swap
    src: /dev/mapper/vg0-swap
    opts: pri=10
    state: mounted 

and gives:

root@machine:~# swapon
NAME      TYPE      SIZE USED PRIO
/dev/dm-4 partition 3,8G 350M   10

@quidame quidame changed the title filesystem: add swap management mount: add swap management Feb 13, 2021
@quidame quidame force-pushed the feature/106-add-support-for-swap-management branch 11 times, most recently from c20f3b5 to d233f95 Compare February 15, 2021 11:33
@quidame quidame marked this pull request as draft February 20, 2021 12:37
@quidame quidame force-pushed the feature/106-add-support-for-swap-management branch from 10c0fd1 to 281f1d2 Compare March 27, 2021 23:50
quidame added 2 commits March 28, 2021 01:21
* 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.
@quidame quidame force-pushed the feature/106-add-support-for-swap-management branch from 281f1d2 to e627afa Compare March 28, 2021 00:38
@Akasurde
Copy link
Member

@quidame Thanks for the contribution. Should we create a separate module to manage swap rather than bloating the mount module?

@Akasurde
Copy link
Member

needs_info

@quidame
Copy link
Contributor Author
quidame commented May 31, 2021

@quidame Thanks for the contribution. Should we create a separate module to manage swap rather than bloating the mount module?

Yes, we should, as suggested here: #106 (comment)

@Akasurde
Copy link
Member
Akasurde commented Jun 1, 2021

@quidame Would you be interested in raising a PR for the new module? Thanks,

@quidame
Copy link
Contributor Author
quidame commented Jun 1, 2021

@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 ?

@frittentheke
Copy link
frittentheke commented Sep 12, 2023

@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 swapon requires using another command, but is that really bloating up the module?

Anyways. In it's current state Ansible core / posix apparently does not have any support to mount swap ... apart from hacking along with lineinfile and shell to create the fstab entry or mount the fs. Would you not reconsider picking up on this PR to get support for handling swap into Ansible? It's such a basic config task on an OS, it's a little sad to not being able to use native functionality of a config management tool to do it.

@maxamillion
Copy link
Collaborator

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 ?

@XakV
Copy link
XakV commented Mar 25, 2025

@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.
ansible/ansible#84881
The PR was closed b/c ansible core isn't accepting contributions for Ansible 2.10, but it doesn't say if it should be submitted for 2.11 or if it would be better in the posix collection?

Just to be transparent, I work with @Nid04 , they're pretty brill and excited about making a contribution.

@Akasurde
Copy link
Member

@XakV @Nid04 Thanks for the comment. Could you please code review this PR so we can move things forward with the PR?

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(-)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Strictly speaking, swap filesystems can't be C(mounted), C(unmounted) or
- Strictly speaking, swap filesystems can not be C(mounted), C(unmounted) or

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To handle translation better.

Comment on lines +721 to +730
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]
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for swap management
5 participants
0