1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/plugins/modules/system/lbu.py
Alexei Znamensky 1202d034b3
Enabling validation-modules for system modules (#1212)
* fixed validation-modules for aix_devices.py

* fixed validation-modules for aix_filesystem.py

* fixed validation-modules for aix_inittab.py

* fixed validation-modules for aix_lvg.py

* fixed validation-modules for aix_lvol.py

* fixed validation-modules for awall.py

* fixed validation-modules for dconf.py

* fixed validation-modules for gconftool2.py

* fixed validation-modules for interfaces_file.py

* fixed validation-modules for java_keystore.py

* fixed validation-modules for kernel_blacklist.py

* fixed validation-modules for plugins/modules/system/lbu.py

* fixed validation-modules for plugins/modules/system/locale_gen.py

* fixed validation-modules for plugins/modules/system/lvg.py

* fixed validation-modules for plugins/modules/system/lvol.py

* fixed validation-modules for plugins/modules/system/mksysb.py

* fixed validation-modules for plugins/modules/system/modprobe.py

* fixed validation-modules for plugins/modules/system/nosh.py

* fixed validation-modules for plugins/modules/system/open_iscsi.py

* fixed validation-modules for plugins/modules/system/openwrt_init.py

* fixed validation-modules for plugins/modules/system/osx_defaults.py

* fixed validation-modules for plugins/modules/system/pamd.py

* fixed validation-modules for plugins/modules/system/pam_limits.py

* fixed validation-modules for plugins/modules/system/parted.py

* fixed validation-modules for plugins/modules/system/puppet.py

* fixed validation-modules for plugins/modules/system/python_requirements_info.py

* fixed validation-modules for plugins/modules/system/runit.py

the parameter "dist" is not used anywhere in the module

* fixed validation-modules for plugins/modules/system/sefcontext.py

* fixed validation-modules for plugins/modules/system/selogin.py

* fixed validation-modules for plugins/modules/system/seport.py

* fixed validation-modules for plugins/modules/system/solaris_zone.py

* fixed validation-modules for plugins/modules/system/syspatch.py

* fixed validation-modules for plugins/modules/system/vdo.py

* fixed validation-modules for plugins/modules/system/xfconf.py

* removed ignore almost all validate-modules lines in system

* removed unnecessary validations, per shippable test

* kernel_blacklist: keeping blacklist_file as str instead of path

* mksysb: keeping storage_path as str instead of path

* pam_limits: keeping dest as str instead of path

* rollback on adding doc for puppet.py legacy param

* rolledback param seuser required in selogin module

* rolledback changes in runit

* rolledback changes in osx_defaults

* rolledback changes in aix_defaults
2020-11-04 09:02:50 +01:00

127 lines
2.7 KiB
Python

#!/usr/bin/python
# Copyright: (c) 2019, Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = '''
---
module: lbu
short_description: Local Backup Utility for Alpine Linux
version_added: '0.2.0'
description:
- Manage Local Backup Utility of Alpine Linux in run-from-RAM mode
options:
commit:
description:
- Control whether to commit changed files.
type: bool
exclude:
description:
- List of paths to exclude.
type: list
elements: str
include:
description:
- List of paths to include.
type: list
elements: str
author:
- Kaarle Ritvanen (@kunkku)
'''
EXAMPLES = '''
# Commit changed files (if any)
- name: Commit
community.general.lbu:
commit: true
# Exclude path and commit
- name: Exclude directory
community.general.lbu:
commit: true
exclude:
- /etc/opt
# Include paths without committing
- name: Include file and directory
community.general.lbu:
include:
- /root/.ssh/authorized_keys
- /var/lib/misc
'''
RETURN = '''
msg:
description: Error message
type: str
returned: on failure
'''
from ansible.module_utils.basic import AnsibleModule
import os.path
def run_module():
module = AnsibleModule(
argument_spec={
'commit': {'type': 'bool'},
'exclude': {'type': 'list', 'elements': 'str'},
'include': {'type': 'list', 'elements': 'str'}
},
supports_check_mode=True
)
changed = False
def run_lbu(*args):
code, stdout, stderr = module.run_command(
[module.get_bin_path('lbu', required=True)] + list(args)
)
if code:
module.fail_json(changed=changed, msg=stderr)
return stdout
update = False
commit = False
for param in ('include', 'exclude'):
if module.params[param]:
paths = run_lbu(param, '-l').split('\n')
for path in module.params[param]:
if os.path.normpath('/' + path)[1:] not in paths:
update = True
if module.params['commit']:
commit = update or run_lbu('status') > ''
if module.check_mode:
module.exit_json(changed=update or commit)
if update:
for param in ('include', 'exclude'):
if module.params[param]:
run_lbu(param, *module.params[param])
changed = True
if commit:
run_lbu('commit')
changed = True
module.exit_json(changed=changed)
def main():
run_module()
if __name__ == '__main__':
main()