mirror of
				https://github.com/ansible-collections/community.general.git
				synced 2025-10-26 05:50:36 -07:00 
			
		
		
		
	
		
			Some checks are pending
		
		
	
	EOL CI / EOL Sanity (Ⓐ2.17) (push) Waiting to run
				
			EOL CI / EOL Units (Ⓐ2.17+py3.10) (push) Waiting to run
				
			EOL CI / EOL Units (Ⓐ2.17+py3.12) (push) Waiting to run
				
			EOL CI / EOL Units (Ⓐ2.17+py3.7) (push) Waiting to run
				
			EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/1/) (push) Waiting to run
				
			EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/2/) (push) Waiting to run
				
			EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/3/) (push) Waiting to run
				
			EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/1/) (push) Waiting to run
				
			EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/2/) (push) Waiting to run
				
			EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/3/) (push) Waiting to run
				
			EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/1/) (push) Waiting to run
				
			EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/2/) (push) Waiting to run
				
			EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/3/) (push) Waiting to run
				
			nox / Run extra sanity tests (push) Waiting to run
				
			* Adjust all __future__ imports: for i in $(grep -REl "__future__.*absolute_import" plugins/ tests/); do sed -e 's/from __future__ import .*/from __future__ import annotations/g' -i $i; done * Remove all UTF-8 encoding specifications for Python source files: for i in $(grep -REl '[-][*]- coding: utf-8 -[*]-' plugins/ tests/); do sed -e '/^# -\*- coding: utf-8 -\*-/d' -i $i; done * Remove __metaclass__ = type: for i in $(grep -REl '__metaclass__ = type' plugins/ tests/); do sed -e '/^__metaclass__ = type/d' -i $i; done
		
			
				
	
	
		
			134 lines
		
	
	
	
		
			2.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			134 lines
		
	
	
	
		
			2.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| #!/usr/bin/python
 | |
| 
 | |
| # Copyright (c) 2019, Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
 | |
| # 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
 | |
| 
 | |
| from __future__ import annotations
 | |
| 
 | |
| DOCUMENTATION = r"""
 | |
| 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.
 | |
| extends_documentation_fragment:
 | |
|   - community.general.attributes
 | |
| 
 | |
| attributes:
 | |
|   check_mode:
 | |
|     support: full
 | |
|   diff_mode:
 | |
|     support: none
 | |
| 
 | |
| 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 = r"""
 | |
| # 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 = r"""
 | |
| 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()
 |