2020-03-09 10:11:07 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2022-08-05 22:45:15 +02:00
|
|
|
# Copyright (c) 2021, Alexei Znamensky (@russoz) <russoz@gmail.com>
|
|
|
|
# Copyright (c) 2017, Kairo Araujo <kairo@kairo.eti.br>
|
2022-08-05 13:17:19 +02:00
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
author: Kairo Araujo (@kairoaraujo)
|
|
|
|
module: mksysb
|
2022-11-09 14:08:55 +01:00
|
|
|
short_description: Generates AIX mksysb rootvg backups
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- This module manages a basic AIX mksysb (image) of rootvg.
|
|
|
|
options:
|
|
|
|
backup_crypt_files:
|
|
|
|
description:
|
|
|
|
- Backup encrypted files.
|
|
|
|
type: bool
|
2022-08-24 20:46:48 +02:00
|
|
|
default: true
|
2020-03-09 10:11:07 +01:00
|
|
|
backup_dmapi_fs:
|
|
|
|
description:
|
|
|
|
- Back up DMAPI filesystem files.
|
|
|
|
type: bool
|
2022-08-24 20:46:48 +02:00
|
|
|
default: true
|
2020-03-09 10:11:07 +01:00
|
|
|
create_map_files:
|
|
|
|
description:
|
|
|
|
- Creates a new MAP files.
|
|
|
|
type: bool
|
2022-08-24 20:46:48 +02:00
|
|
|
default: false
|
2020-03-09 10:11:07 +01:00
|
|
|
exclude_files:
|
|
|
|
description:
|
|
|
|
- Excludes files using C(/etc/rootvg.exclude).
|
|
|
|
type: bool
|
2022-08-24 20:46:48 +02:00
|
|
|
default: false
|
2020-03-09 10:11:07 +01:00
|
|
|
exclude_wpar_files:
|
|
|
|
description:
|
|
|
|
- Excludes WPAR files.
|
|
|
|
type: bool
|
2022-08-24 20:46:48 +02:00
|
|
|
default: false
|
2020-03-09 10:11:07 +01:00
|
|
|
extended_attrs:
|
|
|
|
description:
|
|
|
|
- Backup extended attributes.
|
|
|
|
type: bool
|
2022-08-24 20:46:48 +02:00
|
|
|
default: true
|
2020-03-09 10:11:07 +01:00
|
|
|
name:
|
2020-11-04 09:02:50 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Backup name
|
|
|
|
required: true
|
|
|
|
new_image_data:
|
|
|
|
description:
|
|
|
|
- Creates a new file data.
|
|
|
|
type: bool
|
2022-08-24 20:46:48 +02:00
|
|
|
default: true
|
2020-03-09 10:11:07 +01:00
|
|
|
software_packing:
|
|
|
|
description:
|
|
|
|
- Exclude files from packing option listed in
|
|
|
|
C(/etc/exclude_packing.rootvg).
|
|
|
|
type: bool
|
2022-08-24 20:46:48 +02:00
|
|
|
default: false
|
2020-03-09 10:11:07 +01:00
|
|
|
storage_path:
|
2020-11-04 09:02:50 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Storage path where the mksysb will stored.
|
|
|
|
required: true
|
|
|
|
use_snapshot:
|
|
|
|
description:
|
|
|
|
- Creates backup using snapshots.
|
|
|
|
type: bool
|
2022-08-24 20:46:48 +02:00
|
|
|
default: false
|
2020-03-09 10:11:07 +01:00
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
- name: Running a backup image mksysb
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.mksysb:
|
2020-03-09 10:11:07 +01:00
|
|
|
name: myserver
|
|
|
|
storage_path: /repository/images
|
2022-08-24 20:46:48 +02:00
|
|
|
exclude_files: true
|
|
|
|
exclude_wpar_files: true
|
2020-03-09 10:11:07 +01:00
|
|
|
'''
|
|
|
|
|
|
|
|
RETURN = '''
|
|
|
|
changed:
|
|
|
|
description: Return changed for mksysb actions as true or false.
|
|
|
|
returned: always
|
|
|
|
type: bool
|
|
|
|
msg:
|
|
|
|
description: Return message regarding the action.
|
|
|
|
returned: always
|
|
|
|
type: str
|
|
|
|
'''
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2022-03-14 07:13:45 +01:00
|
|
|
from ansible_collections.community.general.plugins.module_utils.module_helper import (
|
2022-05-23 07:32:54 +02:00
|
|
|
CmdModuleHelper, ArgFormat
|
2022-03-14 07:13:45 +01:00
|
|
|
)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2022-03-14 07:13:45 +01:00
|
|
|
|
|
|
|
class MkSysB(CmdModuleHelper):
|
|
|
|
module = dict(
|
2020-03-09 10:11:07 +01:00
|
|
|
argument_spec=dict(
|
|
|
|
backup_crypt_files=dict(type='bool', default=True),
|
|
|
|
backup_dmapi_fs=dict(type='bool', default=True),
|
|
|
|
create_map_files=dict(type='bool', default=False),
|
|
|
|
exclude_files=dict(type='bool', default=False),
|
|
|
|
exclude_wpar_files=dict(type='bool', default=False),
|
|
|
|
extended_attrs=dict(type='bool', default=True),
|
2020-11-04 09:02:50 +01:00
|
|
|
name=dict(type='str', required=True),
|
2020-03-09 10:11:07 +01:00
|
|
|
new_image_data=dict(type='bool', default=True),
|
|
|
|
software_packing=dict(type='bool', default=False),
|
2020-11-04 09:02:50 +01:00
|
|
|
storage_path=dict(type='str', required=True),
|
2020-03-09 10:11:07 +01:00
|
|
|
use_snapshot=dict(type='bool', default=False)
|
|
|
|
),
|
|
|
|
supports_check_mode=True,
|
|
|
|
)
|
2022-03-14 07:13:45 +01:00
|
|
|
command = ['mksysb', '-X']
|
|
|
|
command_args_formats = dict(
|
|
|
|
create_map_files=dict(fmt="-m", style=ArgFormat.BOOLEAN),
|
|
|
|
use_snapshot=dict(fmt="-T", style=ArgFormat.BOOLEAN),
|
|
|
|
exclude_files=dict(fmt="-e", style=ArgFormat.BOOLEAN),
|
|
|
|
exclude_wpar_files=dict(fmt="-G", style=ArgFormat.BOOLEAN),
|
|
|
|
new_image_data=dict(fmt="-i", style=ArgFormat.BOOLEAN),
|
|
|
|
software_packing=dict(fmt="-p", style=ArgFormat.BOOLEAN_NOT),
|
|
|
|
extended_attrs=dict(fmt="-a", style=ArgFormat.BOOLEAN),
|
|
|
|
backup_crypt_files=dict(fmt="-Z", style=ArgFormat.BOOLEAN_NOT),
|
|
|
|
backup_dmapi_fs=dict(fmt="-A", style=ArgFormat.BOOLEAN),
|
|
|
|
combined_path=dict(fmt=lambda p, n: ["%s/%s" % (p, n)], stars=1)
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init_module__(self):
|
|
|
|
if not os.path.isdir(self.vars.storage_path):
|
2022-05-23 07:32:54 +02:00
|
|
|
self.do_raise("Storage path %s is not valid." % self.vars.storage_path)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2022-03-14 07:13:45 +01:00
|
|
|
def __run__(self):
|
|
|
|
if not self.module.check_mode:
|
|
|
|
self.run_command(params=[
|
|
|
|
'create_map_files', 'use_snapshot', 'exclude_files', 'exclude_wpar_files', 'software_packing',
|
|
|
|
'extended_attrs', 'backup_crypt_files', 'backup_dmapi_fs', 'new_image_data',
|
|
|
|
{'combined_path': [self.vars.storage_path, self.vars.name]},
|
|
|
|
])
|
|
|
|
self._changed = True
|
|
|
|
|
|
|
|
def process_command_output(self, rc, out, err):
|
|
|
|
if rc != 0:
|
2022-05-23 07:32:54 +02:00
|
|
|
self.do_raise("mksysb failed.")
|
2022-03-14 07:13:45 +01:00
|
|
|
self.vars.msg = out
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
MkSysB.execute()
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|