| 1 |
#!/usr/bin/python |
| 2 |
# Copyright (c) 2024, Alexei Znamensky <[email protected]> |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
from __future__ import annotations |
| 7 |
|
| 8 |
DOCUMENTATION = r""" |
| 9 |
module: django_check |
| 10 |
author: |
| 11 |
- Alexei Znamensky (@russoz) |
| 12 |
short_description: Wrapper for C(django-admin check) |
| 13 |
version_added: 9.1.0 |
| 14 |
description: |
| 15 |
- This module is a wrapper for the execution of C(django-admin check). |
| 16 |
extends_documentation_fragment: |
| 17 |
- community.general._attributes |
| 18 |
- community.general._django |
| 19 |
options: |
| 20 |
databases: |
| 21 |
description: |
| 22 |
- Specify databases to run checks against. |
| 23 |
- If not specified, Django does not run database tests. |
| 24 |
- The parameter has been renamed to O(databases) in community.general 11.3.0. The old name is still available as an alias. |
| 25 |
type: list |
| 26 |
elements: str |
| 27 |
aliases: ["database"] |
| 28 |
deploy: |
| 29 |
description: |
| 30 |
- Include additional checks relevant in a deployment setting. |
| 31 |
type: bool |
| 32 |
default: false |
| 33 |
fail_level: |
| 34 |
description: |
| 35 |
- Message level that triggers failure. |
| 36 |
- Default is the Django default value. Check the documentation for the version being used. |
| 37 |
type: str |
| 38 |
choices: [CRITICAL, ERROR, WARNING, INFO, DEBUG] |
| 39 |
tags: |
| 40 |
description: |
| 41 |
- Restrict checks to specific tags. |
| 42 |
type: list |
| 43 |
elements: str |
| 44 |
apps: |
| 45 |
description: |
| 46 |
- Restrict checks to specific applications. |
| 47 |
- Default is to check all applications. |
| 48 |
type: list |
| 49 |
elements: str |
| 50 |
notes: |
| 51 |
- The outcome of the module is found in the common return values RV(ignore:stdout), RV(ignore:stderr), RV(ignore:rc). |
| 52 |
- The module fails if RV(ignore:rc) is not zero. |
| 53 |
attributes: |
| 54 |
check_mode: |
| 55 |
support: full |
| 56 |
diff_mode: |
| 57 |
support: none |
| 58 |
""" |
| 59 |
|
| 60 |
EXAMPLES = r""" |
| 61 |
- name: Check the entire project |
| 62 |
community.general.django_check: |
| 63 |
settings: myproject.settings |
| 64 |
|
| 65 |
- name: Create the project using specific databases |
| 66 |
community.general.django_check: |
| 67 |
database: |
| 68 |
- somedb |
| 69 |
- myotherdb |
| 70 |
settings: fancysite.settings |
| 71 |
pythonpath: /home/joedoe/project/fancysite |
| 72 |
venv: /home/joedoe/project/fancysite/venv |
| 73 |
""" |
| 74 |
|
| 75 |
RETURN = r""" |
| 76 |
run_info: |
| 77 |
description: Command-line execution information. |
| 78 |
type: dict |
| 79 |
returned: success and C(verbosity) >= 3 |
| 80 |
version: |
| 81 |
description: Version of Django. |
| 82 |
type: str |
| 83 |
returned: always |
| 84 |
sample: 5.1.2 |
| 85 |
version_added: 10.0.0 |
| 86 |
""" |
| 87 |
|
| 88 |
from ansible_collections.community.general.plugins.module_utils._django import DjangoModuleHelper |
| 89 |
|
| 90 |
|
| 91 |
class DjangoCheck(DjangoModuleHelper): |
| 92 |
module = dict( |
| 93 |
argument_spec=dict( |
| 94 |
databases=dict(type="list", elements="str", aliases=["database"]), |
| 95 |
deploy=dict(type="bool", default=False), |
| 96 |
fail_level=dict(type="str", choices=["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]), |
| 97 |
tags=dict(type="list", elements="str"), |
| 98 |
apps=dict(type="list", elements="str"), |
| 99 |
), |
| 100 |
supports_check_mode=True, |
| 101 |
) |
| 102 |
django_admin_cmd = "check" |
| 103 |
django_admin_arg_order = "database_stacked_dash deploy fail_level tags apps" |
| 104 |
|
| 105 |
def __init_module__(self): |
| 106 |
self.vars.set("database_stacked_dash", self.vars.databases, output=False) |
| 107 |
|
| 108 |
|
| 109 |
def main(): |
| 110 |
DjangoCheck.execute() |
| 111 |
|
| 112 |
|
| 113 |
if __name__ == "__main__": |
| 114 |
main() |