# Buggy code
def main():
    args = parse_args()
    try:
        config_files = cloud_config.CONFIG_FILES + CONFIG_FILES
        sdk.enable_logging(debug=args.debug)
        inventory_args = dict(
            refresh=args.refresh,
            config_files=config_files,
            private=args.private,
            cloud=args.cloud,
        )
        if hasattr(sdk_inventory.OpenStackInventory, "extra_config"):
            inventory_args.update(
                dict(
                    config_key="ansible",
                    config_defaults={
                        "use_hostnames": False,
                        "expand_hostvars": True,
                        "fail_on_errors": True,
                    },
                )
            )

        inventory = sdk_inventory.OpenStackInventory(**inventory_args)

        if args.list:
            output = get_host_groups(inventory, refresh=args.refresh, cloud=args.cloud)
        elif args.host:
            output = to_json(inventory.get_host(args.host))
        print(output)
    except sdk.exceptions.OpenStackCloudException as e:
        sys.stderr.write("%s\n" % e.message)
        sys.exit(1)
    sys.exit(0)


# Traceback (RuntimeError)
2.890 INFO     Updating inventory 722: Inventory - WindowMonitor㚝
2.916 INFO     Reading Ansible inventory source: /awx_devel/awx/plugins/inventory/openstack.py
Traceback (most recent call last):
File "/usr/local/bin/awx-manage", line 9, in <module>
load_entry_point('awx', 'console_scripts', 'awx-manage')()
File "/awx_devel/awx/__init__.py", line 116, in manage
execute_from_command_line(sys.argv)
File "/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/venv/awx/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/venv/awx/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/awx_devel/awx/main/management/commands/inventory_import.py", line 994, in handle
self.is_custom)
File "/awx_devel/awx/main/management/commands/inventory_import.py", line 245, in load_inventory_source
is_custom=is_custom).load()
File "/awx_devel/awx/main/management/commands/inventory_import.py", line 180, in load
data = self.command_to_json(base_args + ['--list'])
File "/awx_devel/awx/main/management/commands/inventory_import.py", line 163, in command_to_json
self.method, proc.returncode, stdout, stderr))
RuntimeError: ansible-inventory failed (rc=1) with stdout:

stderr:
[WARNING]:  * Failed to parse /awx_devel/awx/plugins/inventory/openstack.py
with script plugin: Invalid empty/false group name provided:

[WARNING]: Unable to parse /awx_devel/awx/plugins/inventory/openstack.py as an
inventory source

ERROR! No inventory was parsed, please check your configuration and options.

# Fixed code
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(
            refresh=args.refresh,
            config_files=config_files,
            private=args.private,
            cloud=args.cloud,
        )
        if hasattr(sdk_inventory.OpenStackInventory, "extra_config"):
            inventory_args.update(
                dict(
                    config_key="ansible",
                    config_defaults={
                        "use_hostnames": False,
                        "expand_hostvars": True,
                        "fail_on_errors": True,
                    },
                )
            )

        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:
            output = to_json(inventory.get_host(args.host))
        print(output)
    except sdk.exceptions.OpenStackCloudException as e:
        sys.stderr.write("%s\n" % e.message)
        sys.exit(1)
    sys.exit(0)