From d0d7bf5c21139542c0c4af96aae018277cbc5514 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Mon, 11 Jun 2018 15:01:46 -0400 Subject: [PATCH] more gracefully handle fact cache failures for hosts that contain / see: https://github.com/ansible/awx/issues/1977 related: https://github.com/ansible/ansible/issues/41413 --- awx/main/models/jobs.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index 7d195b78ac..fdb350d9bb 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -774,9 +774,13 @@ class Job(UnifiedJob, JobOptions, SurveyJobMixin, JobNotificationMixin, TaskMana if not os.path.realpath(filepath).startswith(destination): system_tracking_logger.error('facts for host {} could not be cached'.format(smart_str(host.name))) continue - with codecs.open(filepath, 'w', encoding='utf-8') as f: - os.chmod(f.name, 0o600) - json.dump(host.ansible_facts, f) + try: + with codecs.open(filepath, 'w', encoding='utf-8') as f: + os.chmod(f.name, 0o600) + json.dump(host.ansible_facts, f) + except IOError: + system_tracking_logger.error('facts for host {} could not be cached'.format(smart_str(host.name))) + continue # make note of the time we wrote the file so we can check if it changed later modification_times[filepath] = os.path.getmtime(filepath)