diff options
author | Guido Günther <agx@sigxcpu.org> | 2016-05-04 21:15:21 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2016-05-04 21:15:21 +0200 |
commit | 76e108a540a7699683249153c5f0c5e34b571342 (patch) | |
tree | 70a01b4afb360953cb5098380d0effba09fec597 | |
parent | 4cb6d186a27a86da6dd20796e1c1efc6673e0dbf (diff) | |
parent | 87fe095adc1f3c66bb061a0335ede4550725f1b6 (diff) |
Merge pull request #12 from theforeman/handle_404
Don't fail if host disappears
-rwxr-xr-x | foreman_ansible_inventory.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/foreman_ansible_inventory.py b/foreman_ansible_inventory.py index bece7c7..57cf50a 100755 --- a/foreman_ansible_inventory.py +++ b/foreman_ansible_inventory.py @@ -133,7 +133,7 @@ class ForemanInventory(object): help='Force refresh of cache by making API requests to foreman (default: False - use cache files)') self.args = parser.parse_args() - def _get_json(self, url): + def _get_json(self, url, ignore_errors=None): page = 1 results = [] while True: @@ -141,6 +141,8 @@ class ForemanInventory(object): auth=HTTPBasicAuth(self.foreman_user, self.foreman_pw), verify=self.foreman_ssl_verify, params={'page': page, 'per_page': 250}) + if ignore_errors and ret.status_code in ignore_errors: + break ret.raise_for_status() json = ret.json() if not json.has_key('results'): @@ -162,7 +164,7 @@ class ForemanInventory(object): def _get_params_by_id(self, hid): url = "%s/api/v2/hosts/%s/parameters" % (self.foreman_url, hid) - return self._get_json(url) + return self._get_json(url, [404]) def _resolve_params(self, host): """ |