From 2e39c89192206e955f359dc40721c7e498f2b150 Mon Sep 17 00:00:00 2001 From: Saravanan KR Date: Tue, 12 Mar 2019 15:44:18 +0530 Subject: [PATCH] Create individual logs for each ansible run for better debugging Currently, ansible.log file bloats with multiple run's in case of redeployment, with which analysing logs is bit difficult. Rotate the logs files before starting the deployment so that history is kept and it allows for better debugging. Change-Id: I0741956a44d35f61391e4cba94aa27974c6d5b95 --- tripleo_common/actions/ansible.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tripleo_common/actions/ansible.py b/tripleo_common/actions/ansible.py index 1e6e7a886..59e17ae61 100644 --- a/tripleo_common/actions/ansible.py +++ b/tripleo_common/actions/ansible.py @@ -12,6 +12,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from datetime import datetime import json import logging import os @@ -47,8 +48,14 @@ def write_default_ansible_cfg(work_dir, config.read(ansible_config_path) config.set('defaults', 'retry_files_enabled', 'False') - config.set('defaults', 'log_path', - os.path.join(work_dir, 'ansible.log')) + + log_path = os.path.join(work_dir, 'ansible.log') + config.set('defaults', 'log_path', log_path) + if os.path.exists(log_path): + new_path = (log_path + '-' + + datetime.now().strftime("%Y-%m-%dT%H:%M:%S")) + os.rename(log_path, new_path) + config.set('defaults', 'forks', '25') config.set('defaults', 'timeout', '30') config.set('defaults', 'gather_timeout', '30')