Skip to content
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

mount: add swap management #135

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

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
4 participants