Do not crash if the system do not have required modules (#2852)

pull/18777/head
Michael Scherer 8 years ago committed by Matt Clay
parent e969010cf9
commit f8b7ab1e10

@ -381,9 +381,19 @@ tenant_ip: "192.168.200.21/23"
# import ansible.module_utils.basic
import os
import sys
HAVE_DBUS=False
try:
import dbus
from gi.repository import NetworkManager, NMClient
HAVE_DBUS=True
except ImportError:
pass
HAVE_NM_CLIENT=False
try:
from gi.repository import NetworkManager, NMClient
HAVE_NM_CLIENT=True
except ImportError:
pass
class Nmcli(object):
"""
@ -1010,6 +1020,12 @@ def main():
supports_check_mode=True
)
if not HAVE_DBUS:
module.fail_json(msg="This module requires dbus python bindings")
if not HAVE_NM_CLIENT:
module.fail_json(msg="This module requires NetworkManager glib API")
nmcli=Nmcli(module)
rc=None

Loading…
Cancel
Save