feat: 增加 DEBUG_ANSIBLE 配置项支持打印 Ansible 详细日志

This commit is contained in:
Bai
2023-07-17 13:59:45 +08:00
committed by Bryan
parent f686f9f107
commit 819853eae4
4 changed files with 16 additions and 11 deletions

View File

@@ -5,6 +5,7 @@ import ansible_runner
from django.conf import settings
from .callback import DefaultCallback
from ..utils import get_ansible_log_verbosity
class CommandInBlackListException(Exception):
@@ -37,8 +38,7 @@ class AdHocRunner:
def run(self, verbosity=0, **kwargs):
self.check_module()
if verbosity is None and settings.DEBUG:
verbosity = 1
verbosity = get_ansible_log_verbosity(verbosity)
if not os.path.exists(self.project_dir):
os.mkdir(self.project_dir, 0o755)
@@ -70,8 +70,7 @@ class PlaybookRunner:
self.cb = callback
def run(self, verbosity=0, **kwargs):
if verbosity is None and settings.DEBUG:
verbosity = 1
verbosity = get_ansible_log_verbosity(verbosity)
ansible_runner.run(
private_data_dir=self.project_dir,

View File

@@ -1,16 +1,11 @@
# ~*~ coding: utf-8 ~*~
import os
import uuid
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from common.utils import get_logger, get_object_or_none, make_dirs
from orgs.utils import org_aware_func
from common.utils import get_logger, make_dirs
from jumpserver.const import PROJECT_DIR
from .models import AdHoc, CeleryTask
from .const import DEFAULT_PASSWORD_RULES
logger = get_logger(__file__)
@@ -26,3 +21,11 @@ def get_task_log_path(base_path, task_id, level=2):
make_dirs(os.path.dirname(path), exist_ok=True)
return path
def get_ansible_log_verbosity(verbosity=0):
if settings.DEBUG_ANSIBLE:
return 10
if verbosity is None and settings.DEBUG:
return 1
return verbosity