Skip to main content

Filesystem Management Overview

Filesystem Overview

The filesystem module in the IBM Power Systems AIX Collection manages local and NFS filesystems. It allows for the creation, modification, and removal of these filesystems, supporting various attributes such as mount points, volume groups, and filesystem types. Additionally, it includes options for setting permissions, auto-mounting, and accounting subsystems.

Filesystem Management

The module ensures that specified actions are performed on the filesystems, such as mounting, unmounting, or removing them. Below is an example of how to use the module to create, modify, and remove filesystems.


Examples of creating, modifying, and removing filesystems using the module.

EXAMPLES = r'''
- name: Creation of a JFS2 filesystem
ibm.power_aix.filesystem:
state: present
filesystem: /mnt3
fs_type: jfs2
attributes: size=32768,isnapshot='no'
mount_group: test
vg: rootvg
- name: Increase size of a filesystem
ibm.power_aix.filesystem:
filesystem: /mnt3
state: present
attributes: size=+5M
- name: Remove a NFS filesystem
ibm.power_aix.filesystem:
filesystem: /mnt
state: absent
rm_mount_point: true
'''

Main Functions

The filesystem module includes several main functions that handle different aspects of filesystem management. These functions include is_nfs, valid_attributes, fs_state, compare_attrs, nfs_opts, fs_opts, chfs, mkfs, rmfs, and main.

is_nfs

The is_nfs function determines if a filesystem is of NFS type or not. It runs the lsfs -l command and checks the type of the filesystem.


The is_nfs function implementation.

def is_nfs(module, filesystem):
"""
Determines if a filesystem is NFS or not
param module: Ansible module argument spec.
param filesystem: filesystem name.
return: True - filesystem is NFS type / False - filesystem is not NFS type
"""
cmd = f"lsfs -l { filesystem }"
rc, stdout = module.run_command(cmd)[:2]
if rc != 0:
return None

ln = stdout.splitlines()[1:][0]
type = ln.split()[3]

if type == "nfs":
return True
return False

valid_attributes

The valid_attributes function returns a list of valid attributes for the chfs command. It filters out attributes that are not supported.


The valid_attributes function implementation.

def valid_attributes(module):
"""
Returns list of valid attributes for chfs command
param:
module - Ansible module argument spec.
return:
valid_attrs (list) - List of valid attributes among the provided ones.
"""
attr = module.params['attributes']
if attr is None:
return True

valid_attrs = []

for attributes in attr:
if attributes.split("=")[0] in crfs_specific_attributes:
continue
valid_attrs.append(attributes)

return valid_attrs

fs_state

The fs_state function determines the current state of a filesystem. It checks if the filesystem is mounted, unmounted, or does not exist.


The fs_state function implementation.

def fs_state(module, filesystem):
"""
Determines the current state of filesystem.
param module: Ansible module argument spec.
param filesystem: filesystem name.
return: True - filesystem in mounted state / False - filesystem in unmounted state /
None - filesystem does not exist
"""

cmd = f"lsfs -l { filesystem }"
rc = module.run_command(cmd)[0]
if rc != 0:
return None

cmd = "df"
rc, stdout = module.run_command(cmd)[:2]
if rc != 0:
module.fail_json(f"Command { cmd } failed.")

if stdout:
mdirs = []

compare_attrs

The compare_attrs function compares the provided attributes with the existing attributes of a filesystem. It returns a list of attributes that need to be updated.


The compare_attrs function implementation.

def compare_attrs(module):
"""
Helper function to compare the provided and already existing attributes of a filesystem
params:
module - Ansible module argument spec.
return:
updated_attrs (list) - List of updated attributes and their values, that need to be changed
"""

fs_mount_pt = module.params['filesystem']
cmd1 = f"lsfs -c {fs_mount_pt}"
cmd2 = f"lsfs -q {fs_mount_pt}"

rc1, stdout1, stderr1 = module.run_command(cmd1)

if rc1:
result['stdout'] = stdout1
result['cmd'] = cmd1
result['stderr'] = stderr1
result['msg'] = "Could not get information about the provided filesystem."
module.fail_json(**result)

nfs_opts

The nfs_opts function builds NFS parameters for the mknfsmnt and chnfsmnt commands. It constructs options based on the module parameters.


The nfs_opts function implementation.

def nfs_opts(module):
"""
Helper function to build NFS parameters for mknfsmnt and chnfsmnt.
"""
amount = module.params["auto_mount"]
perms = module.params["permissions"]
mgroup = module.params["mount_group"]
nfs_soft_mount = module.params["nfs_soft_mount"]

opts = ""
if amount == "yes":
opts += "-A "
elif amount == "no":
opts += "-a "

if nfs_soft_mount:
opts += "-S "

if perms:
opts += f"-t { perms } "

fs_opts

The fs_opts function builds filesystem parameters for the crfs and chfs commands. It constructs options based on the module parameters.


The fs_opts function implementation.

def fs_opts(module):
"""
Helper function to build filesystem parameters for crfs and chfs.
"""
amount = module.params["auto_mount"]
perms = module.params["permissions"]
mgroup = module.params["mount_group"]
attrs = module.params["attributes"]
acct_sub_sys = module.params["account_subsystem"]

opts = ""
if amount:
opts += f"-A {amount} "

if attrs:
opts += "-a " + ' -a '.join(attrs) + " "
else:
opts += ""

if mgroup:
opts += f"-u { mgroup } "

chfs

The chfs function changes the attributes of a filesystem. It constructs and runs the appropriate command to modify the filesystem.


The chfs function implementation.

def chfs(module, filesystem):
"""
Changes the attributes of the filesystem.
param module: Ansible module argument spec.
param filesystem: Filesystem name.
return: changed - True/False(filesystem state modified or not),
msg - message
"""
amount = module.params["auto_mount"]
perms = module.params["permissions"]
mgroup = module.params["mount_group"]
acct_sub_sys = module.params["account_subsystem"]

# compare initial and the provided attributes. Exit if no change is required.
if module.params['attributes'] or amount or perms or mgroup or acct_sub_sys:
compare_attrs(module)

opts = ""
nfs = is_nfs(module, filesystem)
if nfs:
opts = nfs_opts(module)

mkfs

The mkfs function creates a filesystem. It constructs and runs the appropriate command to create either a local or NFS filesystem.


The mkfs function implementation.

def mkfs(module, filesystem):
"""
Create filesystem.
param module: Ansible module argument spec.
param filesystem: filesystem name.
return: changed - True/False(filesystem state created or not),
msg - message
"""

nfs_server = module.params['nfs_server']
device = module.params['device']
if device:
device = f"-d { device } "
else:
device = ""

if nfs_server:
# Create NFS Filesystem
opts = nfs_opts(module)

cmd = f"mknfsmnt -f { filesystem } { device } -h { nfs_server } { opts } -w bg "

rmfs

The rmfs function removes a filesystem. It constructs and runs the appropriate command to remove either a local or NFS filesystem.


The rmfs function implementation.

def rmfs(module, filesystem):
"""
Remove the filesystem
param module: Ansible module argument spec.
param filesystem: filesystem name.
return: changed - True/False(filesystem state modified or not),
msg - message
"""

rm_mount_point = module.params["rm_mount_point"]

if is_nfs(module, filesystem):
if rm_mount_point:
cmd = "rmnfsmnt -B -f "
else:
cmd = "rmnfsmnt -I -f "
else:
if rm_mount_point:
cmd = "rmfs -r "
else:
cmd = "rmfs "

main

The main function is the entry point of the module. It handles the creation, modification, and removal of filesystems based on the specified state.


The main function implementation.

def main():
global result

module = AnsibleModule(
supports_check_mode=False,
argument_spec=dict(
attributes=dict(type='list', elements='str'),
account_subsystem=dict(type='str', choices=['yes', 'no']),
auto_mount=dict(type='str', choices=['yes', 'no']),
device=dict(type='str'),
vg=dict(type='str'),
fs_type=dict(type='str', default='jfs2'),
permissions=dict(type='str', choices=['rw', 'ro']),
mount_group=dict(type='str'),
nfs_server=dict(type='str'),
nfs_soft_mount=dict(type='bool', default='False'),
state=dict(type='str', default='present', choices=['absent', 'present']),
rm_mount_point=dict(type='bool', default='false'),
filesystem=dict(type='str', required=True),
),
)

 

This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human