1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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.
This commit is contained in:
Joshua Hesketh 2016-02-29 15:21:42 +11:00
parent 7f8e8ddca9
commit c3ffe0a838
2 changed files with 11 additions and 0 deletions

View file

@ -3,6 +3,7 @@
# Copyright (c) 2012, Marco Vito Moscaritolo <marco@agavee.com> # Copyright (c) 2012, Marco Vito Moscaritolo <marco@agavee.com>
# Copyright (c) 2013, Jesse Keating <jesse.keating@rackspace.com> # Copyright (c) 2013, Jesse Keating <jesse.keating@rackspace.com>
# Copyright (c) 2015, Hewlett-Packard Development Company, L.P. # 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 # 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 # 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 # 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 # and making a group of its hostname to only doing this if the
# hostname in question has more than one server # 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 argparse
import collections import collections
import os import os
import sys import sys
import time import time
from distutils.version import StrictVersion
try: try:
import json import json
@ -128,6 +134,9 @@ def get_host_groups_from_cloud(inventory):
if hasattr(inventory, 'extra_config'): if hasattr(inventory, 'extra_config'):
use_hostnames = inventory.extra_config['use_hostnames'] use_hostnames = inventory.extra_config['use_hostnames']
list_args['expand'] = inventory.extra_config['expand_hostvars'] 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: else:
use_hostnames = False use_hostnames = False
@ -216,6 +225,7 @@ def main():
config_defaults={ config_defaults={
'use_hostnames': False, 'use_hostnames': False,
'expand_hostvars': True, 'expand_hostvars': True,
'fail_on_errors': True,
} }
)) ))

View file

@ -29,3 +29,4 @@ clouds:
ansible: ansible:
use_hostnames: True use_hostnames: True
expand_hostvars: False expand_hostvars: False
fail_on_errors: True