Do not crash if the system do not have required modules (#2852)
This commit is contained in:
parent
e969010cf9
commit
f8b7ab1e10
1 changed files with 18 additions and 2 deletions
|
@ -381,9 +381,19 @@ tenant_ip: "192.168.200.21/23"
|
|||
# import ansible.module_utils.basic
|
||||
import os
|
||||
import sys
|
||||
import dbus
|
||||
from gi.repository import NetworkManager, NMClient
|
||||
HAVE_DBUS=False
|
||||
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):
|
||||
"""
|
||||
|
@ -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…
Reference in a new issue