Merge "Parametrize ansible transport setting"

This commit is contained in:
Zuul 2018-07-09 11:24:32 +00:00 committed by Gerrit Code Review
commit c77b4e1972
2 changed files with 11 additions and 6 deletions

View File

@ -34,7 +34,8 @@ LOG = logging.getLogger(__name__)
def write_default_ansible_cfg(work_dir, def write_default_ansible_cfg(work_dir,
remote_user, remote_user,
ssh_private_key, ssh_private_key=None,
transport=None,
base_ansible_cfg='/etc/ansible/ansible.cfg'): base_ansible_cfg='/etc/ansible/ansible.cfg'):
ansible_config_path = os.path.join(work_dir, 'ansible.cfg') ansible_config_path = os.path.join(work_dir, 'ansible.cfg')
shutil.copy(base_ansible_cfg, ansible_config_path) shutil.copy(base_ansible_cfg, ansible_config_path)
@ -64,6 +65,8 @@ def write_default_ansible_cfg(work_dir,
config.set('defaults', 'remote_user', remote_user) config.set('defaults', 'remote_user', remote_user)
if ssh_private_key: if ssh_private_key:
config.set('defaults', 'private_key_file', ssh_private_key) config.set('defaults', 'private_key_file', ssh_private_key)
if transport:
config.set('defaults', 'transport', transport)
with open(ansible_config_path, 'w') as configfile: with open(ansible_config_path, 'w') as configfile:
config.write(configfile) config.write(configfile)
@ -218,7 +221,7 @@ class AnsibleAction(actions.Action):
ansible_config_path = write_default_ansible_cfg( ansible_config_path = write_default_ansible_cfg(
self.work_dir, self.work_dir,
self.remote_user, self.remote_user,
self.ssh_private_key) ssh_private_key=self.ssh_private_key)
env_variables = { env_variables = {
'HOME': self.work_dir, 'HOME': self.work_dir,
'ANSIBLE_LOCAL_TEMP': self.work_dir, 'ANSIBLE_LOCAL_TEMP': self.work_dir,
@ -480,7 +483,7 @@ class AnsiblePlaybookAction(base.TripleOAction):
ansible_config_path = write_default_ansible_cfg( ansible_config_path = write_default_ansible_cfg(
self.work_dir, self.work_dir,
self.remote_user, self.remote_user,
self.ssh_private_key) ssh_private_key=self.ssh_private_key)
env_variables = { env_variables = {
'HOME': self.work_dir, 'HOME': self.work_dir,
'ANSIBLE_LOCAL_TEMP': self.work_dir, 'ANSIBLE_LOCAL_TEMP': self.work_dir,

View File

@ -60,7 +60,8 @@ class AnsibleActionTest(base.TestCase):
} }
mock_write_cfg.assert_called_once_with(action.work_dir, mock_write_cfg.assert_called_once_with(action.work_dir,
self.remote_user, None) self.remote_user,
ssh_private_key=None)
mock_execute.assert_called_once_with( mock_execute.assert_called_once_with(
'ansible', self.hosts, '-vvvvv', '--module-name', self.module, 'ansible', self.hosts, '-vvvvv', '--module-name', self.module,
@ -101,7 +102,8 @@ class AnsiblePlaybookActionTest(base.TestCase):
action.run(self.ctx) action.run(self.ctx)
mock_write_cfg.assert_called_once_with(action.work_dir, mock_write_cfg.assert_called_once_with(action.work_dir,
self.remote_user, None) self.remote_user,
ssh_private_key=None)
pb = os.path.join(action.work_dir, 'playbook.yaml') pb = os.path.join(action.work_dir, 'playbook.yaml')
env = { env = {
@ -191,7 +193,7 @@ class CopyConfigFileTest(base.TestCase):
ansible_cfg_file.flush() ansible_cfg_file.flush()
resulting_ansible_config = ansible.write_default_ansible_cfg( resulting_ansible_config = ansible.write_default_ansible_cfg(
work_dir, None, None, base_ansible_cfg=ansible_cfg_path) work_dir, None, None, None, base_ansible_cfg=ansible_cfg_path)
self.assertEqual(resulting_ansible_config, self.assertEqual(resulting_ansible_config,
os.path.join(work_dir, 'ansible.cfg')) os.path.join(work_dir, 'ansible.cfg'))