summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorAlan Rominger <arominge@redhat.com>2018-07-30 19:38:05 -0400
committerJohn R Barker <john@johnrbarker.com>2018-07-30 16:38:05 -0700
commitfa45c44026ed471714d0383fd2731911d16a1271 (patch)
treea764fad55919a9a434b1f24fa53a8b7c0a7f5883 /contrib
parent84faa52b26b7e6d4485f73b8e0cd109fd374ff9a (diff)
downloadansible-fa45c44026ed471714d0383fd2731911d16a1271.tar.gz
Update openstack inventory script to keep basic functionality (#43432)
re-applies commit 6667ec447466abf1641787afccf9175369319d1f which fixed the plugin to the script so that it will work with current ansible-inventory. Also redirect stdout before dumping the ouptput, because not doing so will cause JSON parse errors in some cases.
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/inventory/openstack_inventory.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/contrib/inventory/openstack_inventory.py b/contrib/inventory/openstack_inventory.py
index 1bb5e17de9..81237a7bf2 100755
--- a/contrib/inventory/openstack_inventory.py
+++ b/contrib/inventory/openstack_inventory.py
@@ -57,6 +57,7 @@ import os
import sys
import time
from distutils.version import StrictVersion
+from io import StringIO
try:
import json
@@ -81,7 +82,8 @@ def get_groups_from_server(server_vars, namegroup=True):
groups.append(cloud)
# Create a group on region
- groups.append(region)
+ if region:
+ groups.append(region)
# And one by cloud_region
groups.append("%s_%s" % (cloud, region))
@@ -235,6 +237,8 @@ def parse_args():
def main():
args = parse_args()
try:
+ # openstacksdk library may write to stdout, so redirect this
+ sys.stdout = StringIO()
config_files = cloud_config.CONFIG_FILES + CONFIG_FILES
sdk.enable_logging(debug=args.debug)
inventory_args = dict(
@@ -255,6 +259,7 @@ def main():
inventory = sdk_inventory.OpenStackInventory(**inventory_args)
+ sys.stdout = sys.__stdout__
if args.list:
output = get_host_groups(inventory, refresh=args.refresh, cloud=args.cloud)
elif args.host: