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

This commit is contained in:
Michael Scherer 2016-09-06 15:11:36 +02:00 committed by Matt Clay
parent e969010cf9
commit f8b7ab1e10

View file

@ -381,9 +381,19 @@ tenant_ip: "192.168.200.21/23"
# import ansible.module_utils.basic # import ansible.module_utils.basic
import os import os
import sys import sys
import dbus HAVE_DBUS=False
from gi.repository import NetworkManager, NMClient try:
import dbus
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): class Nmcli(object):
""" """
@ -1010,6 +1020,12 @@ def main():
supports_check_mode=True 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) nmcli=Nmcli(module)
rc=None rc=None