1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fixed issue idempotence issue on label an name. (#23411)

This commit is contained in:
Fabrizio Colonna 2017-05-25 16:12:25 +02:00 committed by René Moser
parent 7df246cebb
commit 78fff751ab

View file

@ -71,7 +71,7 @@ options:
description: Creates a new disk label. description: Creates a new disk label.
choices: [ choices: [
'aix', 'amiga', 'bsd', 'dvh', 'gpt', 'loop', 'mac', 'msdos', 'pc98', 'aix', 'amiga', 'bsd', 'dvh', 'gpt', 'loop', 'mac', 'msdos', 'pc98',
'sun', '' 'sun'
] ]
default: msdos default: msdos
part_type: part_type:
@ -81,6 +81,7 @@ options:
'gpt' partition table. Neither part-type nor name may be used with a 'gpt' partition table. Neither part-type nor name may be used with a
'sun' partition table. 'sun' partition table.
choices: ['primary', 'extended', 'logical'] choices: ['primary', 'extended', 'logical']
default: primary
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,
@ -135,14 +136,16 @@ partition_info:
"begin": 0.0, "begin": 0.0,
"end": 1.0, "end": 1.0,
"flags": ["boot", "lvm"], "flags": ["boot", "lvm"],
"fstype": null, "fstype": "",
"name": "",
"num": 1, "num": 1,
"size": 1.0 "size": 1.0
}, { }, {
"begin": 1.0, "begin": 1.0,
"end": 5.0, "end": 5.0,
"flags": [], "flags": [],
"fstype": null, "fstype": "",
"name": "",
"num": 2, "num": 2,
"size": 4.0 "size": 4.0
}] }]
@ -298,11 +301,13 @@ def parse_partition_info(parted_output, unit):
if unit != 'chs': if unit != 'chs':
size = parse_unit(part_params[3])[0] size = parse_unit(part_params[3])[0]
fstype = part_params[4] fstype = part_params[4]
name = part_params[5]
flags = part_params[6] flags = part_params[6]
else: else:
size = "" size = ""
fstype = part_params[3] fstype = part_params[3]
name = part_params[4]
flags = part_params[5] flags = part_params[5]
parts.append({ parts.append({
@ -311,6 +316,7 @@ def parse_partition_info(parted_output, unit):
'end': parse_unit(part_params[2])[0], 'end': parse_unit(part_params[2])[0],
'size': size, 'size': size,
'fstype': fstype, 'fstype': fstype,
'name': name,
'flags': [f.strip() for f in flags.split(', ') if f != ''], 'flags': [f.strip() for f in flags.split(', ') if f != ''],
'unit': unit.lower(), 'unit': unit.lower(),
}) })
@ -555,7 +561,7 @@ def main():
'label': { 'label': {
'choices': [ 'choices': [
'aix', 'amiga', 'bsd', 'dvh', 'gpt', 'loop', 'mac', 'msdos', 'aix', 'amiga', 'bsd', 'dvh', 'gpt', 'loop', 'mac', 'msdos',
'pc98', 'sun', '' 'pc98', 'sun'
], ],
'type': 'str' 'type': 'str'
}, },
@ -623,13 +629,11 @@ def main():
if state == 'present': if state == 'present':
# Default value for the label # Default value for the label
if not current_device['generic']['table'] or \ if not label:
current_device['generic']['table'] == 'unknown' and \
not label:
label = 'msdos' label = 'msdos'
# Assign label if required # Assign label if required
if label: if current_device['generic'].get('table', None) != label:
script += "mklabel %s " % label script += "mklabel %s " % label
# Create partition if required # Create partition if required
@ -660,7 +664,7 @@ def main():
partition = [p for p in current_parts if p['num'] == number][0] partition = [p for p in current_parts if p['num'] == number][0]
# Assign name to the the partition # Assign name to the the partition
if name: if name is not None and partition.get('name', None) != name:
script += "name %s %s " % (number, name) script += "name %s %s " % (number, name)
# Manage flags # Manage flags