From c3ffe0a838cd171c8e9f20dcca96b52f9f68ed2f Mon Sep 17 00:00:00 2001 From: Joshua Hesketh Date: Mon, 29 Feb 2016 15:21:42 +1100 Subject: [PATCH] Allow fail_on_errors in openstack inventory Add support for a new option to the openstack inventory. This is so should one cloud be unavailable you can still list hosts from any other openstack clouds you have configured. This is exposed as an option under the extra config part of ansible in the openstack clouds.yaml. --- contrib/inventory/openstack.py | 10 ++++++++++ contrib/inventory/openstack.yml | 1 + 2 files changed, 11 insertions(+) diff --git a/contrib/inventory/openstack.py b/contrib/inventory/openstack.py index e8687788505..091a60fd898 100755 --- a/contrib/inventory/openstack.py +++ b/contrib/inventory/openstack.py @@ -3,6 +3,7 @@ # Copyright (c) 2012, Marco Vito Moscaritolo # Copyright (c) 2013, Jesse Keating # Copyright (c) 2015, Hewlett-Packard Development Company, L.P. +# Copyright (c) 2016, Rackspace Australia # # This module is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -39,12 +40,17 @@ # use_hostnames changes the behavior from registering every host with its UUID # and making a group of its hostname to only doing this if the # hostname in question has more than one server +# fail_on_errors causes the inventory to fail and return no hosts if one cloud +# has failed (for example, bad credentials or being offline). +# When set to False, the inventory will return hosts from +# whichever other clouds it can contact. (Default: True) import argparse import collections import os import sys import time +from distutils.version import StrictVersion try: import json @@ -128,6 +134,9 @@ def get_host_groups_from_cloud(inventory): if hasattr(inventory, 'extra_config'): use_hostnames = inventory.extra_config['use_hostnames'] list_args['expand'] = inventory.extra_config['expand_hostvars'] + if StrictVersion(shade.__version__) >= StrictVersion("1.6.0"): + list_args['fail_on_cloud_config'] = \ + inventory.extra_config['fail_on_errors'] else: use_hostnames = False @@ -216,6 +225,7 @@ def main(): config_defaults={ 'use_hostnames': False, 'expand_hostvars': True, + 'fail_on_errors': True, } )) diff --git a/contrib/inventory/openstack.yml b/contrib/inventory/openstack.yml index 1520e2937ec..84c5eefd797 100644 --- a/contrib/inventory/openstack.yml +++ b/contrib/inventory/openstack.yml @@ -29,3 +29,4 @@ clouds: ansible: use_hostnames: True expand_hostvars: False + fail_on_errors: True