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 <gchamoul@redhat.com>
This commit is contained in:
parent
8187347eb2
commit
9de3452cf3
|
@ -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'))
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue