diff --git a/awx/main/management/commands/inventory_import.py b/awx/main/management/commands/inventory_import.py index c84d12c16c..797355bf3b 100644 --- a/awx/main/management/commands/inventory_import.py +++ b/awx/main/management/commands/inventory_import.py @@ -177,12 +177,6 @@ class AnsibleInventoryLoader(object): base_args = self.get_base_args() logger.info('Reading Ansible inventory source: %s', self.source) - # by default, the GCE inventory source caches results on disk for - # 5 minutes; disable this behavior - # https://github.com/ansible/tower/blob/cfb633e8a643b0190fa07b6204b339a1d336cbb3/awx/plugins/inventory/gce.py#L115 - if self.source.endswith('gce.py'): - base_args += ['--refresh-cache'] - data = self.command_to_json(base_args + ['--list']) # TODO: remove after we run custom scripts through ansible-inventory diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 8a4c6ca27b..aed99cd9ab 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -1881,6 +1881,16 @@ class RunInventoryUpdate(BaseTask): env['GCE_PROJECT'] = passwords.get('source_project', '') env['GCE_PEM_FILE_PATH'] = cloud_credential env['GCE_ZONE'] = inventory_update.source_regions if inventory_update.source_regions != 'all' else '' + + # by default, the GCE inventory source caches results on disk for + # 5 minutes; disable this behavior + cp = ConfigParser.ConfigParser() + cp.add_section('cache') + cp.set('cache', 'cache_max_age', '0') + handle, path = tempfile.mkstemp(dir=kwargs.get('private_data_dir', None)) + cp.write(os.fdopen(handle, 'w')) + os.chmod(path, stat.S_IRUSR | stat.S_IWUSR) + env['GCE_INI_PATH'] = path elif inventory_update.source == 'openstack': env['OS_CLIENT_CONFIG_FILE'] = cloud_credential elif inventory_update.source == 'satellite6': diff --git a/awx/main/tests/unit/test_tasks.py b/awx/main/tests/unit/test_tasks.py index ed6c5c9929..3a7a218133 100644 --- a/awx/main/tests/unit/test_tasks.py +++ b/awx/main/tests/unit/test_tasks.py @@ -1319,6 +1319,12 @@ class TestInventoryUpdateCredentials(TestJobExecution): assert env['GCE_ZONE'] == expected_gce_zone ssh_key_data = env['GCE_PEM_FILE_PATH'] assert open(ssh_key_data, 'rb').read() == self.EXAMPLE_PRIVATE_KEY + + config = ConfigParser.ConfigParser() + config.read(env['GCE_INI_PATH']) + assert 'cache' in config.sections() + assert config.getint('cache', 'cache_max_age') == 0 + return ['successful', 0] self.run_pexpect.side_effect = run_pexpect_side_effect