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

parted module does not resize partitions #23914

Closed
kwohlfahrt opened this issue Apr 24, 2017 · 9 comments
Closed

parted module does not resize partitions #23914

kwohlfahrt opened this issue Apr 24, 2017 · 9 comments
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bot_closed bug This issue/PR relates to a bug. collection:community.general collection Related to Ansible Collections work module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community. system System category

Comments

@kwohlfahrt
Copy link
Contributor

ISSUE TYPE
  • Bug Report
COMPONENT NAME

parted module

ANSIBLE VERSION
ansible 2.4.0
OS / ENVIRONMENT

Debian Stretch

SUMMARY

Partitions are kept unchanged (and an OK result is reported), even if the size of the partition in the play is different to the actual size. This continues from discussions in #22996 and #23411

STEPS TO REPRODUCE

Run the following task:

- name: Create EFI partitions
  become: yes
  parted:
    label: gpt
    state: present
    device: /dev/vda
    part_start: 0%
    part_end: 512MiB
    number: 1
    name: EFI

Then, run the following (note the changed part_end):

- name: Create EFI partitions
  become: yes
  parted:
    label: gpt
    state: present
    device: /dev/vda
    part_start: 0%
    part_end: 1024MiB
    number: 1
    name: EFI
EXPECTED RESULTS

The result after the first play is correct:

changed: [vm] => {"changed": true, "disk": {"dev": "/dev/vda", "logical_block": 512, "model": "Virtio Block Device", "physical_block": 512, "size": 10485760.0, "table": "gpt", "unit": "kib"}, "partitions": [{"begin": 1024.0, "end": 524288.0, "flags": [], "fstype": "", "name": "EFI", "num": 1, "size": 523264.0, "unit": "kib"}], "script": "unit KiB mklabel gpt mkpart primary 0% 512MiB unit KiB name 1 EFI"}

After the second, I expect to see:

changed: [vm] => {"changed": true, "disk": {"dev": "/dev/vda", "logical_block": 512, "model": "Virtio Block Device", "physical_block": 512, "size": 10485760.0, "table": "gpt", "unit": "kib"}, "partitions": [{"begin": 1024.0, "end": 1048576.0, "flags": [], "fstype": "", "name": "EFI", "num": 1, "size": 1047552.0, "unit": "kib"}], "script": "unit KiB mkpart primary 0% 1024MiB unit KiB name 1 EFI"}
ACTUAL RESULTS

I see the following output after running the second task, and the partition is not changed.

ok: [vm] => {"changed": false, "disk": {"dev": "/dev/vda", "logical_block": 512, "model": "Virtio Block Device", "physical_block": 512, "size": 10485760.0, "table": "gpt", "unit": "kib"}, "partitions": [{"begin": 1024.0, "end": 524288.0, "flags": [], "fstype": "", "name": "EFI", "num": 1, "size": 523264.0, "unit": "kib"}], "script": ""}
@ansibot
Copy link
Contributor

ansibot commented Apr 24, 2017

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels Apr 24, 2017
@alikins alikins removed the needs_triage Needs a first human triage before being processed. label Apr 24, 2017
@fridim
Copy link
Contributor

fridim commented May 1, 2017

Thanks for reporting.
Indeed, current implementation just look at the partition number. I don't know if it's an intended fail-safe or not. Because this bring questions like: "what to do if you increase the size of the partition and it overlaps the next one ? delete and recreate both ?"
With the current code you will need to explicitly delete the partition with state: absent and then recreate it with new size.
I'll let others step in regarding this behavior.

I tried to find the answer in the tests, but there are none for this module. So i link here the PR to add tests to parted (a start at least) : #24164
(it can't be a bad idea to have tests before potentially changing this module)

@kwohlfahrt
Copy link
Contributor Author

Sure. I think a safe behaviour would be to extend the partition if the space after is free (this shouldn't do anything to the filesystem, which would have to be resized separately), and to error otherwise.

@ColOfAbRiX
Copy link
Contributor

My choice was to keep things simple, avoid any manipulation and just provide the parted functionalities as they are. In this situation it would be up to the user to decide what to do.

Maybe the behaviour that @kwohlfahrt is looking for should be implemented using LVM: I'm actually finding myself in the same scenario, a template VM with minimal disk plus an additional disk that I partition and add to a volume group.

@Lekensteyn
Copy link

Lekensteyn commented May 26, 2017

LVM is not needed for simple scenarios. In my case there is a single partition (/dev/vda1) which should grow occupy the full, expanded disk.

Looking at the current implementation, the dimensions are only taken into account when creating a partition, it won't modify an existing one. Playbook example:

---
- hosts: buildbot-workers
  become: yes
  vars:
    dev: /dev/vda
    part: 1
  tasks:
    # Check for device name in QMP/HMP with:  info block
    # Then resize the virtio disk with:       block_resize virtio0 12G
    - name: install apt packages
      apt: name={{ item }} state=present update_cache=yes cache_valid_time=3600
      with_items:
        - parted
        - e2fsprogs
    - name: grow partition until maximum
      parted:
        device: "{{dev}}"
        number: "{{part}}"
        state: present
    - name: grow filesystem until maximum block size
      filesystem:
        fstype: ext4
        dev: "{{dev}}{{part}}"
        resizefs: yes

I came up with this hack instead... Using parted 3.2-15 on Ubuntu 16.04. At least it is idempotent, it also only works when there is a single partition.

---
- hosts: buildbot-workers
  become: yes
  vars:
    dev: /dev/vda
    part: 1
    max_gap_kb: 1024
  tasks:
    # Check for device name in QMP/HMP with:  info block
    # Then resize the virtio disk with:       block_resize virtio0 12G
    - name: install apt packages
      apt: name={{ item }} state=present update_cache=yes cache_valid_time=3600
      with_items:
        - parted
        - e2fsprogs
    - name: partition info
      parted:
        device: "{{dev}}"
        number: "{{part}}"
      register: partinfo
    - set_fact:
        gap_kb: "{{partinfo.disk.size - partinfo.partitions[vars.part-1].end}}"
    - debug: 'msg="Gap after partition {{part}}: {{gap_kb}}kiB"'
    # parted does not resize: https://github.com/ansible/ansible/issues/23914
    - name: grow too small partition to maximum
      # Request resize, ack resize of partition that is in use (when requested).
      # https://bugs.launchpad.net/ubuntu/+source/parted/+bug/1270203
      # https://unix.stackexchange.com/a/365657
      command: 'parted ---pretend-input-tty {{dev}} resizepart {{part}} Yes 100%'
      when: max_gap_kb < gap_kb|int
    - name: grow filesystem until maximum block size
      filesystem:
        fstype: ext4
        dev: "{{dev}}{{part}}"
        resizefs: yes

@ansibot ansibot added the support:community This issue/PR relates to code supported by the Ansible community. label Jun 29, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@dawud
Copy link

dawud commented May 24, 2018

On RHEL, you need a different parted command:

    - name: grow too small partition to maximum
      # Request resize, ack resize of partition that is in use (when requested).
      # https://bugs.launchpad.net/ubuntu/+source/parted/+bug/1270203
      # https://unix.stackexchange.com/a/365657
      command: 'parted {{ dev }} resizepart {{ part }} 100%'
      when: max_gap_kb < gap_kb|int

@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed support:community This issue/PR relates to code supported by the Ansible community. labels Sep 21, 2018
@ansibot ansibot added needs_maintainer Ansibot is unable to identify maintainers for this PR. (Check `author` in docs or BOTMETA.yml) support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 7, 2018
@ansibot ansibot removed the needs_maintainer Ansibot is unable to identify maintainers for this PR. (Check `author` in docs or BOTMETA.yml) label Nov 10, 2018
@ansibot ansibot added the system System category label Feb 17, 2019
@hernando-garcia
Copy link

hernando-garcia commented Jul 6, 2019

Be nice to have the resize functionality in parted instead of using command. Something like:

  • name: Resize a partition
    parted:
    device: {{device}}
    number: {{partition_number}}
    resized: true
    size: 100%
    ....

Of course there would be the need (in my case) for extending the PV and FS but that's another topic altogether since there isn't an ansible module for LVM that I know of can do that atm...one step at the time I suppose till then command it is the Swiss knife.

@FleischKarussel
Copy link

Hey,
I can recommend growpart as an alternative.

@ansibot ansibot added collection Related to Ansible Collections work collection:community.general needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md labels Apr 29, 2020
@ansibot
Copy link
Contributor

ansibot commented Aug 17, 2020

Thank you very much for your interest in Ansible. Ansible has migrated much of the content into separate repositories to allow for more rapid, independent development. We are closing this issue/PR because this content has been moved to one or more collection repositories.

For further information, please see:
https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md

@ansibot ansibot closed this as completed Aug 17, 2020
@ansible ansible locked and limited conversation to collaborators Sep 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bot_closed bug This issue/PR relates to a bug. collection:community.general collection Related to Ansible Collections work module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community. system System category
Projects
None yet
Development

No branches or pull requests

9 participants