mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Make configparser imports python3 ready
the ConfigParser module was renamed to configparser in Python3. Use six.moves to import it so that the modules will function on Python3.
This commit is contained in:
@@ -113,7 +113,7 @@ after:
|
||||
type: string
|
||||
'''
|
||||
|
||||
import ConfigParser
|
||||
import os
|
||||
|
||||
try:
|
||||
from pymongo.errors import ConnectionFailure
|
||||
@@ -130,13 +130,17 @@ except ImportError:
|
||||
else:
|
||||
pymongo_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
from ansible.module_utils.six.moves import configparser
|
||||
|
||||
|
||||
# =========================================
|
||||
# MongoDB module specific support methods.
|
||||
#
|
||||
|
||||
def load_mongocnf():
|
||||
config = ConfigParser.RawConfigParser()
|
||||
config = configparser.RawConfigParser()
|
||||
mongocnf = os.path.expanduser('~/.mongodb.cnf')
|
||||
|
||||
try:
|
||||
@@ -145,7 +149,7 @@ def load_mongocnf():
|
||||
user=config.get('client', 'user'),
|
||||
password=config.get('client', 'pass')
|
||||
)
|
||||
except (ConfigParser.NoOptionError, IOError):
|
||||
except (configparser.NoOptionError, IOError):
|
||||
return False
|
||||
|
||||
return creds
|
||||
@@ -231,9 +235,5 @@ def main():
|
||||
after=value)
|
||||
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -189,9 +189,10 @@ EXAMPLES = '''
|
||||
|
||||
'''
|
||||
|
||||
import os
|
||||
import ssl as ssl_lib
|
||||
import ConfigParser
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
try:
|
||||
from pymongo.errors import ConnectionFailure
|
||||
from pymongo.errors import OperationFailure
|
||||
@@ -207,6 +208,11 @@ except ImportError:
|
||||
else:
|
||||
pymongo_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
from ansible.module_utils.six.moves import configparser
|
||||
|
||||
|
||||
# =========================================
|
||||
# MongoDB module specific support methods.
|
||||
#
|
||||
@@ -279,7 +285,7 @@ def user_remove(module, client, db_name, user):
|
||||
module.exit_json(changed=False, user=user)
|
||||
|
||||
def load_mongocnf():
|
||||
config = ConfigParser.RawConfigParser()
|
||||
config = configparser.RawConfigParser()
|
||||
mongocnf = os.path.expanduser('~/.mongodb.cnf')
|
||||
|
||||
try:
|
||||
@@ -288,7 +294,7 @@ def load_mongocnf():
|
||||
user=config.get('client', 'user'),
|
||||
password=config.get('client', 'pass')
|
||||
)
|
||||
except (ConfigParser.NoOptionError, IOError):
|
||||
except (configparser.NoOptionError, IOError):
|
||||
return False
|
||||
|
||||
return creds
|
||||
@@ -446,9 +452,6 @@ def main():
|
||||
|
||||
module.exit_json(changed=True, user=user)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user