ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
836 stars 1.53k forks source link

Resizing swap using filesystem and/or lvol modules fails #790

Closed rvdlinden closed 7 months ago

rvdlinden commented 4 years ago
SUMMARY

Unable to resize a swap filesystem on RHEL 7/8 using either the filesystem module nor the lvol module.

The filesystem module states in it's documentation that it can resize a swap partition since 2.8 When used however, the following message is shown: "msg": "module does not support resizing swap filesystem yet."

When using the lvol module, resizing swap also fails with a message like "msg": "Unable to resize lv.paging00 to 4g", "rc": 5

NOTE: This issue was already reported early this year as https://github.com/ansible/ansible/issues/67860, but got closed by the ansibot,

ISSUE TYPE
COMPONENT NAME

filesystem module: resizefs parameter lvol module: resizefs parameter

ANSIBLE VERSION
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Sep 26 2019, 13:23:47) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
CONFIGURATION

Default

OS / ENVIRONMENT
STEPS TO REPRODUCE
- hosts: "{{ host | default('all')}}"
  gather_facts: no
  become: yes
  strategy: "{{ playbook_strategy | default('linear')}}"

  tasks:

  - name: lvm lvol
    lvol:
      vg: vg.root
      lv: lv.paging00
      size: 3G
      shrink: no
      opts: default
      state: present
      resizefs: true
    ignore_errors: yes

  - name: lvm filesystem
    filesystem:
      fstype: swap
      dev: /dev/vg.root/lv.paging00
      resizefs: true"
EXPECTED RESULTS

resizing of swap: /dev/vg.root/lv.paging00

ACTUAL RESULTS
TASK [lvm lvol]
****************
fatal: [serverx]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "err": "fsadm: Filesystem \"swap\" on device \"/dev/mapper/vg.root-lv.paging00\" is not supported by this tool.\n  Filesystem check failed.\n", "msg": "Unable to resize lv.paging00 to 3g", "rc": 5}

TASK [lvm filesystem]
****************
fatal: [serverx]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "module does not support resizing swap filesystem yet."}"
ansibullbot commented 4 years ago

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 4 years ago

cc @MorrisA @abulimov @bcoca @d-little @flynn1973 @gforster @jhoekx @kairoaraujo @marvin-sinister @mator @molekuul @pilou- @ramooncamacho @wtcross click here for bot help

quidame commented 3 years ago

There is currently no way/tool to resize a swap filesystem. Once the underlying device (disk partition, Logical Volume or regular file) containing the swap fs has been expanded, the only way to make the swap fs fill the new free space is to replace it by a new one.

So, yes, there is a bug in filesystem module claiming that it supports resizing swap filesystem. But for me, this is all about the documentation, not about the implementation itself. Maybe lvolmodule should list filesystem types supported by its resizefs option too (by the way, lvol module calls lvreduce and lvextend commands with the --resizefs option, that internally calls fsadm, which supports only ext2/3/4, reiserfs and xfs types).

That said, resizing of swap fs could be:

- name: create swap filesystem (forced to ensure it fills the available space)
  community.general.filesystem:
    dev: /dev/vg.root/lv.paging00
    resizefs: true
    force: true

To not fail, this requires the swap area not be in use.

Also, original label (if any) and uuid of the filesystem are lost, that may break tools based on them (as in fstab, entries such as UUID=11a81daa-7fdf-46bd-896a-f7f37a3d477f none swap sw 0 0 will not work anymore).

That means that implementing swap resizing can't be expected from lvol module, and implementing it in filesystem module requires at least to run:

Sounds more like a feature request than a bug report :)

ansibullbot commented 3 years ago

cc @unkaputtbar112 @zigaSRC click here for bot help

ansibullbot commented 2 years ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help