Skip to content

Commit

Permalink
Generalize mkfs parameters: list them in vars
Browse files Browse the repository at this point in the history
  • Loading branch information
pcahyna committed Aug 21, 2020
1 parent a017f0f commit 2ac22b5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
14 changes: 8 additions & 6 deletions library/blivet.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
LIB_IMP_ERR = traceback.format_exc()

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common import sys_info

if BLIVET_PACKAGE:
blivet_flags.debug = True
Expand Down Expand Up @@ -454,14 +453,13 @@ def _type_check(self):
def _get_format(self):
fmt = super(BlivetDiskVolume, self)._get_format()
# pass -F to mke2fs on whole disks in RHEL7
if self._volume['fs_type'] in ('ext2', 'ext3', 'ext4') and \
sys_info.get_distribution().lower() in ('redhat', 'centos') and \
sys_info.get_distribution_version().startswith('7.'):
mkfs_options = mkfs_option_map.get(self._volume['fs_type'])
if mkfs_options:
if fmt.create_options:
fmt.create_options += " "
else:
fmt.create_options = ""
fmt.create_options += "-F"
fmt.create_options += mkfs_options

return fmt

Expand Down Expand Up @@ -1126,7 +1124,8 @@ def run_module():
packages_only=dict(type='bool', required=False, default=False),
disklabel_type=dict(type='str', required=False, default=None),
safe_mode=dict(type='bool', required=False, default=True),
use_partitions=dict(type='bool', required=False, default=True))
use_partitions=dict(type='bool', required=False, default=True),
mkfs_option_map=dict(type='dict', required=False, default={}))

# seed the result dict in the object
result = dict(
Expand Down Expand Up @@ -1162,6 +1161,9 @@ def run_module():
global safe_mode
safe_mode = module.params['safe_mode']

global mkfs_option_map
mkfs_option_map = module.params['mkfs_option_map']

b = Blivet()
b.reset()
fstab = FSTab(b)
Expand Down
1 change: 1 addition & 0 deletions tasks/main-blivet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
use_partitions: "{{ storage_use_partitions }}"
disklabel_type: "{{ storage_disklabel_type }}"
safe_mode: "{{ storage_safe_mode }}"
mkfs_option_map: "{{ __storage_blivet_mkfs_option_map|default(omit) }}"
register: blivet_output

- debug:
Expand Down
4 changes: 4 additions & 0 deletions vars/CentOS_7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ blivet_package_list:
- libblockdev-lvm
- libblockdev-mdraid
- libblockdev-swap
__storage_blivet_mkfs_option_map:
ext2: '-F'
ext3: '-F'
ext4: '-F'
4 changes: 4 additions & 0 deletions vars/RedHat_7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ blivet_package_list:
- libblockdev-lvm
- libblockdev-mdraid
- libblockdev-swap
__storage_blivet_mkfs_option_map:
ext2: '-F'
ext3: '-F'
ext4: '-F'

0 comments on commit 2ac22b5

Please sign in to comment.