Repository URL to install this package:
|
Version:
4.1.94.1.dev5 ▾
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import traceback
from ansible.module_utils.basic import AnsibleModule
from workloadmgr import utils
DOCUMENTATION = '''
---
module: validate_nfs_share
short_description: Validates NFS share
options:
nfsshare:
description:
- NFS share
required: yes
requirements: []
author: Murali Balcha
'''
EXAMPLES = '''
examples:
- name: Validate nfs share
validate_nfs_share:
nfsshare: '192.168.1.114:/home/centos/nfsshare'
'''
def validate_nfs_share(nfsshare):
nfsserver = nfsshare.split(":/")[0]
sharepath = '/'+nfsshare.split(":/")[1]
nfsserver = nfsserver.split('[')[1] if '[' in nfsserver else nfsserver
nfsserver = nfsserver.split(']')[0] if ']' in nfsserver else nfsserver
rpcinfo = utils.execute("rpcinfo", "-s", nfsserver)
for i in rpcinfo[0].split("\n")[1:]:
if len(i.split()) and i.split()[3] == 'mountd':
mounts = utils.execute(
"showmount", "-e", "--no-headers", nfsserver)
if sharepath not in mounts[0]:
raise Exception("'%s' is not found in %s export list" %
(nfsshare, nfsserver))
return dict(changed=False)
raise Exception("NFS Daemon is not running on the server '%s'" %
nfsserver)
def main():
module = AnsibleModule(
argument_spec=dict(
nfsshare=dict(required=True),
),
)
nfsshare = module.params['nfsshare']
try:
d = validate_nfs_share(nfsshare)
except Exception:
module.fail_json(msg=traceback.format_exc())
else:
module.exit_json(**d)
# this is magic, see lib/ansible/module_common.py
# <<INCLUDE_ANSIBLE_MODULE_COMMON>>
if __name__ == '__main__':
main()