ansible-collections / community.general

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

Parted won't resize in use partition #8481

Open Overmorrow1501 opened 3 weeks ago

Overmorrow1501 commented 3 weeks ago

Summary

When I try to extend a partition in use while using community.general.parted I get errors stating the partition is in use and doesn't let me proceed ending the playbook with errors

Issue Type

Bug Report

Component Name

community.general.parted

Ansible Version

$ ansible --version
ansible [core 2.17.0]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/moro/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/moro/library/molecule_ansible/lib/python3.11/site-packages/ansible
  ansible collection location = /home/moro/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/moro/library/molecule_ansible/bin/ansible
  python version = 3.11.9 (main, Apr 18 2024, 16:44:43) [GCC] (/home/moro/library/molecule_ansible/bin/python)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 9.0.1  

Configuration

$ ansible-config dump --only-changed

CONFIG_FILE() = /etc/ansible/ansible.cfg
PAGER(env: PAGER) = less

OS / Environment

Ubuntu 24.04 LTS KERNEL = 6.8.0-35-generic parted -3.6-4build1

Steps to Reproduce


vars:

  vm_internal_ls_dict: [
              {
                  "device": "/dev/sda",
                  "fs_type": "xfs",
                  "label": "gpt",
                  "lvm": "no",
                  "mount_point": "/",
                  "part": 2,
                  "part_end": "100%",
                  "resize": true,
                  "resizefs": true
              }
          ]

tasks:
  - name: Check if parted is >= 3.4.64 # https://github.com/ansible-collections/community.general/pull/7304
    ansible.builtin.set_fact:
      parted_is_newest: "{{ ansible_facts['packages']['parted'][0]['version']  is version('3.4.64', '>=') }}"

  - name: Create disk partition
    community.general.parted:
      device: "{{ item.device }}"
      number: "{{ item.part }}"
      flags: "{{ item.flags | default(omit) }}"
      label: "{{ item.label | default('msdos') }}"
      state: "present"
      part_start: "{{ item.part_start | default(omit) }}"
      part_end: "{{ item.part_end | default(omit) }}"
      resize: "{{ (item.resize | default(omit)) if parted_is_newest | bool else omit }}"
    loop: "{{ vm_internal_ls_dict }}"
    loop_control:
      label: "{{ item.device }} partition {{ item.part }}"

Expected Results

I'm trying to online resize /dev/sda2 partition, but i get this warning Warning: Partition /dev/sda2 is being used. Are you sure you want to continue? which ends in failure.

This seems to happen only on non LVM disk

Actual Results

This is what happens when there's new space to allocate

failed: [ubuntu-plain] (item=/dev/sda partition 2) => {
    "ansible_loop_var": "item",
    "changed": false,
    "err": "Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 8388608 blocks) or continue with the current setting? \nWarning: Partition /dev/sda2 is being used. Are you sure you want to continue?\n",
    "invocation": {
        "module_args": {
            "align": "optimal",
            "device": "/dev/sda",
            "flags": null,
            "fs_type": null,
            "label": "gpt",
            "name": null,
            "number": 2,
            "part_end": "100%",
            "part_start": "0%",
            "part_type": "primary",
            "resize": true,
            "state": "present",
            "unit": "KiB"
        }
    },
    "item": {
        "device": "/dev/sda",
        "fs_type": "xfs",
        "label": "gpt",
        "lvm": "no",
        "mount_point": "/",
        "part": 2,
        "part_end": "100%",
        "resize": true,
        "resizefs": true
    },
    "msg": "Error while running parted script: /usr/sbin/parted -s -f -m -a optimal /dev/sda -- resizepart 2 100%",
    "out": "Fixing, due to --fix\n",
    "rc": 1
}

This is what happens when you try the idempotence of the playbook after manual expansion of the disk


failed: [ubuntu-plain] (item=/dev/sda partition 2) => {
    "ansible_loop_var": "item",
    "changed": false,
    "err": "Warning: Partition /dev/sda2 is being used. Are you sure you want to continue?\n",
    "invocation": {
        "module_args": {
            "align": "optimal",
            "device": "/dev/sda",
            "flags": null,
            "fs_type": null,
            "label": "gpt",
            "name": null,
            "number": 2,
            "part_end": "100%",
            "part_start": "0%",
            "part_type": "primary",
            "resize": true,
            "state": "present",
            "unit": "KiB"
        }
    },
    "item": {
        "device": "/dev/sda",
        "fs_type": "xfs",
        "label": "gpt",
        "lvm": "no",
        "mount_point": "/",
        "part": 2,
        "part_end": "100%",
        "resize": true,
        "resizefs": true
    },
    "msg": "Error while running parted script: /usr/sbin/parted -s -f -m -a optimal /dev/sda -- resizepart 2 100%",
    "out": "",
    "rc": 1
}

Code of Conduct

ansibullbot commented 3 weeks 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

ansibullbot commented 3 weeks ago

cc @ColOfAbRiX @jake2184 @rosowiecki click here for bot help