mirror of
https://github.com/ansible/awx.git
synced 2026-05-12 11:57:37 -02:30
Fix an openshift issue writing the inventory file
Openshift was throwing an error here, though I'm not sure why it makes a whole lot of difference to call fdopen() vs open(). This was introduced when this method was unified under the new ansible-inventory system. This fixes it for all cases. mkstemp(), while not necessary, is a useful addition to keep from leaking inventory details unnecessarily.
This commit is contained in:
@@ -678,11 +678,12 @@ class BaseTask(LogErrorsTask):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def build_inventory(self, instance, **kwargs):
|
def build_inventory(self, instance, **kwargs):
|
||||||
path = os.path.join(kwargs['private_data_dir'], 'inventory')
|
json_data = json.dumps(instance.inventory.get_script_data(hostvars=True))
|
||||||
with open(path, 'w') as f:
|
handle, path = tempfile.mkstemp(dir=kwargs.get('private_data_dir', None))
|
||||||
json_data = json.dumps(instance.inventory.get_script_data(hostvars=True))
|
f = os.fdopen(handle, 'w')
|
||||||
f.write('#! /usr/bin/env python\n# -*- coding: utf-8 -*-\nprint %r\n' % json_data)
|
f.write('#! /usr/bin/env python\n# -*- coding: utf-8 -*-\nprint %r\n' % json_data)
|
||||||
os.chmod(path, stat.S_IRUSR | stat.S_IXUSR)
|
f.close()
|
||||||
|
os.chmod(path, stat.S_IRUSR | stat.S_IXUSR | stat.S_IWUSR)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def build_args(self, instance, **kwargs):
|
def build_args(self, instance, **kwargs):
|
||||||
|
|||||||
Reference in New Issue
Block a user