Skip to content

Commit

Permalink
Update openstack inventory script to keep basic functionality (ansibl…
Browse files Browse the repository at this point in the history
…e#43432)

re-applies commit 6667ec4 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.
  • Loading branch information
AlanCoding authored and gundalow committed Jul 30, 2018
1 parent 84faa52 commit fa45c44
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion contrib/inventory/openstack_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import sys
import time
from distutils.version import StrictVersion
from io import StringIO

try:
import json
Expand All @@ -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))
Expand Down Expand Up @@ -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(
Expand All @@ -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:
Expand Down

0 comments on commit fa45c44

Please sign in to comment.