Add gathering_policy parameter to run_ansible_playbook function
This patch adds a new parameter called 'gathering_policy' (Defaults to None) to the 'run_ansible_playbook' function. This parameter will control the default policy of the Ansible fact gathering. Sets to None by default, it will use the default policy for Ansible (ie. 'implicit'). Change-Id: I0668241a1675dd4e344cc24b6ff2cbb8f93b7a45 Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
This commit is contained in:
parent
4f55cdf59a
commit
d7793ce1a5
@ -269,6 +269,55 @@ class TestRunAnsiblePlaybook(TestCase):
|
||||
'/tmp/existing.yaml'],
|
||||
env=env, retcode_only=False)
|
||||
|
||||
@mock.patch('tempfile.mkstemp', return_value=('foo', '/tmp/fooBar.cfg'))
|
||||
@mock.patch('os.path.exists', return_value=True)
|
||||
@mock.patch('tripleoclient.utils.run_command_and_log')
|
||||
def test_run_success_gathering_policy(self, mock_run, mock_exists,
|
||||
mok_mkstemp):
|
||||
mock_process = mock.Mock()
|
||||
mock_process.returncode = 0
|
||||
mock_run.return_value = mock_process
|
||||
|
||||
retcode, output = utils.run_ansible_playbook(
|
||||
self.mock_log,
|
||||
'/tmp',
|
||||
'existing.yaml',
|
||||
'localhost,',
|
||||
gathering_policy='explicit')
|
||||
self.assertEqual(retcode, 0)
|
||||
mock_exists.assert_called_once_with('/tmp/existing.yaml')
|
||||
env = os.environ.copy()
|
||||
env['ANSIBLE_LIBRARY'] = \
|
||||
('/root/.ansible/plugins/modules:'
|
||||
'/usr/share/ansible/plugins/modules:'
|
||||
'/usr/share/openstack-tripleo-validations/library')
|
||||
env['ANSIBLE_LOOKUP_PLUGINS'] = \
|
||||
('root/.ansible/plugins/lookup:'
|
||||
'/usr/share/ansible/plugins/lookup:'
|
||||
'/usr/share/openstack-tripleo-validations/lookup_plugins')
|
||||
env['ANSIBLE_CALLBACK_PLUGINS'] = \
|
||||
('~/.ansible/plugins/callback:'
|
||||
'/usr/share/ansible/plugins/callback:'
|
||||
'/usr/share/openstack-tripleo-validations/callback_plugins')
|
||||
env['ANSIBLE_ROLES_PATH'] = \
|
||||
('/root/.ansible/roles:'
|
||||
'/usr/share/ansible/roles:'
|
||||
'/etc/ansible/roles:'
|
||||
'/usr/share/openstack-tripleo-validations/roles')
|
||||
env['ANSIBLE_CONFIG'] = '/tmp/fooBar.cfg'
|
||||
env['ANSIBLE_HOST_KEY_CHECKING'] = 'False'
|
||||
env['ANSIBLE_LOG_PATH'] = '/tmp/ansible.log'
|
||||
env['TRIPLEO_PLAN_NAME'] = 'overcloud'
|
||||
env['ANSIBLE_GATHERING'] = 'explicit'
|
||||
|
||||
mock_run.assert_called_once_with(self.mock_log,
|
||||
[self.ansible_playbook_cmd,
|
||||
'-u', 'root',
|
||||
'-i', 'localhost,', '-v',
|
||||
'-c', 'smart',
|
||||
'/tmp/existing.yaml'],
|
||||
env=env, retcode_only=False)
|
||||
|
||||
@mock.patch('tempfile.mkstemp', return_value=('foo', '/tmp/fooBar.cfg'))
|
||||
@mock.patch('os.path.exists', return_value=True)
|
||||
@mock.patch('tripleoclient.utils.run_command_and_log')
|
||||
|
@ -111,7 +111,8 @@ class TestValidatorRun(utils.TestCommand):
|
||||
retries=False,
|
||||
output_callback='validation_output',
|
||||
extra_vars={},
|
||||
python_interpreter='/usr/bin/python{}'.format(sys.version_info[0])
|
||||
python_interpreter='/usr/bin/python{}'.format(sys.version_info[0]),
|
||||
gathering_policy='explicit'
|
||||
)
|
||||
|
||||
assert mock_sysexit.called
|
||||
|
@ -84,7 +84,8 @@ def run_ansible_playbook(logger,
|
||||
skip_tags=None,
|
||||
verbosity=1,
|
||||
extra_vars=None,
|
||||
plan='overcloud'):
|
||||
plan='overcloud',
|
||||
gathering_policy=None):
|
||||
"""Simple wrapper for ansible-playbook
|
||||
|
||||
:param logger: logger instance
|
||||
@ -147,6 +148,12 @@ def run_ansible_playbook(logger,
|
||||
:param extra_vars: set additional variables as a Dict
|
||||
or the absolute path of a JSON or YAML file type
|
||||
:type extra_vars: Either a Dict or the absolute path of JSON or YAML
|
||||
|
||||
:param gathering_policy: This setting controls the default policy of
|
||||
fact gathering ('smart', 'implicit', 'explicit'). Defaults to None.
|
||||
When not specified, the policy will be the default Ansible one, ie.
|
||||
'implicit'.
|
||||
:type gathering_facts: String
|
||||
"""
|
||||
env = os.environ.copy()
|
||||
|
||||
@ -177,6 +184,9 @@ def run_ansible_playbook(logger,
|
||||
|
||||
env['ANSIBLE_HOST_KEY_CHECKING'] = 'False'
|
||||
|
||||
if gathering_policy in ['smart', 'explicit', 'implicit']:
|
||||
env['ANSIBLE_GATHERING'] = gathering_policy
|
||||
|
||||
if extra_vars is None:
|
||||
extra_vars = {}
|
||||
|
||||
|
@ -356,7 +356,8 @@ class TripleOValidatorRun(command.Command):
|
||||
retries=False,
|
||||
output_callback='validation_output',
|
||||
extra_vars=extra_vars_input,
|
||||
python_interpreter=python_interpreter)
|
||||
python_interpreter=python_interpreter,
|
||||
gathering_policy='explicit')
|
||||
print('[SUCCESS] - {}\n{}'.format(playbook,
|
||||
oooutils.indent(output)))
|
||||
except Exception as e:
|
||||
|
Loading…
Reference in New Issue
Block a user