From 9de3452cf39d5d8bbb75f20a5e8b444793d98000 Mon Sep 17 00:00:00 2001 From: Gael Chamoulaud Date: Tue, 2 Jul 2019 14:33:33 +0200 Subject: [PATCH] Add log_path_dir parameter This patch adds a new parameter called 'log_path_dir' (Defaults to None) to the 'run_ansible_playbook' function. The Ansible log file will be created in the location of the playbook by default, otherwise in the given directory path. Change-Id: I7222a116974458b9149771cb44f7d5f7bc51bc79 Signed-off-by: Gael Chamoulaud --- tripleoclient/tests/test_utils.py | 6 +++--- tripleoclient/utils.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tripleoclient/tests/test_utils.py b/tripleoclient/tests/test_utils.py index badfa8106..28ebbd02d 100644 --- a/tripleoclient/tests/test_utils.py +++ b/tripleoclient/tests/test_utils.py @@ -117,10 +117,10 @@ class TestRunAnsiblePlaybook(TestCase): self.assertRaises(RuntimeError, utils.run_ansible_playbook, self.mock_log, '/tmp', 'existing.yaml', 'localhost,', - '/tmp/foo.cfg' + '/home/foo', '/tmp/foo.cfg' ) - mock_exists.assert_called_once_with('/tmp/foo.cfg') - mock_isabs.assert_called_once_with('/tmp/foo.cfg') + mock_exists.assert_called_with('/tmp/foo.cfg') + mock_isabs.assert_called_with('/tmp/foo.cfg') mock_run.assert_not_called() @mock.patch('tempfile.mkstemp', return_value=('foo', '/tmp/fooBar.cfg')) diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index e3ec68a4d..6eec3edc4 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -63,6 +63,7 @@ def run_ansible_playbook(logger, workdir, playbook, inventory, + log_path_dir=None, ansible_config=None, retries=True, connection='smart', @@ -93,6 +94,10 @@ def run_ansible_playbook(logger, temporary file, or False to not manage configuration at all :type ansible_config: String + :param log_path_dir: Dir path location for ansible log file. + Defaults to "None" + :type retries: String + :param retries: do you want to get a retry_file? :type retries: Boolean @@ -146,7 +151,12 @@ def run_ansible_playbook(logger, '/usr/share/ansible/roles:' '/etc/ansible/roles:' '%s/roles' % constants.DEFAULT_VALIDATIONS_BASEDIR) - env['ANSIBLE_LOG_PATH'] = os.path.join(workdir, 'ansible.log') + + if not log_path_dir or not os.path.exists(log_path_dir): + env['ANSIBLE_LOG_PATH'] = os.path.join(workdir, 'ansible.log') + else: + env['ANSIBLE_LOG_PATH'] = os.path.join(log_path_dir, 'ansible.log') + env['ANSIBLE_HOST_KEY_CHECKING'] = 'False' cleanup = False