65587cb279
This change bumps up the maximum supported Ansible version to 6.x (ansible-core 2.13.x) and minimum to 5.x. This synchronises Kayobe with Kolla Ansible. Shebang has been removed from modules due to [1]. os_openstacksdk_version has been added as openstack cloud modules don't support versions greater than 0.99. [1]: https://github.com/ansible/ansible/pull/76677 Depends-On: https://review.opendev.org/c/openstack/kolla-ansible/+/867546 Change-Id: Ibb00f6d079442a8509411ae8a71d74fd7bd8cccd
72 lines
1.4 KiB
Python
72 lines
1.4 KiB
Python
DOCUMENTATION = '''
|
|
---
|
|
module: blockdevice_info
|
|
short_description: Returns information about block devices
|
|
version_added: "N/A"
|
|
description:
|
|
- "Returns information about block devices"
|
|
author:
|
|
- Will Szumski
|
|
'''
|
|
|
|
EXAMPLES = '''
|
|
- name: Retrieve information about block devices
|
|
blockdevice_info:
|
|
become: true
|
|
register: result
|
|
'''
|
|
|
|
RETURN = '''
|
|
umounted:
|
|
description: A list of all umounted block devices.
|
|
type: list
|
|
returned: always
|
|
'''
|
|
|
|
import json
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
def _has_mounts(device):
|
|
if device["mountpoint"]:
|
|
return True
|
|
for child in device.get("children", []):
|
|
if _has_mounts(child):
|
|
return True
|
|
return False
|
|
|
|
def unmounted(module, lsblk):
|
|
result = []
|
|
for device in lsblk.get("blockdevices", []):
|
|
if not _has_mounts(device) and device["type"] == 'disk':
|
|
result.append(device["name"])
|
|
return result
|
|
|
|
def run_module():
|
|
# The module takes no argumnets.
|
|
module_args = dict()
|
|
|
|
result = dict(
|
|
changed=False,
|
|
unmounted=[]
|
|
)
|
|
|
|
module = AnsibleModule(
|
|
argument_spec=module_args,
|
|
supports_check_mode=True
|
|
)
|
|
|
|
_rc, stdout, _stderr = module.run_command("lsblk -J")
|
|
lsblk = json.loads(stdout)
|
|
|
|
result['unmounted'] = unmounted(module, lsblk)
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
|
def main():
|
|
run_module()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main() |