Code cleanup in ansible-inventory.

This commit is contained in:
Matt Clay 2020-05-15 17:00:35 -07:00
parent 159d79995c
commit ed4fd9be67
2 changed files with 7 additions and 4 deletions

View file

@ -0,0 +1,3 @@
bugfixes:
- Use ``sys.exit`` instead of ``exit`` in ``ansible-inventory``.
- Remove unused Python imports in ``ansible-inventory``.

View file

@ -5,6 +5,8 @@
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
import sys
import argparse import argparse
from operator import attrgetter from operator import attrgetter
@ -13,9 +15,7 @@ from ansible import context
from ansible.cli import CLI from ansible.cli import CLI
from ansible.cli.arguments import option_helpers as opt_help from ansible.cli.arguments import option_helpers as opt_help
from ansible.errors import AnsibleError, AnsibleOptionsError from ansible.errors import AnsibleError, AnsibleOptionsError
from ansible.inventory.host import Host
from ansible.module_utils._text import to_bytes, to_native from ansible.module_utils._text import to_bytes, to_native
from ansible.plugins.loader import vars_loader
from ansible.utils.vars import combine_vars from ansible.utils.vars import combine_vars
from ansible.utils.display import Display from ansible.utils.display import Display
from ansible.vars.plugins import get_vars_from_inventory_sources, get_vars_from_path from ansible.vars.plugins import get_vars_from_inventory_sources, get_vars_from_path
@ -161,9 +161,9 @@ class InventoryCLI(CLI):
f.write(results) f.write(results)
except (OSError, IOError) as e: except (OSError, IOError) as e:
raise AnsibleError('Unable to write to destination file (%s): %s' % (to_native(outfile), to_native(e))) raise AnsibleError('Unable to write to destination file (%s): %s' % (to_native(outfile), to_native(e)))
exit(0) sys.exit(0)
exit(1) sys.exit(1)
@staticmethod @staticmethod
def dump(stuff): def dump(stuff):