mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
parent
2f33c1a1a1
commit
5553b20828
206 changed files with 1853 additions and 1870 deletions
|
@ -134,7 +134,7 @@ class LookupModule(LookupBase):
|
|||
item[1] = ASCENDING
|
||||
elif sort_order == "DESCENDING":
|
||||
item[1] = DESCENDING
|
||||
#else the user knows what s/he is doing and we won't predict. PyMongo will return an error if necessary
|
||||
# else the user knows what s/he is doing and we won't predict. PyMongo will return an error if necessary
|
||||
|
||||
def convert_mongo_result_to_valid_json(self, result):
|
||||
if result is None:
|
||||
|
@ -151,17 +151,16 @@ class LookupModule(LookupBase):
|
|||
elif isinstance(result, dict):
|
||||
new_dict = {}
|
||||
for key in result.keys():
|
||||
value = result[key] # python2 and 3 compatible....
|
||||
value = result[key] # python2 and 3 compatible....
|
||||
new_dict[key] = self.convert_mongo_result_to_valid_json(value)
|
||||
return new_dict
|
||||
elif isinstance(result, datetime.datetime):
|
||||
#epoch
|
||||
return (result - datetime.datetime(1970,1,1)).total_seconds()
|
||||
# epoch
|
||||
return (result - datetime.datetime(1970, 1, 1)). total_seconds()
|
||||
else:
|
||||
#failsafe
|
||||
# failsafe
|
||||
return "{}".format(result)
|
||||
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
ret = []
|
||||
|
@ -226,7 +225,7 @@ class LookupModule(LookupBase):
|
|||
|
||||
try:
|
||||
client = MongoClient(connection_string, **extra_connection_parameters)
|
||||
results = client[database][collection].find( **term )
|
||||
results = client[database][collection].find(**term)
|
||||
|
||||
for result in results:
|
||||
result = self.convert_mongo_result_to_valid_json(result)
|
||||
|
@ -235,6 +234,4 @@ class LookupModule(LookupBase):
|
|||
except ConnectionFailure as e:
|
||||
raise AnsibleError('unable to connect to database: %s' % str(e))
|
||||
|
||||
|
||||
|
||||
return ret
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue