From 431bd325775a1c11eba425305a3f7e505df7c89a Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Tue, 13 Sep 2016 12:08:18 +0200 Subject: Break the loop if we don't make any progress (#31) This avoids endless loops when Foreman miscounts the results --- foreman_ansible_inventory.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'foreman_ansible_inventory.py') diff --git a/foreman_ansible_inventory.py b/foreman_ansible_inventory.py index ea0fd2f..7169bd6 100755 --- a/foreman_ansible_inventory.py +++ b/foreman_ansible_inventory.py @@ -18,6 +18,8 @@ # # This is somewhat based on cobbler inventory +from __future__ import print_function + import argparse import ConfigParser import copy @@ -25,6 +27,7 @@ import os import re import requests from requests.auth import HTTPBasicAuth +import sys from time import time try: @@ -176,6 +179,11 @@ class ForemanInventory(object): if len(results) >= json['total']: break page += 1 + if len(json['results']) == 0: + print("Did not make any progress during loop. " + "expected %d got %d" % (json['total'], len(results)), + file=sys.stderr) + break return results def _get_hosts(self): -- cgit v1.2.3