mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00: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:
@@ -1,21 +1,11 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# (c) 2016, Kamil Szczygiel <kamil.szczygiel () intel.com>
|
||||
#
|
||||
# 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/>.
|
||||
# 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'],
|
||||
@@ -100,6 +90,8 @@ try:
|
||||
except ImportError:
|
||||
HAS_INFLUXDB = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def influxdb_argument_spec():
|
||||
return dict(
|
||||
@@ -193,7 +185,6 @@ def main():
|
||||
else:
|
||||
module.exit_json(changed=False)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -1,21 +1,11 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# (c) 2016, Kamil Szczygiel <kamil.szczygiel () intel.com>
|
||||
#
|
||||
# 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/>.
|
||||
# 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'],
|
||||
@@ -115,6 +105,7 @@ RETURN = '''
|
||||
'''
|
||||
|
||||
import re
|
||||
|
||||
try:
|
||||
import requests.exceptions
|
||||
from influxdb import InfluxDBClient
|
||||
@@ -123,6 +114,8 @@ try:
|
||||
except ImportError:
|
||||
HAS_INFLUXDB = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def influxdb_argument_spec():
|
||||
return dict(
|
||||
@@ -238,7 +231,6 @@ def main():
|
||||
else:
|
||||
create_retention_policy(module, client)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Ansible module to manage elasticsearch plugins
|
||||
# (c) 2015, Mathew Davies <thepixeldeveloper@googlemail.com>
|
||||
#
|
||||
# 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/>.
|
||||
# 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'],
|
||||
@@ -102,11 +92,15 @@ EXAMPLES = '''
|
||||
|
||||
import os
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
PACKAGE_STATE_MAP = dict(
|
||||
present="install",
|
||||
absent="remove"
|
||||
)
|
||||
|
||||
|
||||
def parse_plugin_repo(string):
|
||||
elements = string.split("/")
|
||||
|
||||
@@ -219,7 +213,6 @@ def main():
|
||||
|
||||
module.exit_json(changed=changed, cmd=cmd, name=name, state=state, url=url, timeout=timeout, stdout=out, stderr=err)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -1,23 +1,14 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Ansible module to manage elasticsearch shield role
|
||||
# (c) 2016, Thierno IB. BARRY @barryib
|
||||
# Sponsored by Polyconseil http://polyconseil.fr.
|
||||
#
|
||||
# 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/>.
|
||||
# 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'],
|
||||
@@ -129,11 +120,15 @@ state:
|
||||
|
||||
import os
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
PACKAGE_STATE_MAP = dict(
|
||||
present="--install",
|
||||
absent="--remove"
|
||||
)
|
||||
|
||||
|
||||
def parse_plugin_repo(string):
|
||||
elements = string.split("/")
|
||||
|
||||
@@ -241,7 +236,6 @@ def main():
|
||||
|
||||
module.exit_json(changed=changed, cmd=cmd, name=name, state=state, url=url, timeout=timeout, stdout=out, stderr=err)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
#!/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'],
|
||||
@@ -141,6 +133,7 @@ EXAMPLES = '''
|
||||
name: lua-time-limit
|
||||
value: 100
|
||||
'''
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import redis
|
||||
@@ -149,6 +142,9 @@ except ImportError:
|
||||
else:
|
||||
redis_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
# ===========================================
|
||||
# Redis module specific support methods.
|
||||
@@ -231,9 +227,9 @@ def main():
|
||||
password=login_password)
|
||||
try:
|
||||
r.ping()
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="unable to connect to database: %s" % e)
|
||||
except Exception as e:
|
||||
module.fail_json(msg="unable to connect to database: %s" % to_native(e),
|
||||
exception=traceback.format_exc())
|
||||
|
||||
#Check if we are already in the mode that we want
|
||||
info = r.info()
|
||||
@@ -291,9 +287,9 @@ def main():
|
||||
db=db)
|
||||
try:
|
||||
r.ping()
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="unable to connect to database: %s" % e)
|
||||
except Exception as e:
|
||||
module.fail_json(msg="unable to connect to database: %s" % to_native(e),
|
||||
exception=traceback.format_exc())
|
||||
|
||||
# Do the stuff
|
||||
# (Check Check_mode before commands so the commands aren't evaluated
|
||||
@@ -319,16 +315,16 @@ def main():
|
||||
|
||||
try:
|
||||
r.ping()
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="unable to connect to database: %s" % e)
|
||||
except Exception as e:
|
||||
module.fail_json(msg="unable to connect to database: %s" % to_native(e),
|
||||
exception=traceback.format_exc())
|
||||
|
||||
|
||||
try:
|
||||
old_value = r.config_get(name)[name]
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="unable to read config: %s" % e)
|
||||
except Exception as e:
|
||||
module.fail_json(msg="unable to read config: %s" % to_native(e),
|
||||
exception=traceback.format_exc())
|
||||
changed = old_value != value
|
||||
|
||||
if module.check_mode or not changed:
|
||||
@@ -336,16 +332,13 @@ def main():
|
||||
else:
|
||||
try:
|
||||
r.config_set(name, value)
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="unable to write config: %s" % e)
|
||||
except Exception as e:
|
||||
module.fail_json(msg="unable to write config: %s" % to_native(e),
|
||||
exception=traceback.format_exc())
|
||||
module.exit_json(changed=changed, name=name, value=value)
|
||||
else:
|
||||
module.fail_json(msg='A valid command must be provided')
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -2,22 +2,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# (c) 2013, James Martin <jmartin@basho.com>, Drew Kerrigan <dkerrigan@basho.com>
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
# 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'],
|
||||
'supported_by': 'community'}
|
||||
@@ -97,18 +87,11 @@ EXAMPLES = '''
|
||||
wait_for_service: kv
|
||||
'''
|
||||
|
||||
import json
|
||||
import time
|
||||
import socket
|
||||
import sys
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
try:
|
||||
import simplejson as json
|
||||
except ImportError:
|
||||
# Let snippet from module_utils/basic.py return a proper error in this case
|
||||
pass
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
|
||||
|
||||
def ring_check(module, riak_admin_bin):
|
||||
@@ -137,13 +120,11 @@ def main():
|
||||
|
||||
|
||||
command = module.params.get('command')
|
||||
config_dir = module.params.get('config_dir')
|
||||
http_conn = module.params.get('http_conn')
|
||||
target_node = module.params.get('target_node')
|
||||
wait_for_handoffs = module.params.get('wait_for_handoffs')
|
||||
wait_for_ring = module.params.get('wait_for_ring')
|
||||
wait_for_service = module.params.get('wait_for_service')
|
||||
validate_certs = module.params.get('validate_certs')
|
||||
|
||||
|
||||
#make sure riak commands are on the path
|
||||
@@ -255,8 +236,6 @@ def main():
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.urls import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -1,26 +1,15 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
(c) 2016, Loic Blot <loic.blot@unix-experience.fr>
|
||||
Sponsored by Infopro Digital. http://www.infopro-digital.com/
|
||||
Sponsored by E.T.A.I. http://www.etai.fr/
|
||||
# (c) 2016, Loic Blot <loic.blot@unix-experience.fr>
|
||||
# Sponsored by Infopro Digital. http://www.infopro-digital.com/
|
||||
# Sponsored by E.T.A.I. http://www.etai.fr/
|
||||
#
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
This file is part of Ansible
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
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'],
|
||||
@@ -115,6 +104,7 @@ after:
|
||||
'''
|
||||
|
||||
import os
|
||||
import traceback
|
||||
|
||||
try:
|
||||
from pymongo.errors import ConnectionFailure
|
||||
@@ -132,8 +122,8 @@ 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
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
# =========================================
|
||||
@@ -197,7 +187,6 @@ def main():
|
||||
if param_type == 'int':
|
||||
value = int(value)
|
||||
except ValueError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="value '%s' is not %s" % (value, param_type))
|
||||
|
||||
try:
|
||||
@@ -217,17 +206,15 @@ def main():
|
||||
if login_user is not None and login_password is not None:
|
||||
client.admin.authenticate(login_user, login_password, source=login_database)
|
||||
|
||||
except ConnectionFailure:
|
||||
e = get_exception()
|
||||
module.fail_json(msg='unable to connect to database: %s' % str(e))
|
||||
except ConnectionFailure as e:
|
||||
module.fail_json(msg='unable to connect to database: %s' % to_native(e), exception=traceback.format_exc())
|
||||
|
||||
db = client.admin
|
||||
|
||||
try:
|
||||
after_value = db.command("setParameter", **{param: value})
|
||||
except OperationFailure:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="unable to change parameter: %s" % str(e))
|
||||
except OperationFailure as e:
|
||||
module.fail_json(msg="unable to change parameter: %s" % to_native(e), exception=traceback.format_exc())
|
||||
|
||||
if "was" not in after_value:
|
||||
module.exit_json(changed=True, msg="Unable to determine old value, assume it changed.")
|
||||
|
||||
@@ -4,20 +4,11 @@
|
||||
# Sponsored by Four Kitchens http://fourkitchens.com.
|
||||
# (c) 2014, Epic Games, Inc.
|
||||
#
|
||||
# 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/>.
|
||||
# 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'],
|
||||
@@ -390,7 +381,6 @@ def main():
|
||||
user = module.params['name']
|
||||
password = module.params['password']
|
||||
ssl = module.params['ssl']
|
||||
ssl_cert_reqs = None
|
||||
roles = module.params['roles'] or []
|
||||
state = module.params['state']
|
||||
update_password = module.params['update_password']
|
||||
|
||||
@@ -1,24 +1,13 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Ansible module to manage mssql databases
|
||||
# (c) 2014, Vedit Firat Arig <firatarig@gmail.com>
|
||||
# Outline and parts are reused from Mark Theunissen's mysql_db module
|
||||
#
|
||||
# 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/>.
|
||||
# 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'],
|
||||
@@ -107,6 +96,7 @@ RETURN = '''
|
||||
'''
|
||||
|
||||
import os
|
||||
|
||||
try:
|
||||
import pymssql
|
||||
except ImportError:
|
||||
@@ -114,6 +104,8 @@ except ImportError:
|
||||
else:
|
||||
mssql_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def db_exists(conn, cursor, db):
|
||||
cursor.execute("SELECT name FROM master.sys.databases WHERE name = %s", db)
|
||||
@@ -241,8 +233,6 @@ def main():
|
||||
|
||||
module.exit_json(changed=changed, db=db)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
@@ -3,21 +3,11 @@
|
||||
|
||||
# (c) 2012, Mark Theunissen <mark.theunissen@gmail.com>
|
||||
# Sponsored by Four Kitchens http://fourkitchens.com.
|
||||
#
|
||||
# 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/>.
|
||||
# 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,8 +104,8 @@ EXAMPLES = '''
|
||||
|
||||
import os
|
||||
import pipes
|
||||
import stat
|
||||
import subprocess
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import MySQLdb
|
||||
@@ -124,6 +114,12 @@ except ImportError:
|
||||
else:
|
||||
mysqldb_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.database import mysql_quote_identifier
|
||||
from ansible.module_utils.mysql import mysql_connect, mysqldb_found
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
# ===========================================
|
||||
# MySQL module specific support methods.
|
||||
#
|
||||
@@ -316,13 +312,12 @@ def main():
|
||||
try:
|
||||
cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca,
|
||||
connect_timeout=connect_timeout)
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
except Exception as e:
|
||||
if os.path.exists(config_file):
|
||||
module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. "
|
||||
"Exception message: %s" % (config_file, e))
|
||||
"Exception message: %s" % (config_file, to_native(e)))
|
||||
else:
|
||||
module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, e))
|
||||
module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, to_native(e)))
|
||||
|
||||
changed = False
|
||||
if not os.path.exists(config_file):
|
||||
@@ -334,9 +329,8 @@ def main():
|
||||
else:
|
||||
try:
|
||||
changed = db_delete(cursor, db)
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="error deleting database: " + str(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg="error deleting database: %s" % to_native(e))
|
||||
module.exit_json(changed=changed, db=db)
|
||||
|
||||
elif state == "dump":
|
||||
@@ -378,9 +372,9 @@ def main():
|
||||
else:
|
||||
try:
|
||||
changed = db_create(cursor, db, encoding, collation)
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="error creating database: " + str(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg="error creating database: %s" % to_native(e),
|
||||
exception=traceback.format_exc())
|
||||
module.exit_json(changed=changed, db=db)
|
||||
|
||||
elif state == "import":
|
||||
@@ -397,9 +391,9 @@ def main():
|
||||
module.fail_json(msg="%s" % stderr)
|
||||
else:
|
||||
module.exit_json(changed=True, db=db, msg=stdout)
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="error creating database: " + str(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg="error creating database: %s" % to_native(e),
|
||||
exception=traceback.format_exc())
|
||||
|
||||
elif state == "absent":
|
||||
if module.check_mode:
|
||||
@@ -411,9 +405,6 @@ def main():
|
||||
module.exit_json(changed=False, db=db)
|
||||
module.fail_json(msg="Cannot dump database %s - not found" % (db))
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.database import *
|
||||
from ansible.module_utils.mysql import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -1,26 +1,14 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
# (c) 2013, Balazs Pocze <banyek@gawker.com>
|
||||
# Certain parts are taken from Mark Theunissen's mysqldb module
|
||||
#
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
Ansible module to manage mysql replication
|
||||
(c) 2013, Balazs Pocze <banyek@gawker.com>
|
||||
Certain parts are taken from Mark Theunissen's mysqldb module
|
||||
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'],
|
||||
@@ -142,7 +130,7 @@ else:
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.mysql import mysql_connect
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
def get_master_status(cursor):
|
||||
@@ -265,13 +253,12 @@ def main():
|
||||
try:
|
||||
cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca, None, 'MySQLdb.cursors.DictCursor',
|
||||
connect_timeout=connect_timeout)
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
except Exception as e:
|
||||
if os.path.exists(config_file):
|
||||
module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. "
|
||||
"Exception message: %s" % (config_file, e))
|
||||
"Exception message: %s" % (config_file, to_native(e)))
|
||||
else:
|
||||
module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, e))
|
||||
module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, to_native(e)))
|
||||
|
||||
if mode in "getmaster":
|
||||
status = get_master_status(cursor)
|
||||
@@ -341,12 +328,10 @@ def main():
|
||||
chm.append("MASTER_AUTO_POSITION = 1")
|
||||
try:
|
||||
changemaster(cursor, chm, chm_params)
|
||||
except MySQLdb.Warning:
|
||||
e = get_exception()
|
||||
result['warning'] = str(e)
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg='%s. Query == CHANGE MASTER TO %s' % (e, chm))
|
||||
except MySQLdb.Warning as e:
|
||||
result['warning'] = to_native(e)
|
||||
except Exception as e:
|
||||
module.fail_json(msg='%s. Query == CHANGE MASTER TO %s' % (to_native(e), chm))
|
||||
result['changed'] = True
|
||||
module.exit_json(**result)
|
||||
elif mode in "startslave":
|
||||
|
||||
@@ -2,21 +2,11 @@
|
||||
|
||||
# (c) 2012, Mark Theunissen <mark.theunissen@gmail.com>
|
||||
# Sponsored by Four Kitchens http://fourkitchens.com.
|
||||
#
|
||||
# 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/>.
|
||||
# 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'],
|
||||
@@ -214,16 +204,23 @@ EXAMPLES = """
|
||||
# password=n<_665{vS43y
|
||||
"""
|
||||
|
||||
|
||||
import re
|
||||
import string
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import MySQLdb
|
||||
except ImportError:
|
||||
mysqldb_found = False
|
||||
else:
|
||||
mysqldb_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.database import SQLParseError
|
||||
from ansible.module_utils.mysql import mysql_connect, mysqldb_found
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
VALID_PRIVS = frozenset(('CREATE', 'DROP', 'GRANT', 'GRANT OPTION',
|
||||
'LOCK TABLES', 'REFERENCES', 'EVENT', 'ALTER',
|
||||
@@ -608,10 +605,9 @@ def main():
|
||||
if not cursor:
|
||||
cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca, db,
|
||||
connect_timeout=connect_timeout)
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
except Exception as e:
|
||||
module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. "
|
||||
"Exception message: %s" % (config_file, e))
|
||||
"Exception message: %s" % (config_file, to_native(e)))
|
||||
|
||||
if not sql_log_bin:
|
||||
cursor.execute("SET SQL_LOG_BIN=0;")
|
||||
@@ -619,14 +615,12 @@ def main():
|
||||
if priv is not None:
|
||||
try:
|
||||
mode = get_mode(cursor)
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
try:
|
||||
priv = privileges_unpack(priv, mode)
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="invalid privileges string: %s" % str(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg="invalid privileges string: %s" % to_native(e))
|
||||
|
||||
if state == "present":
|
||||
if user_exists(cursor, user, host, host_all):
|
||||
@@ -636,17 +630,15 @@ def main():
|
||||
else:
|
||||
changed = user_mod(cursor, user, host, host_all, None, encrypted, priv, append_privs, module)
|
||||
|
||||
except (SQLParseError, InvalidPrivsError, MySQLdb.Error):
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except (SQLParseError, InvalidPrivsError, MySQLdb.Error) as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
else:
|
||||
if host_all:
|
||||
module.fail_json(msg="host_all parameter cannot be used when adding a user")
|
||||
try:
|
||||
changed = user_add(cursor, user, host, host_all, password, encrypted, priv, module.check_mode)
|
||||
except (SQLParseError, InvalidPrivsError, MySQLdb.Error):
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except (SQLParseError, InvalidPrivsError, MySQLdb.Error) as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
elif state == "absent":
|
||||
if user_exists(cursor, user, host, host_all):
|
||||
changed = user_delete(cursor, user, host, host_all, module.check_mode)
|
||||
@@ -654,10 +646,6 @@ def main():
|
||||
changed = False
|
||||
module.exit_json(changed=changed, user=user)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.database import *
|
||||
from ansible.module_utils.mysql import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -1,26 +1,14 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
# (c) 2013, Balazs Pocze <banyek@gawker.com>
|
||||
# Certain parts are taken from Mark Theunissen's mysqldb module
|
||||
#
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
Ansible module to manage mysql variables
|
||||
(c) 2013, Balazs Pocze <banyek@gawker.com>
|
||||
Certain parts are taken from Mark Theunissen's mysqldb module
|
||||
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'],
|
||||
@@ -58,7 +46,7 @@ EXAMPLES = '''
|
||||
value: 1
|
||||
'''
|
||||
|
||||
|
||||
import os
|
||||
import warnings
|
||||
from re import match
|
||||
|
||||
@@ -69,6 +57,11 @@ except ImportError:
|
||||
else:
|
||||
mysqldb_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.database import SQLParseError, mysql_quote_identifier
|
||||
from ansible.module_utils.mysql import mysql_connect, mysqldb_found
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
def typedvalue(value):
|
||||
"""
|
||||
@@ -118,9 +111,8 @@ def setvariable(cursor, mysqlvar, value):
|
||||
cursor.execute(query + "%s", (value,))
|
||||
cursor.fetchall()
|
||||
result = True
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
result = str(e)
|
||||
except Exception as e:
|
||||
result = to_native(e)
|
||||
return result
|
||||
|
||||
|
||||
@@ -164,13 +156,12 @@ def main():
|
||||
try:
|
||||
cursor = mysql_connect(module, user, password, config_file, ssl_cert, ssl_key, ssl_ca, db,
|
||||
connect_timeout=connect_timeout)
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
except Exception as e:
|
||||
if os.path.exists(config_file):
|
||||
module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. "
|
||||
"Exception message: %s" % (config_file, e))
|
||||
"Exception message: %s" % (config_file, to_native(e)))
|
||||
else:
|
||||
module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, e))
|
||||
module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, to_native(e)))
|
||||
|
||||
mysqlvar_val = getvariable(cursor, mysqlvar)
|
||||
if mysqlvar_val is None:
|
||||
@@ -185,17 +176,14 @@ def main():
|
||||
module.exit_json(msg="Variable already set to requested value", changed=False)
|
||||
try:
|
||||
result = setvariable(cursor, mysqlvar, value_wanted)
|
||||
except SQLParseError:
|
||||
e = get_exception()
|
||||
result = str(e)
|
||||
except SQLParseError as e:
|
||||
result = to_native(e)
|
||||
|
||||
if result is True:
|
||||
module.exit_json(msg="Variable change succeeded prev_value=%s" % value_actual, changed=True)
|
||||
else:
|
||||
module.fail_json(msg=result, changed=False)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.database import *
|
||||
from ansible.module_utils.mysql import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -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': ['stableinterface'],
|
||||
@@ -120,6 +111,8 @@ EXAMPLES = '''
|
||||
target_opts: "-n public"
|
||||
'''
|
||||
|
||||
import traceback
|
||||
|
||||
HAS_PSYCOPG2 = False
|
||||
try:
|
||||
import psycopg2
|
||||
@@ -132,13 +125,12 @@ except ImportError:
|
||||
pass
|
||||
else:
|
||||
HAS_PSYCOPG2 = True
|
||||
from ansible.module_utils.six import iteritems
|
||||
|
||||
import traceback
|
||||
|
||||
import ansible.module_utils.postgres as pgutils
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.database import SQLParseError, pg_quote_identifier
|
||||
from ansible.module_utils.basic import get_exception, AnsibleModule
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
class NotSupportedError(Exception):
|
||||
@@ -386,7 +378,6 @@ def main():
|
||||
module.fail_json(msg="the python psycopg2 module is required")
|
||||
|
||||
db = module.params["db"]
|
||||
port = module.params["port"]
|
||||
owner = module.params["owner"]
|
||||
template = module.params["template"]
|
||||
encoding = module.params["encoding"]
|
||||
@@ -395,7 +386,6 @@ def main():
|
||||
target = module.params["target"]
|
||||
target_opts = module.params["target_opts"]
|
||||
state = module.params["state"]
|
||||
sslrootcert = module.params["ssl_rootcert"]
|
||||
changed = False
|
||||
|
||||
# To use defaults values, keyword arguments must be absent, so
|
||||
@@ -435,20 +425,17 @@ def main():
|
||||
db_connection.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
||||
cursor = db_connection.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||
|
||||
except pgutils.LibraryError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="unable to connect to database: {0}".format(str(e)), exception=traceback.format_exc())
|
||||
except pgutils.LibraryError as e:
|
||||
module.fail_json(msg="unable to connect to database: {0}".format(to_native(e)), exception=traceback.format_exc())
|
||||
|
||||
except TypeError:
|
||||
e = get_exception()
|
||||
except TypeError as e:
|
||||
if 'sslrootcert' in e.args[0]:
|
||||
module.fail_json(msg='Postgresql server must be at least version 8.4 to support sslrootcert. Exception: {0}'.format(e),
|
||||
module.fail_json(msg='Postgresql server must be at least version 8.4 to support sslrootcert. Exception: {0}'.format(to_native(e)),
|
||||
exception=traceback.format_exc())
|
||||
module.fail_json(msg="unable to connect to database: %s" % e, exception=traceback.format_exc())
|
||||
module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())
|
||||
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="unable to connect to database: %s" % e, exception=traceback.format_exc())
|
||||
except Exception as e:
|
||||
module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())
|
||||
|
||||
try:
|
||||
if module.check_mode:
|
||||
@@ -461,16 +448,14 @@ def main():
|
||||
if state == "absent":
|
||||
try:
|
||||
changed = db_delete(cursor, db)
|
||||
except SQLParseError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except SQLParseError as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
elif state == "present":
|
||||
try:
|
||||
changed = db_create(cursor, db, owner, template, encoding, lc_collate, lc_ctype)
|
||||
except SQLParseError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except SQLParseError as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
elif state in ("dump", "restore"):
|
||||
method = state == "dump" and db_dump or db_restore
|
||||
@@ -480,19 +465,16 @@ def main():
|
||||
module.fail_json(msg=stderr, stdout=stdout, rc=rc, cmd=cmd)
|
||||
else:
|
||||
module.exit_json(changed=True, msg=stdout, stderr=stderr, rc=rc, cmd=cmd)
|
||||
except SQLParseError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except SQLParseError as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
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="Database query failed: %s" % e)
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Database query failed: %s" % to_native(e), exception=traceback.format_exc())
|
||||
|
||||
module.exit_json(changed=changed, db=db)
|
||||
|
||||
|
||||
@@ -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'],
|
||||
@@ -81,6 +72,7 @@ EXAMPLES = '''
|
||||
name: postgis
|
||||
db: acme
|
||||
'''
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import psycopg2
|
||||
@@ -90,6 +82,10 @@ except ImportError:
|
||||
else:
|
||||
postgresqldb_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
class NotSupportedError(Exception):
|
||||
pass
|
||||
|
||||
@@ -142,7 +138,6 @@ def main():
|
||||
|
||||
db = module.params["db"]
|
||||
ext = module.params["ext"]
|
||||
port = module.params["port"]
|
||||
state = module.params["state"]
|
||||
changed = False
|
||||
|
||||
@@ -168,9 +163,8 @@ def main():
|
||||
.ISOLATION_LEVEL_AUTOCOMMIT)
|
||||
cursor = db_connection.cursor(
|
||||
cursor_factory=psycopg2.extras.DictCursor)
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="unable to connect to database: %s" % e)
|
||||
except Exception as e:
|
||||
module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())
|
||||
|
||||
try:
|
||||
if module.check_mode:
|
||||
@@ -184,18 +178,13 @@ def main():
|
||||
|
||||
elif state == "present":
|
||||
changed = ext_create(cursor, ext)
|
||||
except NotSupportedError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="Database query failed: %s" % e)
|
||||
except NotSupportedError as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Database query failed: %s" % to_native(e), exception=traceback.format_exc())
|
||||
|
||||
module.exit_json(changed=changed, db=db, ext=ext)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -2,21 +2,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# (c) 2014, Jens Depuydt <http://www.jensd.be>
|
||||
#
|
||||
# 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/>.
|
||||
# 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'],
|
||||
'supported_by': 'community'}
|
||||
@@ -151,6 +142,7 @@ EXAMPLES = '''
|
||||
state: absent
|
||||
fail_on_drop: no
|
||||
'''
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import psycopg2
|
||||
@@ -159,6 +151,10 @@ except ImportError:
|
||||
else:
|
||||
postgresqldb_found = True
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
def lang_exists(cursor, lang):
|
||||
"""Checks if language exists for db"""
|
||||
query = "SELECT lanname FROM pg_language WHERE lanname='%s'" % lang
|
||||
@@ -220,7 +216,6 @@ def main():
|
||||
)
|
||||
|
||||
db = module.params["db"]
|
||||
port = module.params["port"]
|
||||
lang = module.params["lang"]
|
||||
state = module.params["state"]
|
||||
trust = module.params["trust"]
|
||||
@@ -243,12 +238,10 @@ def main():
|
||||
try:
|
||||
db_connection = psycopg2.connect(**kw)
|
||||
cursor = db_connection.cursor()
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="unable to connect to database: %s" % e)
|
||||
except Exception as e:
|
||||
module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())
|
||||
changed = False
|
||||
lang_dropped = False
|
||||
kw = dict(db=db,lang=lang,trust=trust)
|
||||
kw = {'db': db, 'lang': lang, 'trust': trust}
|
||||
|
||||
if state == "present":
|
||||
if lang_exists(cursor, lang):
|
||||
@@ -287,9 +280,6 @@ def main():
|
||||
kw['changed'] = changed
|
||||
module.exit_json(**kw)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
|
||||
if __name__ == '__main__':
|
||||
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': ['stableinterface'],
|
||||
|
||||
@@ -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'],
|
||||
@@ -104,6 +95,8 @@ schema:
|
||||
sample: "acme"
|
||||
'''
|
||||
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import psycopg2
|
||||
import psycopg2.extras
|
||||
@@ -112,10 +105,11 @@ except ImportError:
|
||||
else:
|
||||
postgresqldb_found = True
|
||||
|
||||
import traceback
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.database import SQLParseError, pg_quote_identifier
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
class NotSupportedError(Exception):
|
||||
pass
|
||||
|
||||
@@ -235,8 +229,7 @@ def main():
|
||||
.ISOLATION_LEVEL_AUTOCOMMIT)
|
||||
cursor = db_connection.cursor(
|
||||
cursor_factory=psycopg2.extras.DictCursor)
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
except Exception as e:
|
||||
module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())
|
||||
|
||||
try:
|
||||
@@ -250,31 +243,24 @@ def main():
|
||||
if state == "absent":
|
||||
try:
|
||||
changed = schema_delete(cursor, schema)
|
||||
except SQLParseError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except SQLParseError as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
elif state == "present":
|
||||
try:
|
||||
changed = schema_create(cursor, schema, owner)
|
||||
except SQLParseError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except NotSupportedError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except SQLParseError as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
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()
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Database query failed: %s" % to_native(e), exception=traceback.format_exc())
|
||||
|
||||
module.exit_json(changed=changed, schema=schema)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.database import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -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': ['stableinterface'],
|
||||
@@ -209,13 +200,10 @@ EXAMPLES = '''
|
||||
|
||||
import itertools
|
||||
import re
|
||||
import traceback
|
||||
from distutils.version import StrictVersion
|
||||
from hashlib import md5
|
||||
|
||||
from ansible.module_utils.basic import get_exception, AnsibleModule
|
||||
from ansible.module_utils.database import pg_quote_identifier, SQLParseError
|
||||
|
||||
|
||||
try:
|
||||
import psycopg2
|
||||
import psycopg2.extras
|
||||
@@ -224,9 +212,12 @@ except ImportError:
|
||||
else:
|
||||
postgresqldb_found = True
|
||||
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.database import pg_quote_identifier, SQLParseError
|
||||
from ansible.module_utils._text import to_bytes, to_native
|
||||
from ansible.module_utils.six import iteritems
|
||||
|
||||
|
||||
FLAGS = ('SUPERUSER', 'CREATEROLE', 'CREATEUSER', 'CREATEDB', 'INHERIT', 'LOGIN', 'REPLICATION')
|
||||
FLAGS_BY_VERSION = {'BYPASSRLS': '9.5.0'}
|
||||
|
||||
@@ -378,13 +369,12 @@ def user_alter(db_connection, module, user, password, role_attr_flags, encrypted
|
||||
try:
|
||||
cursor.execute(' '.join(alter), query_password_data)
|
||||
changed = True
|
||||
except psycopg2.InternalError:
|
||||
e = get_exception()
|
||||
except psycopg2.InternalError as e:
|
||||
if e.pgcode == '25006':
|
||||
# Handle errors due to read-only transactions indicated by pgcode 25006
|
||||
# ERROR: cannot execute ALTER ROLE in a read-only transaction
|
||||
changed = False
|
||||
module.fail_json(msg=e.pgerror)
|
||||
module.fail_json(msg=e.pgerror, exception=traceback.format_exc())
|
||||
return changed
|
||||
else:
|
||||
raise psycopg2.InternalError(e)
|
||||
@@ -420,13 +410,12 @@ def user_alter(db_connection, module, user, password, role_attr_flags, encrypted
|
||||
|
||||
try:
|
||||
cursor.execute(' '.join(alter))
|
||||
except psycopg2.InternalError:
|
||||
e = get_exception()
|
||||
except psycopg2.InternalError as e:
|
||||
if e.pgcode == '25006':
|
||||
# Handle errors due to read-only transactions indicated by pgcode 25006
|
||||
# ERROR: cannot execute ALTER ROLE in a read-only transaction
|
||||
changed = False
|
||||
module.fail_json(msg=e.pgerror)
|
||||
module.fail_json(msg=e.pgerror, exception=traceback.format_exc())
|
||||
return changed
|
||||
else:
|
||||
raise psycopg2.InternalError(e)
|
||||
@@ -794,22 +783,19 @@ def main():
|
||||
cursor = db_connection.cursor(
|
||||
cursor_factory=psycopg2.extras.DictCursor)
|
||||
|
||||
except TypeError:
|
||||
e = get_exception()
|
||||
except TypeError as e:
|
||||
if 'sslrootcert' in e.args[0]:
|
||||
module.fail_json(
|
||||
msg='Postgresql server must be at least version 8.4 to support sslrootcert')
|
||||
module.fail_json(msg="unable to connect to database: %s" % e)
|
||||
module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())
|
||||
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="unable to connect to database: %s" % e)
|
||||
except Exception as e:
|
||||
module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())
|
||||
|
||||
try:
|
||||
role_attr_flags = parse_role_attrs(cursor, module.params["role_attr_flags"])
|
||||
except InvalidFlagsError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except InvalidFlagsError as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
kw = dict(user=user)
|
||||
changed = False
|
||||
@@ -820,21 +806,18 @@ def main():
|
||||
try:
|
||||
changed = user_alter(db_connection, module, user, password,
|
||||
role_attr_flags, encrypted, expires, no_password_changes)
|
||||
except SQLParseError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except SQLParseError as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
else:
|
||||
try:
|
||||
changed = user_add(cursor, user, password,
|
||||
role_attr_flags, encrypted, expires)
|
||||
except SQLParseError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except SQLParseError as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
try:
|
||||
changed = grant_privileges(cursor, user, privs) or changed
|
||||
except SQLParseError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except SQLParseError as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
else:
|
||||
if user_exists(cursor, user):
|
||||
if module.check_mode:
|
||||
@@ -844,9 +827,8 @@ def main():
|
||||
try:
|
||||
changed = revoke_privileges(cursor, user, privs)
|
||||
user_removed = user_delete(cursor, user)
|
||||
except SQLParseError:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=str(e))
|
||||
except SQLParseError as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
changed = changed or user_removed
|
||||
if fail_on_user and not user_removed:
|
||||
msg = "unable to remove user"
|
||||
|
||||
@@ -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})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user