Revert "Pass connection info via ansible config file"

This reverts commit dde623f6e5.

Change-Id: I4e5fdcf085d068dc9b444f4eb20a015c63203bd5
Closes-Bug: #1760935
This commit is contained in:
Alex Schultz 2018-04-03 17:24:35 +00:00
parent 30dded9bcd
commit 6090d32b51
2 changed files with 23 additions and 29 deletions

View File

@ -30,8 +30,6 @@ from tripleo_common.inventory import TripleoInventory
def write_default_ansible_cfg(work_dir,
remote_user,
ssh_private_key,
base_ansible_cfg='/etc/ansible/ansible.cfg'):
ansible_config_path = os.path.join(work_dir, 'ansible.cfg')
shutil.copy(base_ansible_cfg, ansible_config_path)
@ -47,13 +45,6 @@ def write_default_ansible_cfg(work_dir,
config.set('ssh_connection', 'ssh_args',
'-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no')
# Set connection info in config file so that subsequent/nested ansible
# calls can re-use it
if remote_user:
config.set('defaults', 'remote_user', remote_user)
if ssh_private_key:
config.set('defaults', 'private_key_file', ssh_private_key)
with open(ansible_config_path, 'w') as configfile:
config.write(configfile)
@ -171,6 +162,9 @@ class AnsibleAction(actions.Action):
if self.limit_hosts:
command.extend(['--limit', self.limit_hosts])
if self.remote_user:
command.extend(['--user', self.remote_user])
if self.become:
command.extend(['--become'])
@ -195,6 +189,9 @@ class AnsibleAction(actions.Action):
if self.inventory:
command.extend(['--inventory-file', self.inventory])
if self.ssh_private_key:
command.extend(['--private-key', self.ssh_private_key])
if self.extra_env_variables:
if not isinstance(self.extra_env_variables, dict):
msg = "extra_env_variables must be a dict"
@ -204,10 +201,7 @@ class AnsibleAction(actions.Action):
command.extend(['--gather-facts', self.gather_facts])
try:
ansible_config_path = write_default_ansible_cfg(
self.work_dir,
self.remote_user,
self.ssh_private_key)
ansible_config_path = write_default_ansible_cfg(self.work_dir)
env_variables = {
'HOME': self.work_dir,
'ANSIBLE_CONFIG': ansible_config_path
@ -400,6 +394,9 @@ class AnsiblePlaybookAction(base.TripleOAction):
if self.module_path:
command.extend(['--module-path', self.module_path])
if self.remote_user:
command.extend(['--user', self.remote_user])
if self.become:
command.extend(['--become'])
@ -427,6 +424,9 @@ class AnsiblePlaybookAction(base.TripleOAction):
if self.inventory:
command.extend(['--inventory-file', self.inventory])
if self.ssh_private_key:
command.extend(['--private-key', self.ssh_private_key])
if self.tags:
command.extend(['--tags', self.tags])
@ -442,10 +442,7 @@ class AnsiblePlaybookAction(base.TripleOAction):
command.extend(['--gather-facts', self.gather_facts])
try:
ansible_config_path = write_default_ansible_cfg(
self.work_dir,
self.remote_user,
self.ssh_private_key)
ansible_config_path = write_default_ansible_cfg(self.work_dir)
env_variables = {
'HOME': self.work_dir,
'ANSIBLE_CONFIG': ansible_config_path

View File

@ -58,13 +58,12 @@ class AnsibleActionTest(base.TestCase):
'ANSIBLE_CONFIG': ansible_config_path
}
mock_write_cfg.assert_called_once_with(action.work_dir,
self.remote_user, None)
mock_execute.assert_called_once_with(
'ansible', self.hosts, '-vvvvv', '--module-name', self.module,
'--become', '--become-user', self.become_user, env_variables=env,
cwd=action.work_dir, log_errors=processutils.LogErrors.ALL
'ansible', self.hosts, '-vvvvv', '--module-name',
self.module, '--user', self.remote_user, '--become',
'--become-user', self.become_user,
env_variables=env, cwd=action.work_dir,
log_errors=processutils.LogErrors.ALL
)
@ -99,9 +98,6 @@ class AnsiblePlaybookActionTest(base.TestCase):
action.run(self.ctx)
mock_write_cfg.assert_called_once_with(action.work_dir,
self.remote_user, None)
pb = os.path.join(action.work_dir, 'playbook.yaml')
env = {
'HOME': action.work_dir,
@ -109,8 +105,9 @@ class AnsiblePlaybookActionTest(base.TestCase):
}
mock_execute.assert_called_once_with(
'ansible-playbook', '-v', pb, '--become', '--become-user',
self.become_user, '--extra-vars', json.dumps(self.extra_vars),
'ansible-playbook', '-v', pb, '--user',
self.remote_user, '--become', '--become-user', self.become_user,
'--extra-vars', json.dumps(self.extra_vars),
env_variables=env, cwd=action.work_dir,
log_errors=processutils.LogErrors.ALL)
@ -183,7 +180,7 @@ class CopyConfigFileTest(base.TestCase):
ansible_cfg_file.flush()
resulting_ansible_config = ansible.write_default_ansible_cfg(
work_dir, None, None, base_ansible_cfg=ansible_cfg_path)
work_dir, base_ansible_cfg=ansible_cfg_path)
self.assertEqual(resulting_ansible_config,
os.path.join(work_dir, 'ansible.cfg'))