Rotate ansible.log during ceph deploy

'overcloud ceph deploy' logs are redirected to /home/stack/ansible.log.
Before python-tripleo-client runs cephadm playbook, check if the log
file ansible.log exists (from a previous run). If it does, then rename it
to append a timestamp. When cephadm is run,a new log will be created.

A new parameter 'rotate_log=False' is added to run_ansible_playbook function
which can be enabled for any other operations to perform log rotation.

Change-Id: I13bf6c6377ac049054c22d0b8a0e005366c44b7f
Resolves: rhbz#2149339
(cherry picked from commit 6e7c8c35aa)
This commit is contained in:
Manoj Katari 2022-12-15 05:41:32 -05:00 committed by Manojkatari
parent fcb9861d80
commit 732c126000
3 changed files with 15 additions and 1 deletions

View File

@ -364,6 +364,7 @@ class TestOvercloudCephSpec(fakes.FakePlaybookExecution):
verbosity=3,
tags='ceph_spec',
reproduce_command=False,
rotate_log=True,
extra_vars={
"baremetal_deployed_path": mock.ANY,
'tripleo_roles_path': mock.ANY,

View File

@ -255,7 +255,7 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
ansible_cfg=None, ansible_timeout=30,
reproduce_command=True,
timeout=None, forks=None,
ignore_unreachable=False):
ignore_unreachable=False, rotate_log=False):
"""Simple wrapper for ansible-playbook.
:param playbook: Playbook filename.
@ -348,6 +348,9 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
:param timeout: Timeout for ansible to finish playbook execution (minutes).
:type timeout: int
:param rotate_log: Enable or disable option to rotate ansible.log
:type rotate_log: Boolean
"""
def _playbook_check(play):
@ -627,6 +630,9 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
if parallel_run:
r_opts['directory_isolation_base_path'] = ansible_artifact_path
if rotate_log and os.path.exists(env['ANSIBLE_LOG_PATH']):
rotate_ansible_log(env['ANSIBLE_LOG_PATH'])
runner_config = ansible_runner.runner_config.RunnerConfig(**r_opts)
runner_config.prepare()
# NOTE(cloudnull): overload the output callback after prepare
@ -3572,3 +3578,9 @@ def get_output_dir(output_dir: str, stack_name: str = "undercloud") -> str:
return os.path.join(constants.UNDERCLOUD_OUTPUT_DIR,
'tripleo-deploy', stack_name)
return output_dir
def rotate_ansible_log(ansible_log_abspath):
now = datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
new_ansible_log_abspath = os.path.join(ansible_log_abspath+"-"+now)
os.rename(ansible_log_abspath, new_ansible_log_abspath)

View File

@ -1145,4 +1145,5 @@ class OvercloudCephSpec(command.Command):
extra_vars=extra_vars,
reproduce_command=False,
tags=tags,
rotate_log=True,
)