From f7bd4e71fe092724780de37002275016a29e5f3d Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Fri, 22 Jun 2018 13:57:48 -0600 Subject: [PATCH] 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 --- tripleo_common/actions/ansible.py | 2 ++ tripleo_common/inventory.py | 2 ++ tripleo_common/tests/actions/test_ansible.py | 2 ++ tripleo_common/tests/test_inventory.py | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/tripleo_common/actions/ansible.py b/tripleo_common/actions/ansible.py index 370e5ced7..55111c2d2 100644 --- a/tripleo_common/actions/ansible.py +++ b/tripleo_common/actions/ansible.py @@ -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, } diff --git a/tripleo_common/inventory.py b/tripleo_common/inventory.py index ff1faf640..6335fccee 100644 --- a/tripleo_common/inventory.py +++ b/tripleo_common/inventory.py @@ -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': diff --git a/tripleo_common/tests/actions/test_ansible.py b/tripleo_common/tests/actions/test_ansible.py index 628520f6a..c5b0fe81e 100644 --- a/tripleo_common/tests/actions/test_ansible.py +++ b/tripleo_common/tests/actions/test_ansible.py @@ -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', diff --git a/tripleo_common/tests/test_inventory.py b/tripleo_common/tests/test_inventory.py index d16cf46fe..c673ad018 100644 --- a/tripleo_common/tests/test_inventory.py +++ b/tripleo_common/tests/test_inventory.py @@ -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',