Switch ansible tmp for local connections

With ansible 2.5.4, they introduced a change that causes the temp
directory used to not honor the HOME for a user. See
https://github.com/ansible/ansible/pull/40363. Now the directory
defaults to ~/.ansible/tmp but using the HOME env has no effect. In our
case the code can be executed via mistral which doesn't have a valid
or writable home directory so it errors.  This change updates the
ansible_remote_tmp for the undercloud inventory file to
/tmp/ansible-${USER} to ensure it will work when running under mistral
but will work for any user as well.

The recommended fix for this is to configure the ansible_remote_tmp in
the inventory file for local connections to change this location.
Alternatively ANSIBLE_REMOTE_TMP can be used via an environment var but
that would change the location for all hosts which is not ideal.

Additionally HOME has been replaced with ANSIBLE_LOCAL_TEMP due to
changes upstream around the effect of home. See
https://github.com/ansible/ansible/pull/36755

Change-Id: Iaf1b8aa68af0274ba40eae329e32ab14f3689481
Closes-Bug: #1778269
This commit is contained in:
Alex Schultz
2018-06-22 13:57:48 -06:00
parent 5191b65676
commit f7bd4e71fe
4 changed files with 10 additions and 0 deletions

View File

@@ -221,6 +221,7 @@ class AnsibleAction(actions.Action):
self.ssh_private_key)
env_variables = {
'HOME': self.work_dir,
'ANSIBLE_LOCAL_TEMP': self.work_dir,
'ANSIBLE_CONFIG': ansible_config_path
}
@@ -482,6 +483,7 @@ class AnsiblePlaybookAction(base.TripleOAction):
self.ssh_private_key)
env_variables = {
'HOME': self.work_dir,
'ANSIBLE_LOCAL_TEMP': self.work_dir,
'ANSIBLE_CONFIG': ansible_config_path,
}

View File

@@ -159,6 +159,8 @@ class TripleoInventory(object):
'vars': {
'ansible_host': 'localhost',
'ansible_connection': 'local',
# see https://github.com/ansible/ansible/issues/41808
'ansible_remote_tmp': '/tmp/ansible-${USER}',
'auth_url': self.auth_url,
'cacert': self.cacert,
'os_auth_token':

View File

@@ -55,6 +55,7 @@ class AnsibleActionTest(base.TestCase):
env = {
'HOME': action.work_dir,
'ANSIBLE_LOCAL_TEMP': action.work_dir,
'ANSIBLE_CONFIG': ansible_config_path
}
@@ -105,6 +106,7 @@ class AnsiblePlaybookActionTest(base.TestCase):
pb = os.path.join(action.work_dir, 'playbook.yaml')
env = {
'HOME': action.work_dir,
'ANSIBLE_LOCAL_TEMP': action.work_dir,
'ANSIBLE_CONFIG': ansible_config_path,
'ANSIBLE_CALLBACK_WHITELIST': 'profile_tasks',
'PROFILE_TASKS_TASK_OUTPUT_LIMIT': '0',

View File

@@ -213,6 +213,7 @@ class TestInventory(base.TestCase):
'hosts': ['undercloud'],
'vars': {'ansible_connection': 'local',
'ansible_host': 'localhost',
'ansible_remote_tmp': '/tmp/ansible-${USER}',
'auth_url': 'xyz://keystone.local',
'cacert': 'acacert',
'os_auth_token': 'atoken',
@@ -281,6 +282,7 @@ class TestInventory(base.TestCase):
'hosts': ['undercloud'],
'vars': {'ansible_connection': 'local',
'ansible_host': 'localhost',
'ansible_remote_tmp': '/tmp/ansible-${USER}',
'auth_url': 'xyz://keystone.local',
'cacert': 'acacert',
'os_auth_token':
@@ -377,6 +379,8 @@ class TestInventory(base.TestCase):
'Undercloud': {'hosts': {'undercloud': {}},
'vars': {'ansible_connection': 'local',
'ansible_host': 'localhost',
'ansible_remote_tmp':
'/tmp/ansible-${USER}',
'auth_url': 'xyz://keystone.local',
'cacert': 'acacert',
'os_auth_token': 'atoken',