aboutsummaryrefslogtreecommitdiff
path: root/foreman_ansible_inventory.py
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-09-13 12:08:18 +0200
committerDaniel Lobato García <me@daniellobato.me>2016-09-13 12:08:18 +0200
commit431bd325775a1c11eba425305a3f7e505df7c89a (patch)
tree89196fa178b4dcae2e7d5ea048c1e325964d0a4d /foreman_ansible_inventory.py
parenteaaddd7cac8c7a4770e560cefb9dd9a861e0f058 (diff)
Break the loop if we don't make any progress (#31)
This avoids endless loops when Foreman miscounts the results
Diffstat (limited to 'foreman_ansible_inventory.py')
-rwxr-xr-xforeman_ansible_inventory.py8
1 files changed, 8 insertions, 0 deletions
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):