mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-07-25 00:44:42 +00:00
Merge pull request #1261 from t-woerner/inventory_plugin_try_imports
plugins/inventory/freeipa: Try imports for requests and urllib3
This commit is contained in:
@@ -92,12 +92,14 @@ verify: ca.crt
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import requests
|
|
||||||
try:
|
try:
|
||||||
from requests.packages import urllib3
|
import requests
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
requests = None
|
||||||
|
try:
|
||||||
import urllib3
|
import urllib3
|
||||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
except ImportError:
|
||||||
|
urllib3 = None
|
||||||
|
|
||||||
from ansible import constants
|
from ansible import constants
|
||||||
from ansible.errors import AnsibleParserError
|
from ansible.errors import AnsibleParserError
|
||||||
@@ -125,6 +127,11 @@ class InventoryModule(BaseInventoryPlugin):
|
|||||||
self._read_config_data(path) # This also loads the cache
|
self._read_config_data(path) # This also loads the cache
|
||||||
|
|
||||||
self.get_option("plugin")
|
self.get_option("plugin")
|
||||||
|
|
||||||
|
if requests is None:
|
||||||
|
raise AnsibleParserError("The required Python library "
|
||||||
|
"'requests' could not be imported.")
|
||||||
|
|
||||||
ipaadmin_principal = self.get_option("ipaadmin_principal")
|
ipaadmin_principal = self.get_option("ipaadmin_principal")
|
||||||
ipaadmin_password = self.get_option("ipaadmin_password")
|
ipaadmin_password = self.get_option("ipaadmin_password")
|
||||||
server = self.get_option("server")
|
server = self.get_option("server")
|
||||||
@@ -137,6 +144,11 @@ class InventoryModule(BaseInventoryPlugin):
|
|||||||
raise AnsibleParserError("ERROR: Could not load %s" % verify)
|
raise AnsibleParserError("ERROR: Could not load %s" % verify)
|
||||||
else:
|
else:
|
||||||
verify = False
|
verify = False
|
||||||
|
# Disable certificate verification warning without certificate
|
||||||
|
# as long as urllib3 could have been loaded.
|
||||||
|
if urllib3 is not None:
|
||||||
|
urllib3.disable_warnings(
|
||||||
|
urllib3.exceptions.InsecureRequestWarning)
|
||||||
|
|
||||||
self.inventory.add_group(inventory_group)
|
self.inventory.add_group(inventory_group)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user