mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Remove wildcard, add boilerplate and get rid of get_exception
* smaller collections of database modules * Some of the smaller collections of network modules
This commit is contained in:
parent
0c7602fb59
commit
0b9a78f0b3
110 changed files with 1094 additions and 2224 deletions
|
@ -1,20 +1,11 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright: Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||
'status': ['preview'],
|
||||
|
@ -79,6 +70,7 @@ EXAMPLES = """
|
|||
- name: updating load_balance_policy
|
||||
vertica_configuration: name=failovertostandbyafter value='8 hours'
|
||||
"""
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import pyodbc
|
||||
|
@ -88,7 +80,6 @@ else:
|
|||
pyodbc_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
|
@ -174,9 +165,9 @@ def main():
|
|||
module.params['login_user'], module.params['login_password'], 'true')
|
||||
db_conn = pyodbc.connect(dsn, autocommit=True)
|
||||
cursor = db_conn.cursor()
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="Unable to connect to database: {0}.".format(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Unable to connect to database: {0}.".format(to_native(e)),
|
||||
exception=traceback.format_exc())
|
||||
|
||||
try:
|
||||
configuration_facts = get_configuration_facts(cursor)
|
||||
|
@ -185,21 +176,17 @@ def main():
|
|||
else:
|
||||
try:
|
||||
changed = present(configuration_facts, cursor, parameter_name, current_value)
|
||||
except pyodbc.Error:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except NotSupportedError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e), ansible_facts={'vertica_configuration': configuration_facts})
|
||||
except CannotDropError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e), ansible_facts={'vertica_configuration': configuration_facts})
|
||||
except pyodbc.Error as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
except NotSupportedError as e:
|
||||
module.fail_json(msg=to_native(e), ansible_facts={'vertica_configuration': configuration_facts})
|
||||
except CannotDropError as e:
|
||||
module.fail_json(msg=to_native(e), ansible_facts={'vertica_configuration': configuration_facts})
|
||||
except SystemExit:
|
||||
# avoid catching this on python 2.4
|
||||
raise
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=to_native(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
module.exit_json(changed=changed, parameter=parameter_name, ansible_facts={'vertica_configuration': configuration_facts})
|
||||
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
# Copyright: Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||
'status': ['preview'],
|
||||
|
@ -71,6 +63,7 @@ EXAMPLES = """
|
|||
- name: gathering vertica facts
|
||||
vertica_facts: db=db_name
|
||||
"""
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import pyodbc
|
||||
|
@ -80,7 +73,6 @@ else:
|
|||
pyodbc_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
|
@ -255,9 +247,8 @@ def main():
|
|||
module.params['login_user'], module.params['login_password'], 'true')
|
||||
db_conn = pyodbc.connect(dsn, autocommit=True)
|
||||
cursor = db_conn.cursor()
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="Unable to connect to database: %s." % str(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Unable to connect to database: %s." % to_native(e), exception=traceback.format_exc())
|
||||
|
||||
try:
|
||||
schema_facts = get_schema_facts(cursor)
|
||||
|
@ -271,15 +262,13 @@ def main():
|
|||
'vertica_roles': role_facts,
|
||||
'vertica_configuration': configuration_facts,
|
||||
'vertica_nodes': node_facts})
|
||||
except NotSupportedError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except NotSupportedError as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
except SystemExit:
|
||||
# avoid catching this on python 2.4
|
||||
raise
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=to_native(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
# Copyright: Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||
'status': ['preview'],
|
||||
|
@ -90,6 +82,7 @@ EXAMPLES = """
|
|||
- name: creating a new vertica role with other role assigned
|
||||
vertica_role: name=role_name assigned_role=other_role_name state=present
|
||||
"""
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import pyodbc
|
||||
|
@ -99,7 +92,6 @@ else:
|
|||
pyodbc_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
|
@ -218,9 +210,8 @@ def main():
|
|||
module.params['login_user'], module.params['login_password'], 'true')
|
||||
db_conn = pyodbc.connect(dsn, autocommit=True)
|
||||
cursor = db_conn.cursor()
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="Unable to connect to database: {0}.".format(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Unable to connect to database: {0}.".format(to_native(e)))
|
||||
|
||||
try:
|
||||
role_facts = get_role_facts(cursor)
|
||||
|
@ -229,27 +220,22 @@ def main():
|
|||
elif state == 'absent':
|
||||
try:
|
||||
changed = absent(role_facts, cursor, role, assigned_roles)
|
||||
except pyodbc.Error:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except pyodbc.Error as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
elif state == 'present':
|
||||
try:
|
||||
changed = present(role_facts, cursor, role, assigned_roles)
|
||||
except pyodbc.Error:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except NotSupportedError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e), ansible_facts={'vertica_roles': role_facts})
|
||||
except CannotDropError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e), ansible_facts={'vertica_roles': role_facts})
|
||||
except pyodbc.Error as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
except NotSupportedError as e:
|
||||
module.fail_json(msg=to_native(e), ansible_facts={'vertica_roles': role_facts})
|
||||
except CannotDropError as e:
|
||||
module.fail_json(msg=to_native(e), ansible_facts={'vertica_roles': role_facts})
|
||||
except SystemExit:
|
||||
# avoid catching this on python 2.4
|
||||
raise
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=to_native(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
module.exit_json(changed=changed, role=role, ansible_facts={'vertica_roles': role_facts})
|
||||
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
# Copyright: Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||
'status': ['preview'],
|
||||
|
@ -114,6 +106,7 @@ EXAMPLES = """
|
|||
db=db_name
|
||||
state=present
|
||||
"""
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import pyodbc
|
||||
|
@ -123,7 +116,6 @@ else:
|
|||
pyodbc_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
|
@ -293,9 +285,8 @@ def main():
|
|||
module.params['login_user'], module.params['login_password'], 'true')
|
||||
db_conn = pyodbc.connect(dsn, autocommit=True)
|
||||
cursor = db_conn.cursor()
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="Unable to connect to database: {0}.".format(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Unable to connect to database: {0}.".format(to_native(e)))
|
||||
|
||||
try:
|
||||
schema_facts = get_schema_facts(cursor)
|
||||
|
@ -304,27 +295,22 @@ def main():
|
|||
elif state == 'absent':
|
||||
try:
|
||||
changed = absent(schema_facts, cursor, schema, usage_roles, create_roles)
|
||||
except pyodbc.Error:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except pyodbc.Error as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
elif state == 'present':
|
||||
try:
|
||||
changed = present(schema_facts, cursor, schema, usage_roles, create_roles, owner)
|
||||
except pyodbc.Error:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except NotSupportedError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e), ansible_facts={'vertica_schemas': schema_facts})
|
||||
except CannotDropError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e), ansible_facts={'vertica_schemas': schema_facts})
|
||||
except pyodbc.Error as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
except NotSupportedError as e:
|
||||
module.fail_json(msg=to_native(e), ansible_facts={'vertica_schemas': schema_facts})
|
||||
except CannotDropError as e:
|
||||
module.fail_json(msg=to_native(e), ansible_facts={'vertica_schemas': schema_facts})
|
||||
except SystemExit:
|
||||
# avoid catching this on python 2.4
|
||||
raise
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=to_native(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
module.exit_json(changed=changed, schema=schema, ansible_facts={'vertica_schemas': schema_facts})
|
||||
|
||||
|
|
|
@ -1,20 +1,11 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright: Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||
'status': ['preview'],
|
||||
|
@ -127,6 +118,7 @@ EXAMPLES = """
|
|||
roles=schema_name_ro
|
||||
state=present
|
||||
"""
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import pyodbc
|
||||
|
@ -136,7 +128,6 @@ else:
|
|||
pyodbc_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
|
@ -361,8 +352,7 @@ def main():
|
|||
module.params['login_user'], module.params['login_password'], 'true')
|
||||
db_conn = pyodbc.connect(dsn, autocommit=True)
|
||||
cursor = db_conn.cursor()
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Unable to connect to database: {0}.".format(e))
|
||||
|
||||
try:
|
||||
|
@ -373,28 +363,23 @@ def main():
|
|||
elif state == 'absent':
|
||||
try:
|
||||
changed = absent(user_facts, cursor, user, roles)
|
||||
except pyodbc.Error:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except pyodbc.Error as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
elif state in ['present', 'locked']:
|
||||
try:
|
||||
changed = present(user_facts, cursor, user, profile, resource_pool,
|
||||
locked, password, expired, ldap, roles)
|
||||
except pyodbc.Error:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except NotSupportedError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e), ansible_facts={'vertica_users': user_facts})
|
||||
except CannotDropError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e), ansible_facts={'vertica_users': user_facts})
|
||||
except pyodbc.Error as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
except NotSupportedError as e:
|
||||
module.fail_json(msg=to_native(e), ansible_facts={'vertica_users': user_facts})
|
||||
except CannotDropError as e:
|
||||
module.fail_json(msg=to_native(e), ansible_facts={'vertica_users': user_facts})
|
||||
except SystemExit:
|
||||
# avoid catching this on python 2.4
|
||||
raise
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=to_native(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
module.exit_json(changed=changed, user=user, ansible_facts={'vertica_users': user_facts})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue