mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Allow passing negative numbers to specify partition boundary relative to disk end
Fixes: https://github.com/ansible/ansible/issues/43369
This commit is contained in:
parent
c2e37d202a
commit
41a51d88f9
2 changed files with 16 additions and 5 deletions
2
changelogs/fragments/parted_negative_numbers.yml
Normal file
2
changelogs/fragments/parted_negative_numbers.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- "parted - accept negative numbers in ``part_start`` and ``part_end``"
|
|
@ -68,15 +68,17 @@ options:
|
||||||
part_start:
|
part_start:
|
||||||
description:
|
description:
|
||||||
- Where the partition will start as offset from the beginning of the disk,
|
- Where the partition will start as offset from the beginning of the disk,
|
||||||
that is, the "distance" from the start of the disk.
|
that is, the "distance" from the start of the disk. Negative numbers
|
||||||
|
specify distance from the end of the disk.
|
||||||
- The distance can be specified with all the units supported by parted
|
- The distance can be specified with all the units supported by parted
|
||||||
(except compat) and it is case sensitive, e.g. C(10GiB), C(15%).
|
(except compat) and it is case sensitive, e.g. C(10GiB), C(15%).
|
||||||
type: str
|
type: str
|
||||||
default: 0%
|
default: 0%
|
||||||
part_end :
|
part_end:
|
||||||
description:
|
description:
|
||||||
- Where the partition will end as offset from the beginning of the disk,
|
- Where the partition will end as offset from the beginning of the disk,
|
||||||
that is, the "distance" from the start of the disk.
|
that is, the "distance" from the start of the disk. Negative numbers
|
||||||
|
specify distance from the end of the disk.
|
||||||
- The distance can be specified with all the units supported by parted
|
- The distance can be specified with all the units supported by parted
|
||||||
(except compat) and it is case sensitive, e.g. C(10GiB), C(15%).
|
(except compat) and it is case sensitive, e.g. C(10GiB), C(15%).
|
||||||
type: str
|
type: str
|
||||||
|
@ -178,6 +180,13 @@ EXAMPLES = r'''
|
||||||
state: present
|
state: present
|
||||||
part_start: 1GiB
|
part_start: 1GiB
|
||||||
|
|
||||||
|
- name: Create a new primary partition with a size of 1GiB at disk's end
|
||||||
|
parted:
|
||||||
|
device: /dev/sdb
|
||||||
|
number: 3
|
||||||
|
state: present
|
||||||
|
part_start: -1GiB
|
||||||
|
|
||||||
# Example on how to read info and reuse it in subsequent task
|
# Example on how to read info and reuse it in subsequent task
|
||||||
- name: Read device information (always use unit when probing)
|
- name: Read device information (always use unit when probing)
|
||||||
parted: device=/dev/sdb unit=MiB
|
parted: device=/dev/sdb unit=MiB
|
||||||
|
@ -206,9 +215,9 @@ parted_units = units_si + units_iec + ['s', '%', 'cyl', 'chs', 'compact']
|
||||||
|
|
||||||
def parse_unit(size_str, unit=''):
|
def parse_unit(size_str, unit=''):
|
||||||
"""
|
"""
|
||||||
Parses a string containing a size of information
|
Parses a string containing a size or boundary information
|
||||||
"""
|
"""
|
||||||
matches = re.search(r'^([\d.]+)([\w%]+)?$', size_str)
|
matches = re.search(r'^(-?[\d.]+)([\w%]+)?$', size_str)
|
||||||
if matches is None:
|
if matches is None:
|
||||||
# "<cylinder>,<head>,<sector>" format
|
# "<cylinder>,<head>,<sector>" format
|
||||||
matches = re.search(r'^(\d+),(\d+),(\d+)$', size_str)
|
matches = re.search(r'^(\d+),(\d+),(\d+)$', size_str)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue