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:
Toshio Kuratomi 2017-07-29 14:14:16 -07:00
parent 0c7602fb59
commit 0b9a78f0b3
110 changed files with 1094 additions and 2224 deletions

View file

@ -1,21 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# (c) 2016, Kamil Szczygiel <kamil.szczygiel () intel.com> # (c) 2016, Kamil Szczygiel <kamil.szczygiel () intel.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -100,6 +90,8 @@ try:
except ImportError: except ImportError:
HAS_INFLUXDB = False HAS_INFLUXDB = False
from ansible.module_utils.basic import AnsibleModule
def influxdb_argument_spec(): def influxdb_argument_spec():
return dict( return dict(
@ -193,7 +185,6 @@ def main():
else: else:
module.exit_json(changed=False) module.exit_json(changed=False)
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,21 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# (c) 2016, Kamil Szczygiel <kamil.szczygiel () intel.com> # (c) 2016, Kamil Szczygiel <kamil.szczygiel () intel.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -115,6 +105,7 @@ RETURN = '''
''' '''
import re import re
try: try:
import requests.exceptions import requests.exceptions
from influxdb import InfluxDBClient from influxdb import InfluxDBClient
@ -123,6 +114,8 @@ try:
except ImportError: except ImportError:
HAS_INFLUXDB = False HAS_INFLUXDB = False
from ansible.module_utils.basic import AnsibleModule
def influxdb_argument_spec(): def influxdb_argument_spec():
return dict( return dict(
@ -238,7 +231,6 @@ def main():
else: else:
create_retention_policy(module, client) create_retention_policy(module, client)
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,22 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Ansible module to manage elasticsearch plugins
# (c) 2015, Mathew Davies <thepixeldeveloper@googlemail.com> # (c) 2015, Mathew Davies <thepixeldeveloper@googlemail.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -102,11 +92,15 @@ EXAMPLES = '''
import os import os
from ansible.module_utils.basic import AnsibleModule
PACKAGE_STATE_MAP = dict( PACKAGE_STATE_MAP = dict(
present="install", present="install",
absent="remove" absent="remove"
) )
def parse_plugin_repo(string): def parse_plugin_repo(string):
elements = string.split("/") 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) 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__': if __name__ == '__main__':
main() main()

View file

@ -1,23 +1,14 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Ansible module to manage elasticsearch shield role
# (c) 2016, Thierno IB. BARRY @barryib # (c) 2016, Thierno IB. BARRY @barryib
# Sponsored by Polyconseil http://polyconseil.fr. # Sponsored by Polyconseil http://polyconseil.fr.
# #
# This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -129,11 +120,15 @@ state:
import os import os
from ansible.module_utils.basic import AnsibleModule
PACKAGE_STATE_MAP = dict( PACKAGE_STATE_MAP = dict(
present="--install", present="--install",
absent="--remove" absent="--remove"
) )
def parse_plugin_repo(string): def parse_plugin_repo(string):
elements = string.split("/") 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) 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__': if __name__ == '__main__':
main() main()

View file

@ -1,20 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -141,6 +133,7 @@ EXAMPLES = '''
name: lua-time-limit name: lua-time-limit
value: 100 value: 100
''' '''
import traceback
try: try:
import redis import redis
@ -149,6 +142,9 @@ except ImportError:
else: else:
redis_found = True redis_found = True
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
# =========================================== # ===========================================
# Redis module specific support methods. # Redis module specific support methods.
@ -231,9 +227,9 @@ def main():
password=login_password) password=login_password)
try: try:
r.ping() r.ping()
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="unable to connect to database: %s" % to_native(e),
module.fail_json(msg="unable to connect to database: %s" % e) exception=traceback.format_exc())
#Check if we are already in the mode that we want #Check if we are already in the mode that we want
info = r.info() info = r.info()
@ -291,9 +287,9 @@ def main():
db=db) db=db)
try: try:
r.ping() r.ping()
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="unable to connect to database: %s" % to_native(e),
module.fail_json(msg="unable to connect to database: %s" % e) exception=traceback.format_exc())
# Do the stuff # Do the stuff
# (Check Check_mode before commands so the commands aren't evaluated # (Check Check_mode before commands so the commands aren't evaluated
@ -319,16 +315,16 @@ def main():
try: try:
r.ping() r.ping()
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="unable to connect to database: %s" % to_native(e),
module.fail_json(msg="unable to connect to database: %s" % e) exception=traceback.format_exc())
try: try:
old_value = r.config_get(name)[name] old_value = r.config_get(name)[name]
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="unable to read config: %s" % to_native(e),
module.fail_json(msg="unable to read config: %s" % e) exception=traceback.format_exc())
changed = old_value != value changed = old_value != value
if module.check_mode or not changed: if module.check_mode or not changed:
@ -336,16 +332,13 @@ def main():
else: else:
try: try:
r.config_set(name, value) r.config_set(name, value)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="unable to write config: %s" % to_native(e),
module.fail_json(msg="unable to write config: %s" % e) exception=traceback.format_exc())
module.exit_json(changed=changed, name=name, value=value) module.exit_json(changed=changed, name=name, value=value)
else: else:
module.fail_json(msg='A valid command must be provided') 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__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2013, James Martin <jmartin@basho.com>, Drew Kerrigan <dkerrigan@basho.com> # (c) 2013, James Martin <jmartin@basho.com>, Drew Kerrigan <dkerrigan@basho.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
'supported_by': 'community'} 'supported_by': 'community'}
@ -97,18 +87,11 @@ EXAMPLES = '''
wait_for_service: kv wait_for_service: kv
''' '''
import json
import time import time
import socket
import sys
try: from ansible.module_utils.basic import AnsibleModule
import json from ansible.module_utils.urls import fetch_url
except ImportError:
try:
import simplejson as json
except ImportError:
# Let snippet from module_utils/basic.py return a proper error in this case
pass
def ring_check(module, riak_admin_bin): def ring_check(module, riak_admin_bin):
@ -137,13 +120,11 @@ def main():
command = module.params.get('command') command = module.params.get('command')
config_dir = module.params.get('config_dir')
http_conn = module.params.get('http_conn') http_conn = module.params.get('http_conn')
target_node = module.params.get('target_node') target_node = module.params.get('target_node')
wait_for_handoffs = module.params.get('wait_for_handoffs') wait_for_handoffs = module.params.get('wait_for_handoffs')
wait_for_ring = module.params.get('wait_for_ring') wait_for_ring = module.params.get('wait_for_ring')
wait_for_service = module.params.get('wait_for_service') wait_for_service = module.params.get('wait_for_service')
validate_certs = module.params.get('validate_certs')
#make sure riak commands are on the path #make sure riak commands are on the path
@ -255,8 +236,6 @@ def main():
module.exit_json(**result) module.exit_json(**result)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,26 +1,15 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" # (c) 2016, Loic Blot <loic.blot@unix-experience.fr>
(c) 2016, Loic Blot <loic.blot@unix-experience.fr> # Sponsored by Infopro Digital. http://www.infopro-digital.com/
Sponsored by Infopro Digital. http://www.infopro-digital.com/ # Sponsored by E.T.A.I. http://www.etai.fr/
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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -115,6 +104,7 @@ after:
''' '''
import os import os
import traceback
try: try:
from pymongo.errors import ConnectionFailure from pymongo.errors import ConnectionFailure
@ -132,8 +122,8 @@ else:
pymongo_found = True pymongo_found = True
from ansible.module_utils.basic import AnsibleModule 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.six.moves import configparser
from ansible.module_utils._text import to_native
# ========================================= # =========================================
@ -197,7 +187,6 @@ def main():
if param_type == 'int': if param_type == 'int':
value = int(value) value = int(value)
except ValueError: except ValueError:
e = get_exception()
module.fail_json(msg="value '%s' is not %s" % (value, param_type)) module.fail_json(msg="value '%s' is not %s" % (value, param_type))
try: try:
@ -217,17 +206,15 @@ def main():
if login_user is not None and login_password is not None: if login_user is not None and login_password is not None:
client.admin.authenticate(login_user, login_password, source=login_database) client.admin.authenticate(login_user, login_password, source=login_database)
except ConnectionFailure: except ConnectionFailure as e:
e = get_exception() module.fail_json(msg='unable to connect to database: %s' % to_native(e), exception=traceback.format_exc())
module.fail_json(msg='unable to connect to database: %s' % str(e))
db = client.admin db = client.admin
try: try:
after_value = db.command("setParameter", **{param: value}) after_value = db.command("setParameter", **{param: value})
except OperationFailure: except OperationFailure as e:
e = get_exception() module.fail_json(msg="unable to change parameter: %s" % to_native(e), exception=traceback.format_exc())
module.fail_json(msg="unable to change parameter: %s" % str(e))
if "was" not in after_value: if "was" not in after_value:
module.exit_json(changed=True, msg="Unable to determine old value, assume it changed.") module.exit_json(changed=True, msg="Unable to determine old value, assume it changed.")

View file

@ -4,20 +4,11 @@
# Sponsored by Four Kitchens http://fourkitchens.com. # Sponsored by Four Kitchens http://fourkitchens.com.
# (c) 2014, Epic Games, Inc. # (c) 2014, Epic Games, Inc.
# #
# This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -390,7 +381,6 @@ def main():
user = module.params['name'] user = module.params['name']
password = module.params['password'] password = module.params['password']
ssl = module.params['ssl'] ssl = module.params['ssl']
ssl_cert_reqs = None
roles = module.params['roles'] or [] roles = module.params['roles'] or []
state = module.params['state'] state = module.params['state']
update_password = module.params['update_password'] update_password = module.params['update_password']

View file

@ -1,24 +1,13 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Ansible module to manage mssql databases
# (c) 2014, Vedit Firat Arig <firatarig@gmail.com> # (c) 2014, Vedit Firat Arig <firatarig@gmail.com>
# Outline and parts are reused from Mark Theunissen's mysql_db module # Outline and parts are reused from Mark Theunissen's mysql_db module
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -107,6 +96,7 @@ RETURN = '''
''' '''
import os import os
try: try:
import pymssql import pymssql
except ImportError: except ImportError:
@ -114,6 +104,8 @@ except ImportError:
else: else:
mssql_found = True mssql_found = True
from ansible.module_utils.basic import AnsibleModule
def db_exists(conn, cursor, db): def db_exists(conn, cursor, db):
cursor.execute("SELECT name FROM master.sys.databases WHERE name = %s", 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) module.exit_json(changed=changed, db=db)
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -3,21 +3,11 @@
# (c) 2012, Mark Theunissen <mark.theunissen@gmail.com> # (c) 2012, Mark Theunissen <mark.theunissen@gmail.com>
# Sponsored by Four Kitchens http://fourkitchens.com. # Sponsored by Four Kitchens http://fourkitchens.com.
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -114,8 +104,8 @@ EXAMPLES = '''
import os import os
import pipes import pipes
import stat
import subprocess import subprocess
import traceback
try: try:
import MySQLdb import MySQLdb
@ -124,6 +114,12 @@ except ImportError:
else: else:
mysqldb_found = True 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. # MySQL module specific support methods.
# #
@ -316,13 +312,12 @@ def main():
try: try:
cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca, cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca,
connect_timeout=connect_timeout) connect_timeout=connect_timeout)
except Exception: except Exception as e:
e = get_exception()
if os.path.exists(config_file): 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. " 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: 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 changed = False
if not os.path.exists(config_file): if not os.path.exists(config_file):
@ -334,9 +329,8 @@ def main():
else: else:
try: try:
changed = db_delete(cursor, db) changed = db_delete(cursor, db)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="error deleting database: %s" % to_native(e))
module.fail_json(msg="error deleting database: " + str(e))
module.exit_json(changed=changed, db=db) module.exit_json(changed=changed, db=db)
elif state == "dump": elif state == "dump":
@ -378,9 +372,9 @@ def main():
else: else:
try: try:
changed = db_create(cursor, db, encoding, collation) changed = db_create(cursor, db, encoding, collation)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="error creating database: %s" % to_native(e),
module.fail_json(msg="error creating database: " + str(e)) exception=traceback.format_exc())
module.exit_json(changed=changed, db=db) module.exit_json(changed=changed, db=db)
elif state == "import": elif state == "import":
@ -397,9 +391,9 @@ def main():
module.fail_json(msg="%s" % stderr) module.fail_json(msg="%s" % stderr)
else: else:
module.exit_json(changed=True, db=db, msg=stdout) module.exit_json(changed=True, db=db, msg=stdout)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="error creating database: %s" % to_native(e),
module.fail_json(msg="error creating database: " + str(e)) exception=traceback.format_exc())
elif state == "absent": elif state == "absent":
if module.check_mode: if module.check_mode:
@ -411,9 +405,6 @@ def main():
module.exit_json(changed=False, db=db) module.exit_json(changed=False, db=db)
module.fail_json(msg="Cannot dump database %s - not found" % (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__': if __name__ == '__main__':
main() main()

View file

@ -1,26 +1,14 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- 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 from __future__ import absolute_import, division, print_function
(c) 2013, Balazs Pocze <banyek@gawker.com> __metaclass__ = type
Certain parts are taken from Mark Theunissen's mysqldb 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/>.
"""
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -142,7 +130,7 @@ else:
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.mysql import mysql_connect 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): def get_master_status(cursor):
@ -265,13 +253,12 @@ def main():
try: try:
cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca, None, 'MySQLdb.cursors.DictCursor', cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca, None, 'MySQLdb.cursors.DictCursor',
connect_timeout=connect_timeout) connect_timeout=connect_timeout)
except Exception: except Exception as e:
e = get_exception()
if os.path.exists(config_file): 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. " 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: 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": if mode in "getmaster":
status = get_master_status(cursor) status = get_master_status(cursor)
@ -341,12 +328,10 @@ def main():
chm.append("MASTER_AUTO_POSITION = 1") chm.append("MASTER_AUTO_POSITION = 1")
try: try:
changemaster(cursor, chm, chm_params) changemaster(cursor, chm, chm_params)
except MySQLdb.Warning: except MySQLdb.Warning as e:
e = get_exception() result['warning'] = to_native(e)
result['warning'] = str(e) except Exception as e:
except Exception: module.fail_json(msg='%s. Query == CHANGE MASTER TO %s' % (to_native(e), chm))
e = get_exception()
module.fail_json(msg='%s. Query == CHANGE MASTER TO %s' % (e, chm))
result['changed'] = True result['changed'] = True
module.exit_json(**result) module.exit_json(**result)
elif mode in "startslave": elif mode in "startslave":

View file

@ -2,21 +2,11 @@
# (c) 2012, Mark Theunissen <mark.theunissen@gmail.com> # (c) 2012, Mark Theunissen <mark.theunissen@gmail.com>
# Sponsored by Four Kitchens http://fourkitchens.com. # Sponsored by Four Kitchens http://fourkitchens.com.
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -214,16 +204,23 @@ EXAMPLES = """
# password=n<_665{vS43y # password=n<_665{vS43y
""" """
import re import re
import string import string
import traceback
try: try:
import MySQLdb import MySQLdb
except ImportError: except ImportError:
mysqldb_found = False mysqldb_found = False
else: else:
mysqldb_found = True 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.six import iteritems
from ansible.module_utils._text import to_native
VALID_PRIVS = frozenset(('CREATE', 'DROP', 'GRANT', 'GRANT OPTION', VALID_PRIVS = frozenset(('CREATE', 'DROP', 'GRANT', 'GRANT OPTION',
'LOCK TABLES', 'REFERENCES', 'EVENT', 'ALTER', 'LOCK TABLES', 'REFERENCES', 'EVENT', 'ALTER',
@ -608,10 +605,9 @@ def main():
if not cursor: if not cursor:
cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca, db, cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca, db,
connect_timeout=connect_timeout) connect_timeout=connect_timeout)
except Exception: except Exception as e:
e = get_exception()
module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. " 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: if not sql_log_bin:
cursor.execute("SET SQL_LOG_BIN=0;") cursor.execute("SET SQL_LOG_BIN=0;")
@ -619,14 +615,12 @@ def main():
if priv is not None: if priv is not None:
try: try:
mode = get_mode(cursor) mode = get_mode(cursor)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
try: try:
priv = privileges_unpack(priv, mode) priv = privileges_unpack(priv, mode)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="invalid privileges string: %s" % to_native(e))
module.fail_json(msg="invalid privileges string: %s" % str(e))
if state == "present": if state == "present":
if user_exists(cursor, user, host, host_all): if user_exists(cursor, user, host, host_all):
@ -636,17 +630,15 @@ def main():
else: else:
changed = user_mod(cursor, user, host, host_all, None, encrypted, priv, append_privs, module) changed = user_mod(cursor, user, host, host_all, None, encrypted, priv, append_privs, module)
except (SQLParseError, InvalidPrivsError, MySQLdb.Error): except (SQLParseError, InvalidPrivsError, MySQLdb.Error) as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
else: else:
if host_all: if host_all:
module.fail_json(msg="host_all parameter cannot be used when adding a user") module.fail_json(msg="host_all parameter cannot be used when adding a user")
try: try:
changed = user_add(cursor, user, host, host_all, password, encrypted, priv, module.check_mode) changed = user_add(cursor, user, host, host_all, password, encrypted, priv, module.check_mode)
except (SQLParseError, InvalidPrivsError, MySQLdb.Error): except (SQLParseError, InvalidPrivsError, MySQLdb.Error) as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
elif state == "absent": elif state == "absent":
if user_exists(cursor, user, host, host_all): if user_exists(cursor, user, host, host_all):
changed = user_delete(cursor, user, host, host_all, module.check_mode) changed = user_delete(cursor, user, host, host_all, module.check_mode)
@ -654,10 +646,6 @@ def main():
changed = False changed = False
module.exit_json(changed=changed, user=user) 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__': if __name__ == '__main__':
main() main()

View file

@ -1,26 +1,14 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- 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 from __future__ import absolute_import, division, print_function
(c) 2013, Balazs Pocze <banyek@gawker.com> __metaclass__ = type
Certain parts are taken from Mark Theunissen's mysqldb 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/>.
"""
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -58,7 +46,7 @@ EXAMPLES = '''
value: 1 value: 1
''' '''
import os
import warnings import warnings
from re import match from re import match
@ -69,6 +57,11 @@ except ImportError:
else: else:
mysqldb_found = True 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): def typedvalue(value):
""" """
@ -118,9 +111,8 @@ def setvariable(cursor, mysqlvar, value):
cursor.execute(query + "%s", (value,)) cursor.execute(query + "%s", (value,))
cursor.fetchall() cursor.fetchall()
result = True result = True
except Exception: except Exception as e:
e = get_exception() result = to_native(e)
result = str(e)
return result return result
@ -164,13 +156,12 @@ def main():
try: try:
cursor = mysql_connect(module, user, password, config_file, ssl_cert, ssl_key, ssl_ca, db, cursor = mysql_connect(module, user, password, config_file, ssl_cert, ssl_key, ssl_ca, db,
connect_timeout=connect_timeout) connect_timeout=connect_timeout)
except Exception: except Exception as e:
e = get_exception()
if os.path.exists(config_file): 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. " 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: 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) mysqlvar_val = getvariable(cursor, mysqlvar)
if mysqlvar_val is None: if mysqlvar_val is None:
@ -185,17 +176,14 @@ def main():
module.exit_json(msg="Variable already set to requested value", changed=False) module.exit_json(msg="Variable already set to requested value", changed=False)
try: try:
result = setvariable(cursor, mysqlvar, value_wanted) result = setvariable(cursor, mysqlvar, value_wanted)
except SQLParseError: except SQLParseError as e:
e = get_exception() result = to_native(e)
result = str(e)
if result is True: if result is True:
module.exit_json(msg="Variable change succeeded prev_value=%s" % value_actual, changed=True) module.exit_json(msg="Variable change succeeded prev_value=%s" % value_actual, changed=True)
else: else:
module.fail_json(msg=result, changed=False) 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__': if __name__ == '__main__':
main() main()

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['stableinterface'], 'status': ['stableinterface'],
@ -120,6 +111,8 @@ EXAMPLES = '''
target_opts: "-n public" target_opts: "-n public"
''' '''
import traceback
HAS_PSYCOPG2 = False HAS_PSYCOPG2 = False
try: try:
import psycopg2 import psycopg2
@ -132,13 +125,12 @@ except ImportError:
pass pass
else: else:
HAS_PSYCOPG2 = True HAS_PSYCOPG2 = True
from ansible.module_utils.six import iteritems
import traceback
import ansible.module_utils.postgres as pgutils 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.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): class NotSupportedError(Exception):
@ -386,7 +378,6 @@ def main():
module.fail_json(msg="the python psycopg2 module is required") module.fail_json(msg="the python psycopg2 module is required")
db = module.params["db"] db = module.params["db"]
port = module.params["port"]
owner = module.params["owner"] owner = module.params["owner"]
template = module.params["template"] template = module.params["template"]
encoding = module.params["encoding"] encoding = module.params["encoding"]
@ -395,7 +386,6 @@ def main():
target = module.params["target"] target = module.params["target"]
target_opts = module.params["target_opts"] target_opts = module.params["target_opts"]
state = module.params["state"] state = module.params["state"]
sslrootcert = module.params["ssl_rootcert"]
changed = False changed = False
# To use defaults values, keyword arguments must be absent, so # 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) db_connection.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
cursor = db_connection.cursor(cursor_factory=psycopg2.extras.DictCursor) cursor = db_connection.cursor(cursor_factory=psycopg2.extras.DictCursor)
except pgutils.LibraryError: except pgutils.LibraryError as e:
e = get_exception() module.fail_json(msg="unable to connect to database: {0}".format(to_native(e)), exception=traceback.format_exc())
module.fail_json(msg="unable to connect to database: {0}".format(str(e)), exception=traceback.format_exc())
except TypeError: except TypeError as e:
e = get_exception()
if 'sslrootcert' in e.args[0]: 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()) 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: except Exception as e:
e = get_exception() module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())
module.fail_json(msg="unable to connect to database: %s" % e, exception=traceback.format_exc())
try: try:
if module.check_mode: if module.check_mode:
@ -461,16 +448,14 @@ def main():
if state == "absent": if state == "absent":
try: try:
changed = db_delete(cursor, db) changed = db_delete(cursor, db)
except SQLParseError: except SQLParseError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
elif state == "present": elif state == "present":
try: try:
changed = db_create(cursor, db, owner, template, encoding, lc_collate, lc_ctype) changed = db_create(cursor, db, owner, template, encoding, lc_collate, lc_ctype)
except SQLParseError: except SQLParseError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
elif state in ("dump", "restore"): elif state in ("dump", "restore"):
method = state == "dump" and db_dump or db_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) module.fail_json(msg=stderr, stdout=stdout, rc=rc, cmd=cmd)
else: else:
module.exit_json(changed=True, msg=stdout, stderr=stderr, rc=rc, cmd=cmd) module.exit_json(changed=True, msg=stdout, stderr=stderr, rc=rc, cmd=cmd)
except SQLParseError: except SQLParseError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
except NotSupportedError: except NotSupportedError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
except SystemExit: except SystemExit:
# Avoid catching this on Python 2.4 # Avoid catching this on Python 2.4
raise raise
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="Database query failed: %s" % to_native(e), exception=traceback.format_exc())
module.fail_json(msg="Database query failed: %s" % e)
module.exit_json(changed=changed, db=db) module.exit_json(changed=changed, db=db)

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -81,6 +72,7 @@ EXAMPLES = '''
name: postgis name: postgis
db: acme db: acme
''' '''
import traceback
try: try:
import psycopg2 import psycopg2
@ -90,6 +82,10 @@ except ImportError:
else: else:
postgresqldb_found = True postgresqldb_found = True
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
class NotSupportedError(Exception): class NotSupportedError(Exception):
pass pass
@ -142,7 +138,6 @@ def main():
db = module.params["db"] db = module.params["db"]
ext = module.params["ext"] ext = module.params["ext"]
port = module.params["port"]
state = module.params["state"] state = module.params["state"]
changed = False changed = False
@ -168,9 +163,8 @@ def main():
.ISOLATION_LEVEL_AUTOCOMMIT) .ISOLATION_LEVEL_AUTOCOMMIT)
cursor = db_connection.cursor( cursor = db_connection.cursor(
cursor_factory=psycopg2.extras.DictCursor) cursor_factory=psycopg2.extras.DictCursor)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())
module.fail_json(msg="unable to connect to database: %s" % e)
try: try:
if module.check_mode: if module.check_mode:
@ -184,18 +178,13 @@ def main():
elif state == "present": elif state == "present":
changed = ext_create(cursor, ext) changed = ext_create(cursor, ext)
except NotSupportedError: except NotSupportedError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e)) except Exception as e:
except Exception: module.fail_json(msg="Database query failed: %s" % to_native(e), exception=traceback.format_exc())
e = get_exception()
module.fail_json(msg="Database query failed: %s" % e)
module.exit_json(changed=changed, db=db, ext=ext) 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__': if __name__ == '__main__':
main() main()

View file

@ -2,21 +2,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# (c) 2014, Jens Depuydt <http://www.jensd.be> # (c) 2014, Jens Depuydt <http://www.jensd.be>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
'supported_by': 'community'} 'supported_by': 'community'}
@ -151,6 +142,7 @@ EXAMPLES = '''
state: absent state: absent
fail_on_drop: no fail_on_drop: no
''' '''
import traceback
try: try:
import psycopg2 import psycopg2
@ -159,6 +151,10 @@ except ImportError:
else: else:
postgresqldb_found = True postgresqldb_found = True
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
def lang_exists(cursor, lang): def lang_exists(cursor, lang):
"""Checks if language exists for db""" """Checks if language exists for db"""
query = "SELECT lanname FROM pg_language WHERE lanname='%s'" % lang query = "SELECT lanname FROM pg_language WHERE lanname='%s'" % lang
@ -220,7 +216,6 @@ def main():
) )
db = module.params["db"] db = module.params["db"]
port = module.params["port"]
lang = module.params["lang"] lang = module.params["lang"]
state = module.params["state"] state = module.params["state"]
trust = module.params["trust"] trust = module.params["trust"]
@ -243,12 +238,10 @@ def main():
try: try:
db_connection = psycopg2.connect(**kw) db_connection = psycopg2.connect(**kw)
cursor = db_connection.cursor() cursor = db_connection.cursor()
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())
module.fail_json(msg="unable to connect to database: %s" % e)
changed = False changed = False
lang_dropped = False kw = {'db': db, 'lang': lang, 'trust': trust}
kw = dict(db=db,lang=lang,trust=trust)
if state == "present": if state == "present":
if lang_exists(cursor, lang): if lang_exists(cursor, lang):
@ -287,9 +280,6 @@ def main():
kw['changed'] = changed kw['changed'] = changed
module.exit_json(**kw) module.exit_json(**kw)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.pycompat24 import get_exception
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,20 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['stableinterface'], 'status': ['stableinterface'],

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -104,6 +95,8 @@ schema:
sample: "acme" sample: "acme"
''' '''
import traceback
try: try:
import psycopg2 import psycopg2
import psycopg2.extras import psycopg2.extras
@ -112,10 +105,11 @@ except ImportError:
else: else:
postgresqldb_found = True 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 from ansible.module_utils._text import to_native
class NotSupportedError(Exception): class NotSupportedError(Exception):
pass pass
@ -235,8 +229,7 @@ def main():
.ISOLATION_LEVEL_AUTOCOMMIT) .ISOLATION_LEVEL_AUTOCOMMIT)
cursor = db_connection.cursor( cursor = db_connection.cursor(
cursor_factory=psycopg2.extras.DictCursor) cursor_factory=psycopg2.extras.DictCursor)
except Exception: except Exception as e:
e = get_exception()
module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc()) module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())
try: try:
@ -250,31 +243,24 @@ def main():
if state == "absent": if state == "absent":
try: try:
changed = schema_delete(cursor, schema) changed = schema_delete(cursor, schema)
except SQLParseError: except SQLParseError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
elif state == "present": elif state == "present":
try: try:
changed = schema_create(cursor, schema, owner) changed = schema_create(cursor, schema, owner)
except SQLParseError: except SQLParseError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e)) except NotSupportedError as e:
except NotSupportedError: module.fail_json(msg=to_native(e), exception=traceback.format_exc())
e = get_exception()
module.fail_json(msg=str(e))
except SystemExit: except SystemExit:
# Avoid catching this on Python 2.4 # Avoid catching this on Python 2.4
raise raise
except Exception: except Exception as e:
e = get_exception()
module.fail_json(msg="Database query failed: %s" % to_native(e), exception=traceback.format_exc()) module.fail_json(msg="Database query failed: %s" % to_native(e), exception=traceback.format_exc())
module.exit_json(changed=changed, schema=schema) 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__': if __name__ == '__main__':
main() main()

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['stableinterface'], 'status': ['stableinterface'],
@ -209,13 +200,10 @@ EXAMPLES = '''
import itertools import itertools
import re import re
import traceback
from distutils.version import StrictVersion from distutils.version import StrictVersion
from hashlib import md5 from hashlib import md5
from ansible.module_utils.basic import get_exception, AnsibleModule
from ansible.module_utils.database import pg_quote_identifier, SQLParseError
try: try:
import psycopg2 import psycopg2
import psycopg2.extras import psycopg2.extras
@ -224,9 +212,12 @@ except ImportError:
else: else:
postgresqldb_found = True 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 from ansible.module_utils.six import iteritems
FLAGS = ('SUPERUSER', 'CREATEROLE', 'CREATEUSER', 'CREATEDB', 'INHERIT', 'LOGIN', 'REPLICATION') FLAGS = ('SUPERUSER', 'CREATEROLE', 'CREATEUSER', 'CREATEDB', 'INHERIT', 'LOGIN', 'REPLICATION')
FLAGS_BY_VERSION = {'BYPASSRLS': '9.5.0'} FLAGS_BY_VERSION = {'BYPASSRLS': '9.5.0'}
@ -378,13 +369,12 @@ def user_alter(db_connection, module, user, password, role_attr_flags, encrypted
try: try:
cursor.execute(' '.join(alter), query_password_data) cursor.execute(' '.join(alter), query_password_data)
changed = True changed = True
except psycopg2.InternalError: except psycopg2.InternalError as e:
e = get_exception()
if e.pgcode == '25006': if e.pgcode == '25006':
# Handle errors due to read-only transactions indicated by pgcode 25006 # Handle errors due to read-only transactions indicated by pgcode 25006
# ERROR: cannot execute ALTER ROLE in a read-only transaction # ERROR: cannot execute ALTER ROLE in a read-only transaction
changed = False changed = False
module.fail_json(msg=e.pgerror) module.fail_json(msg=e.pgerror, exception=traceback.format_exc())
return changed return changed
else: else:
raise psycopg2.InternalError(e) raise psycopg2.InternalError(e)
@ -420,13 +410,12 @@ def user_alter(db_connection, module, user, password, role_attr_flags, encrypted
try: try:
cursor.execute(' '.join(alter)) cursor.execute(' '.join(alter))
except psycopg2.InternalError: except psycopg2.InternalError as e:
e = get_exception()
if e.pgcode == '25006': if e.pgcode == '25006':
# Handle errors due to read-only transactions indicated by pgcode 25006 # Handle errors due to read-only transactions indicated by pgcode 25006
# ERROR: cannot execute ALTER ROLE in a read-only transaction # ERROR: cannot execute ALTER ROLE in a read-only transaction
changed = False changed = False
module.fail_json(msg=e.pgerror) module.fail_json(msg=e.pgerror, exception=traceback.format_exc())
return changed return changed
else: else:
raise psycopg2.InternalError(e) raise psycopg2.InternalError(e)
@ -794,22 +783,19 @@ def main():
cursor = db_connection.cursor( cursor = db_connection.cursor(
cursor_factory=psycopg2.extras.DictCursor) cursor_factory=psycopg2.extras.DictCursor)
except TypeError: except TypeError as e:
e = get_exception()
if 'sslrootcert' in e.args[0]: if 'sslrootcert' in e.args[0]:
module.fail_json( module.fail_json(
msg='Postgresql server must be at least version 8.4 to support sslrootcert') 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: except Exception as e:
e = get_exception() module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())
module.fail_json(msg="unable to connect to database: %s" % e)
try: try:
role_attr_flags = parse_role_attrs(cursor, module.params["role_attr_flags"]) role_attr_flags = parse_role_attrs(cursor, module.params["role_attr_flags"])
except InvalidFlagsError: except InvalidFlagsError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
kw = dict(user=user) kw = dict(user=user)
changed = False changed = False
@ -820,21 +806,18 @@ def main():
try: try:
changed = user_alter(db_connection, module, user, password, changed = user_alter(db_connection, module, user, password,
role_attr_flags, encrypted, expires, no_password_changes) role_attr_flags, encrypted, expires, no_password_changes)
except SQLParseError: except SQLParseError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
else: else:
try: try:
changed = user_add(cursor, user, password, changed = user_add(cursor, user, password,
role_attr_flags, encrypted, expires) role_attr_flags, encrypted, expires)
except SQLParseError: except SQLParseError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
try: try:
changed = grant_privileges(cursor, user, privs) or changed changed = grant_privileges(cursor, user, privs) or changed
except SQLParseError: except SQLParseError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
else: else:
if user_exists(cursor, user): if user_exists(cursor, user):
if module.check_mode: if module.check_mode:
@ -844,9 +827,8 @@ def main():
try: try:
changed = revoke_privileges(cursor, user, privs) changed = revoke_privileges(cursor, user, privs)
user_removed = user_delete(cursor, user) user_removed = user_delete(cursor, user)
except SQLParseError: except SQLParseError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
changed = changed or user_removed changed = changed or user_removed
if fail_on_user and not user_removed: if fail_on_user and not user_removed:
msg = "unable to remove user" msg = "unable to remove user"

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -79,6 +70,7 @@ EXAMPLES = """
- name: updating load_balance_policy - name: updating load_balance_policy
vertica_configuration: name=failovertostandbyafter value='8 hours' vertica_configuration: name=failovertostandbyafter value='8 hours'
""" """
import traceback
try: try:
import pyodbc import pyodbc
@ -88,7 +80,6 @@ else:
pyodbc_found = True pyodbc_found = True
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native
@ -174,9 +165,9 @@ def main():
module.params['login_user'], module.params['login_password'], 'true') module.params['login_user'], module.params['login_password'], 'true')
db_conn = pyodbc.connect(dsn, autocommit=True) db_conn = pyodbc.connect(dsn, autocommit=True)
cursor = db_conn.cursor() cursor = db_conn.cursor()
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="Unable to connect to database: {0}.".format(to_native(e)),
module.fail_json(msg="Unable to connect to database: {0}.".format(e)) exception=traceback.format_exc())
try: try:
configuration_facts = get_configuration_facts(cursor) configuration_facts = get_configuration_facts(cursor)
@ -185,21 +176,17 @@ def main():
else: else:
try: try:
changed = present(configuration_facts, cursor, parameter_name, current_value) changed = present(configuration_facts, cursor, parameter_name, current_value)
except pyodbc.Error: except pyodbc.Error as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e)) except NotSupportedError as e:
except NotSupportedError: module.fail_json(msg=to_native(e), ansible_facts={'vertica_configuration': configuration_facts})
e = get_exception() except CannotDropError as e:
module.fail_json(msg=str(e), ansible_facts={'vertica_configuration': configuration_facts}) module.fail_json(msg=to_native(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 SystemExit: except SystemExit:
# avoid catching this on python 2.4 # avoid catching this on python 2.4
raise raise
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=to_native(e))
module.exit_json(changed=changed, parameter=parameter_name, ansible_facts={'vertica_configuration': configuration_facts}) module.exit_json(changed=changed, parameter=parameter_name, ansible_facts={'vertica_configuration': configuration_facts})

View file

@ -1,20 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -71,6 +63,7 @@ EXAMPLES = """
- name: gathering vertica facts - name: gathering vertica facts
vertica_facts: db=db_name vertica_facts: db=db_name
""" """
import traceback
try: try:
import pyodbc import pyodbc
@ -80,7 +73,6 @@ else:
pyodbc_found = True pyodbc_found = True
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native
@ -255,9 +247,8 @@ def main():
module.params['login_user'], module.params['login_password'], 'true') module.params['login_user'], module.params['login_password'], 'true')
db_conn = pyodbc.connect(dsn, autocommit=True) db_conn = pyodbc.connect(dsn, autocommit=True)
cursor = db_conn.cursor() cursor = db_conn.cursor()
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="Unable to connect to database: %s." % to_native(e), exception=traceback.format_exc())
module.fail_json(msg="Unable to connect to database: %s." % str(e))
try: try:
schema_facts = get_schema_facts(cursor) schema_facts = get_schema_facts(cursor)
@ -271,15 +262,13 @@ def main():
'vertica_roles': role_facts, 'vertica_roles': role_facts,
'vertica_configuration': configuration_facts, 'vertica_configuration': configuration_facts,
'vertica_nodes': node_facts}) 'vertica_nodes': node_facts})
except NotSupportedError: except NotSupportedError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
except SystemExit: except SystemExit:
# avoid catching this on python 2.4 # avoid catching this on python 2.4
raise raise
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=to_native(e))
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -1,20 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -90,6 +82,7 @@ EXAMPLES = """
- name: creating a new vertica role with other role assigned - name: creating a new vertica role with other role assigned
vertica_role: name=role_name assigned_role=other_role_name state=present vertica_role: name=role_name assigned_role=other_role_name state=present
""" """
import traceback
try: try:
import pyodbc import pyodbc
@ -99,7 +92,6 @@ else:
pyodbc_found = True pyodbc_found = True
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native
@ -218,9 +210,8 @@ def main():
module.params['login_user'], module.params['login_password'], 'true') module.params['login_user'], module.params['login_password'], 'true')
db_conn = pyodbc.connect(dsn, autocommit=True) db_conn = pyodbc.connect(dsn, autocommit=True)
cursor = db_conn.cursor() cursor = db_conn.cursor()
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="Unable to connect to database: {0}.".format(to_native(e)))
module.fail_json(msg="Unable to connect to database: {0}.".format(e))
try: try:
role_facts = get_role_facts(cursor) role_facts = get_role_facts(cursor)
@ -229,27 +220,22 @@ def main():
elif state == 'absent': elif state == 'absent':
try: try:
changed = absent(role_facts, cursor, role, assigned_roles) changed = absent(role_facts, cursor, role, assigned_roles)
except pyodbc.Error: except pyodbc.Error as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
elif state == 'present': elif state == 'present':
try: try:
changed = present(role_facts, cursor, role, assigned_roles) changed = present(role_facts, cursor, role, assigned_roles)
except pyodbc.Error: except pyodbc.Error as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e)) except NotSupportedError as e:
except NotSupportedError: module.fail_json(msg=to_native(e), ansible_facts={'vertica_roles': role_facts})
e = get_exception() except CannotDropError as e:
module.fail_json(msg=str(e), ansible_facts={'vertica_roles': role_facts}) module.fail_json(msg=to_native(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 SystemExit: except SystemExit:
# avoid catching this on python 2.4 # avoid catching this on python 2.4
raise raise
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=to_native(e))
module.exit_json(changed=changed, role=role, ansible_facts={'vertica_roles': role_facts}) module.exit_json(changed=changed, role=role, ansible_facts={'vertica_roles': role_facts})

View file

@ -1,20 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -114,6 +106,7 @@ EXAMPLES = """
db=db_name db=db_name
state=present state=present
""" """
import traceback
try: try:
import pyodbc import pyodbc
@ -123,7 +116,6 @@ else:
pyodbc_found = True pyodbc_found = True
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native
@ -293,9 +285,8 @@ def main():
module.params['login_user'], module.params['login_password'], 'true') module.params['login_user'], module.params['login_password'], 'true')
db_conn = pyodbc.connect(dsn, autocommit=True) db_conn = pyodbc.connect(dsn, autocommit=True)
cursor = db_conn.cursor() cursor = db_conn.cursor()
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="Unable to connect to database: {0}.".format(to_native(e)))
module.fail_json(msg="Unable to connect to database: {0}.".format(e))
try: try:
schema_facts = get_schema_facts(cursor) schema_facts = get_schema_facts(cursor)
@ -304,27 +295,22 @@ def main():
elif state == 'absent': elif state == 'absent':
try: try:
changed = absent(schema_facts, cursor, schema, usage_roles, create_roles) changed = absent(schema_facts, cursor, schema, usage_roles, create_roles)
except pyodbc.Error: except pyodbc.Error as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
elif state == 'present': elif state == 'present':
try: try:
changed = present(schema_facts, cursor, schema, usage_roles, create_roles, owner) changed = present(schema_facts, cursor, schema, usage_roles, create_roles, owner)
except pyodbc.Error: except pyodbc.Error as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e)) except NotSupportedError as e:
except NotSupportedError: module.fail_json(msg=to_native(e), ansible_facts={'vertica_schemas': schema_facts})
e = get_exception() except CannotDropError as e:
module.fail_json(msg=str(e), ansible_facts={'vertica_schemas': schema_facts}) module.fail_json(msg=to_native(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 SystemExit: except SystemExit:
# avoid catching this on python 2.4 # avoid catching this on python 2.4
raise raise
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=to_native(e))
module.exit_json(changed=changed, schema=schema, ansible_facts={'vertica_schemas': schema_facts}) module.exit_json(changed=changed, schema=schema, ansible_facts={'vertica_schemas': schema_facts})

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -127,6 +118,7 @@ EXAMPLES = """
roles=schema_name_ro roles=schema_name_ro
state=present state=present
""" """
import traceback
try: try:
import pyodbc import pyodbc
@ -136,7 +128,6 @@ else:
pyodbc_found = True pyodbc_found = True
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native
@ -361,8 +352,7 @@ def main():
module.params['login_user'], module.params['login_password'], 'true') module.params['login_user'], module.params['login_password'], 'true')
db_conn = pyodbc.connect(dsn, autocommit=True) db_conn = pyodbc.connect(dsn, autocommit=True)
cursor = db_conn.cursor() cursor = db_conn.cursor()
except Exception: except Exception as e:
e = get_exception()
module.fail_json(msg="Unable to connect to database: {0}.".format(e)) module.fail_json(msg="Unable to connect to database: {0}.".format(e))
try: try:
@ -373,28 +363,23 @@ def main():
elif state == 'absent': elif state == 'absent':
try: try:
changed = absent(user_facts, cursor, user, roles) changed = absent(user_facts, cursor, user, roles)
except pyodbc.Error: except pyodbc.Error as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
elif state in ['present', 'locked']: elif state in ['present', 'locked']:
try: try:
changed = present(user_facts, cursor, user, profile, resource_pool, changed = present(user_facts, cursor, user, profile, resource_pool,
locked, password, expired, ldap, roles) locked, password, expired, ldap, roles)
except pyodbc.Error: except pyodbc.Error as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e)) except NotSupportedError as e:
except NotSupportedError: module.fail_json(msg=to_native(e), ansible_facts={'vertica_users': user_facts})
e = get_exception() except CannotDropError as e:
module.fail_json(msg=str(e), ansible_facts={'vertica_users': user_facts}) module.fail_json(msg=to_native(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 SystemExit: except SystemExit:
# avoid catching this on python 2.4 # avoid catching this on python 2.4
raise raise
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=to_native(e))
module.exit_json(changed=changed, user=user, ansible_facts={'vertica_users': user_facts}) module.exit_json(changed=changed, user=user, ansible_facts={'vertica_users': user_facts})

View file

@ -1,26 +1,14 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" # (c) 2014, Mischa Peters <mpeters@a10networks.com>,
Ansible module to manage A10 Networks slb server objects # (c) 2016, Eric Chou <ericc@a10networks.com>
(c) 2014, Mischa Peters <mpeters@a10networks.com>, #
2016, Eric Chou <ericc@a10networks.com> # 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -114,13 +102,15 @@ content:
''' '''
import json import json
from ansible.module_utils.a10 import (axapi_call, a10_argument_spec, axapi_authenticate, axapi_failure,
axapi_get_port_protocol, axapi_enabled_disabled, AXAPI_PORT_PROTOCOLS)
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import url_argument_spec from ansible.module_utils.urls import url_argument_spec
from ansible.module_utils.a10 import axapi_call, a10_argument_spec, axapi_authenticate, axapi_failure
from ansible.module_utils.a10 import axapi_get_port_protocol, axapi_enabled_disabled, AXAPI_PORT_PROTOCOLS
VALID_PORT_FIELDS = ['port_num', 'protocol', 'status'] VALID_PORT_FIELDS = ['port_num', 'protocol', 'status']
def validate_ports(module, ports): def validate_ports(module, ports):
for item in ports: for item in ports:
for key in item: for key in item:
@ -209,7 +199,7 @@ def main():
if slb_server_status: if slb_server_status:
json_post['server']['status'] = axapi_enabled_disabled(slb_server_status) json_post['server']['status'] = axapi_enabled_disabled(slb_server_status)
slb_server_partition = axapi_call(module, session_url + '&method=system.partition.active', json.dumps({'name': partition})) axapi_call(module, session_url + '&method=system.partition.active', json.dumps({'name': partition}))
slb_server_data = axapi_call(module, session_url + '&method=slb.server.search', json.dumps({'name': slb_server})) slb_server_data = axapi_call(module, session_url + '&method=slb.server.search', json.dumps({'name': slb_server}))
slb_server_exists = not axapi_failure(slb_server_data) slb_server_exists = not axapi_failure(slb_server_data)
@ -296,5 +286,6 @@ def main():
axapi_call(module, session_url + '&method=session.close') axapi_call(module, session_url + '&method=session.close')
module.exit_json(changed=changed, content=result) module.exit_json(changed=changed, content=result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,25 +1,14 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" # (c) 2014, Mischa Peters <mpeters@a10networks.com>
Ansible module to manage A10 Networks slb server objects # (c) 2016, Eric Chou <ericc@a10networks.com>
(c) 2014, Mischa Peters <mpeters@a10networks.com>, 2016, Eric Chou <ericc@a10networks.com> #
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -102,13 +91,15 @@ EXAMPLES = '''
''' '''
import json import json
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import url_argument_spec
from ansible.module_utils.a10 import axapi_call_v3, a10_argument_spec, axapi_authenticate_v3, axapi_failure from ansible.module_utils.a10 import axapi_call_v3, a10_argument_spec, axapi_authenticate_v3, axapi_failure
from ansible.module_utils.a10 import AXAPI_PORT_PROTOCOLS from ansible.module_utils.a10 import AXAPI_PORT_PROTOCOLS
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import url_argument_spec
VALID_PORT_FIELDS = ['port-number', 'protocol', 'action'] VALID_PORT_FIELDS = ['port-number', 'protocol', 'action']
def validate_ports(module, ports): def validate_ports(module, ports):
for item in ports: for item in ports:
for key in item: for key in item:
@ -251,5 +242,6 @@ def main():
axapi_call_v3(module, axapi_base_url + 'logoff/', method='POST', body='', signature=signature) axapi_call_v3(module, axapi_base_url + 'logoff/', method='POST', body='', signature=signature)
module.exit_json(changed=changed, content=result) module.exit_json(changed=changed, content=result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,26 +1,14 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" # (c) 2014, Mischa Peters <mpeters@a10networks.com>,
Ansible module to manage A10 Networks slb service-group objects # Eric Chou <ericc@a10networks.com>
(c) 2014, Mischa Peters <mpeters@a10networks.com>, #
Eric Chou <ericc@a10networks.com> # 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -124,13 +112,16 @@ content:
''' '''
import json import json
from ansible.module_utils.a10 import (axapi_call, a10_argument_spec, axapi_authenticate, axapi_failure,
axapi_enabled_disabled)
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import url_argument_spec from ansible.module_utils.urls import url_argument_spec
from ansible.module_utils.a10 import axapi_call, a10_argument_spec, axapi_authenticate, axapi_failure, axapi_enabled_disabled
VALID_SERVICE_GROUP_FIELDS = ['name', 'protocol', 'lb_method'] VALID_SERVICE_GROUP_FIELDS = ['name', 'protocol', 'lb_method']
VALID_SERVER_FIELDS = ['server', 'port', 'status'] VALID_SERVER_FIELDS = ['server', 'port', 'status']
def validate_servers(module, servers): def validate_servers(module, servers):
for item in servers: for item in servers:
for key in item: for key in item:
@ -234,7 +225,7 @@ def main():
# first we authenticate to get a session id # first we authenticate to get a session id
session_url = axapi_authenticate(module, axapi_base_url, username, password) session_url = axapi_authenticate(module, axapi_base_url, username, password)
# then we select the active-partition # then we select the active-partition
slb_server_partition = axapi_call(module, session_url + '&method=system.partition.active', json.dumps({'name': partition})) axapi_call(module, session_url + '&method=system.partition.active', json.dumps({'name': partition}))
# then we check to see if the specified group exists # then we check to see if the specified group exists
slb_result = axapi_call(module, session_url + '&method=slb.service_group.search', json.dumps({'name': slb_service_group})) slb_result = axapi_call(module, session_url + '&method=slb.service_group.search', json.dumps({'name': slb_service_group}))
slb_service_group_exist = not axapi_failure(slb_result) slb_service_group_exist = not axapi_failure(slb_result)

View file

@ -1,26 +1,14 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" # (c) 2014, Mischa Peters <mpeters@a10networks.com>,
Ansible module to manage A10 Networks slb virtual server objects # Eric Chou <ericc@a10networks.com>
(c) 2014, Mischa Peters <mpeters@a10networks.com>, #
Eric Chou <ericc@a10networks.com> # 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -113,13 +101,15 @@ content:
''' '''
import json import json
from ansible.module_utils.a10 import (axapi_call, a10_argument_spec, axapi_authenticate, axapi_failure,
axapi_enabled_disabled, axapi_get_vport_protocol, AXAPI_VPORT_PROTOCOLS)
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import url_argument_spec from ansible.module_utils.urls import url_argument_spec
from ansible.module_utils.a10 import axapi_call, a10_argument_spec, axapi_authenticate, axapi_failure
from ansible.module_utils.a10 import axapi_enabled_disabled, axapi_get_vport_protocol, AXAPI_VPORT_PROTOCOLS
VALID_PORT_FIELDS = ['port', 'protocol', 'service_group', 'status'] VALID_PORT_FIELDS = ['port', 'protocol', 'service_group', 'status']
def validate_ports(module, ports): def validate_ports(module, ports):
for item in ports: for item in ports:
for key in item: for key in item:
@ -194,7 +184,7 @@ def main():
axapi_base_url = 'https://%s/services/rest/V2.1/?format=json' % host axapi_base_url = 'https://%s/services/rest/V2.1/?format=json' % host
session_url = axapi_authenticate(module, axapi_base_url, username, password) session_url = axapi_authenticate(module, axapi_base_url, username, password)
slb_server_partition = axapi_call(module, session_url + '&method=system.partition.active', json.dumps({'name': partition})) axapi_call(module, session_url + '&method=system.partition.active', json.dumps({'name': partition}))
slb_virtual_data = axapi_call(module, session_url + '&method=slb.virtual_server.search', json.dumps({'name': slb_virtual})) slb_virtual_data = axapi_call(module, session_url + '&method=slb.virtual_server.search', json.dumps({'name': slb_virtual}))
slb_virtual_exists = not axapi_failure(slb_virtual_data) slb_virtual_exists = not axapi_failure(slb_virtual_data)
@ -287,5 +277,6 @@ def main():
axapi_call(module, session_url + '&method=session.close') axapi_call(module, session_url + '&method=session.close')
module.exit_json(changed=changed, content=result) module.exit_json(changed=changed, content=result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -3,21 +3,11 @@
# Copyright 2017 Dag Wieers <dag@wieers.com> # Copyright 2017 Dag Wieers <dag@wieers.com>
# Copyright 2017 Swetha Chunduri (@schunduri) # Copyright 2017 Swetha Chunduri (@schunduri)
# 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 by Red Hat
#
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -175,7 +165,6 @@ totalCount:
sample: '0' sample: '0'
''' '''
import json
import os import os
# Optional, only used for XML payload # Optional, only used for XML payload
@ -288,5 +277,6 @@ def main():
# Report success # Report success
module.exit_json(**aci.result) module.exit_json(**aci.result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Team
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Team
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -176,16 +167,11 @@ backup_path:
type: string type: string
sample: /playbooks/ansible/backup/aireos_config.2016-07-16@22:28:34 sample: /playbooks/ansible/backup/aireos_config.2016-07-16@22:28:34
""" """
import re
import time
from ansible.module_utils.aireos import run_commands, get_config, load_config, sanitize from ansible.module_utils.aireos import run_commands, get_config, load_config, sanitize
from ansible.module_utils.aireos import aireos_argument_spec from ansible.module_utils.aireos import aireos_argument_spec
from ansible.module_utils.aireos import check_args as aireos_check_args from ansible.module_utils.aireos import check_args as aireos_check_args
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netcli import Conditional
from ansible.module_utils.netcfg import NetworkConfig, dumps from ansible.module_utils.netcfg import NetworkConfig, dumps
from ansible.module_utils.six import iteritems
def get_running_config(module, config=None): def get_running_config(module, config=None):

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Team
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -147,7 +138,6 @@ responses:
type: list type: list
sample: ['...', '...'] sample: ['...', '...']
""" """
import ansible.module_utils.asa
from ansible.module_utils.network import NetworkModule from ansible.module_utils.network import NetworkModule
from ansible.module_utils.netcfg import NetworkConfig, dumps from ansible.module_utils.netcfg import NetworkConfig, dumps
@ -199,12 +189,6 @@ def main():
lines = module.params['lines'] lines = module.params['lines']
before = module.params['before']
after = module.params['after']
match = module.params['match']
replace = module.params['replace']
result = dict(changed=False) result = dict(changed=False)
candidate = NetworkConfig(indent=1) candidate = NetworkConfig(indent=1)

View file

@ -1,20 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -231,13 +222,12 @@ responses:
type: list type: list
sample: ['...', '...'] sample: ['...', '...']
""" """
import re import traceback
import ansible.module_utils.asa
from ansible.module_utils.basic import get_exception
from ansible.module_utils.network import NetworkModule, NetworkError from ansible.module_utils.network import NetworkModule, NetworkError
from ansible.module_utils.netcfg import NetworkConfig, dumps from ansible.module_utils.netcfg import NetworkConfig, dumps
from ansible.module_utils._text import to_native
def get_config(module): def get_config(module):
contents = module.params['config'] contents = module.params['config']
@ -339,11 +329,11 @@ def main():
try: try:
run(module, result) run(module, result)
except NetworkError: except NetworkError as e:
exc = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc(), **e.kwargs)
module.fail_json(msg=str(exc), **exc.kwargs)
module.exit_json(**result) module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,23 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Ansible module to manage Big Cloud Fabric (versions 4.1) switches
# (c) 2017, Ted Elhourani <ted@bigswitch.com> # (c) 2017, Ted Elhourani <ted@bigswitch.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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 = {'status': ['preview'], ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community', 'supported_by': 'community',
@ -86,19 +74,19 @@ EXAMPLES = '''
RETURN = ''' # ''' RETURN = ''' # '''
import os import os
import traceback
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.bigswitch_utils import Rest, Response from ansible.module_utils.bigswitch_utils import Rest
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils._text import to_native
def switch(module, check_mode): def switch(module, check_mode):
try: try:
access_token = module.params['access_token'] or os.environ['BIGSWITCH_ACCESS_TOKEN'] access_token = module.params['access_token'] or os.environ['BIGSWITCH_ACCESS_TOKEN']
except KeyError: except KeyError as e:
e = get_exception() module.fail_json(msg='Unable to load %s' % e.message, exception=traceback.format_exc())
module.fail_json(msg='Unable to load %s' % e.message)
name = module.params['name'] name = module.params['name']
fabric_role = module.params['fabric_role'] fabric_role = module.params['fabric_role']
@ -166,9 +154,9 @@ def main():
try: try:
switch(module, check_mode=module.check_mode) switch(module, check_mode=module.check_mode)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -3,21 +3,11 @@
# Ansible module to manage Big Monitoring Fabric service chains # Ansible module to manage Big Monitoring Fabric service chains
# (c) 2016, Ted Elhourani <ted@bigswitch.com> # (c) 2016, Ted Elhourani <ted@bigswitch.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -72,16 +62,18 @@ EXAMPLES = '''
RETURN = ''' # ''' RETURN = ''' # '''
import os import os
import traceback
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.bigswitch_utils import Rest, Response from ansible.module_utils.bigswitch_utils import Rest
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils._text import to_native
def chain(module): def chain(module):
try: try:
access_token = module.params['access_token'] or os.environ['BIGSWITCH_ACCESS_TOKEN'] access_token = module.params['access_token'] or os.environ['BIGSWITCH_ACCESS_TOKEN']
except KeyError: except KeyError as e:
e = get_exception() module.fail_json(msg='Unable to load %s' % e.message, exception=traceback.format_exc())
module.fail_json(msg='Unable to load %s' % e.message )
name = module.params['name'] name = module.params['name']
state = module.params['state'] state = module.params['state']
@ -136,9 +128,9 @@ def main():
try: try:
chain(module) chain(module)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -3,21 +3,11 @@
# Ansible module to manage Big Monitoring Fabric service chains # Ansible module to manage Big Monitoring Fabric service chains
# (c) 2016, Ted Elhourani <ted@bigswitch.com> # (c) 2016, Ted Elhourani <ted@bigswitch.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -97,18 +87,20 @@ EXAMPLES = '''
RETURN = ''' # ''' RETURN = ''' # '''
import os
import datetime import datetime
import os
import traceback
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.bigswitch_utils import Rest, Response from ansible.module_utils.bigswitch_utils import Rest
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils._text import to_native
def policy(module): def policy(module):
try: try:
access_token = module.params['access_token'] or os.environ['BIGSWITCH_ACCESS_TOKEN'] access_token = module.params['access_token'] or os.environ['BIGSWITCH_ACCESS_TOKEN']
except KeyError: except KeyError as e:
e = get_exception() module.fail_json(msg='Unable to load %s' % e.message, exception=traceback.format_exc())
module.fail_json(msg='Unable to load %s' % e.message)
name = module.params['name'] name = module.params['name']
policy_description = module.params['policy_description'] policy_description = module.params['policy_description']
@ -187,9 +179,8 @@ def main():
try: try:
policy(module) policy(module)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,25 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" # (c) 2013, Nandor Sivok <nandor@gawker.com>
Ansible module to manage Citrix NetScaler entities # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
(c) 2013, Nandor Sivok <nandor@gawker.com>
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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -116,9 +103,14 @@ EXAMPLES = '''
import base64 import base64
import json
import socket import socket
import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils._text import to_native
from ansible.module_utils.urls import fetch_url
class netscaler(object): class netscaler(object):
@ -193,9 +185,8 @@ def main():
rc = 0 rc = 0
try: try:
rc, result = core(module) rc, result = core(module)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
if rc != 0: if rc != 0:
module.fail_json(rc=rc, msg=result) module.fail_json(rc=rc, msg=result)
@ -204,10 +195,5 @@ def main():
module.exit_json(**result) module.exit_json(**result)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
from ansible.module_utils.pycompat24 import get_exception
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,18 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com> # (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['deprecated'], 'status': ['deprecated'],

View file

@ -2,18 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com> # (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['deprecated'], 'status': ['deprecated'],

View file

@ -2,18 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com> # (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['deprecated'], 'status': ['deprecated'],
@ -111,12 +104,9 @@ msg:
''' '''
import re import re
from urlparse import urlparse
# import module snippets
from ansible.module_utils.basic import AnsibleModule, platform from ansible.module_utils.basic import AnsibleModule, platform
# incompatible with ansible 1.4.4 - ubuntu 12.04 version from ansible.module_utils.six.moves.urllib import parse as urlparse
# from ansible.module_utils.urls import *
def check_url(module, url): def check_url(module, url):

View file

@ -2,18 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com> # (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['deprecated'], 'status': ['deprecated'],
@ -210,7 +203,6 @@ msg:
''' '''
import os import os
import platform
import re import re
import tempfile import tempfile

View file

@ -2,18 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com> # (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['deprecated'], 'status': ['deprecated'],
@ -71,6 +64,10 @@ msg:
type: string type: string
sample: "interface bond0 config updated" sample: "interface bond0 config updated"
''' '''
import os
import re
from ansible.module_utils.basic import AnsibleModule
# get list of interface files that are currently "configured". # get list of interface files that are currently "configured".
@ -144,11 +141,5 @@ def main():
module.exit_json(changed=module.changed, msg=module.msg) module.exit_json(changed=module.changed, msg=module.msg)
# import module snippets
from ansible.module_utils.basic import *
# from ansible.module_utils.urls import *
import os
import shutil
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,18 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com> # (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['deprecated'], 'status': ['deprecated'],
@ -107,11 +100,12 @@ msg:
sample: "interface bond0 config updated" sample: "interface bond0 config updated"
''' '''
# import module snippets
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
CL_LICENSE_PATH='/usr/cumulus/bin/cl-license' CL_LICENSE_PATH='/usr/cumulus/bin/cl-license'
def install_license(module): def install_license(module):
# license is not installed, install it # license is not installed, install it
_url = module.params.get('src') _url = module.params.get('src')

View file

@ -2,18 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com> # (c) 2016, Cumulus Networks <ce-ceng@cumulusnetworks.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['deprecated'], 'status': ['deprecated'],
@ -84,6 +77,14 @@ msg:
type: string type: string
sample: "interface bond0 config updated" sample: "interface bond0 config updated"
''' '''
import os
import re
import tempfile
import shutil
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
PORTS_CONF = '/etc/cumulus/ports.conf' PORTS_CONF = '/etc/cumulus/ports.conf'
@ -95,9 +96,8 @@ def hash_existing_ports_conf(module):
try: try:
existing_ports_conf = open(PORTS_CONF).readlines() existing_ports_conf = open(PORTS_CONF).readlines()
except IOError: except IOError as e:
error_msg = get_exception() _msg = "Failed to open %s: %s" % (PORTS_CONF, to_native(e))
_msg = "Failed to open %s: %s" % (PORTS_CONF, error_msg)
module.fail_json(msg=_msg) module.fail_json(msg=_msg)
return # for testing only should return on module.fail_json return # for testing only should return on module.fail_json
@ -155,9 +155,8 @@ def make_copy_of_orig_ports_conf(module):
try: try:
shutil.copyfile(PORTS_CONF, PORTS_CONF + '.orig') shutil.copyfile(PORTS_CONF, PORTS_CONF + '.orig')
except IOError: except IOError as e:
error_msg = get_exception() _msg = "Failed to save the original %s: %s" % (PORTS_CONF, to_native(e))
_msg = "Failed to save the original %s: %s" % (PORTS_CONF, error_msg)
module.fail_json(msg=_msg) module.fail_json(msg=_msg)
return # for testing only return # for testing only
@ -178,10 +177,8 @@ def write_to_ports_conf(module):
temp.write(_str) temp.write(_str)
temp.seek(0) temp.seek(0)
shutil.copyfile(temp.name, PORTS_CONF) shutil.copyfile(temp.name, PORTS_CONF)
except IOError: except IOError as e:
error_msg = get_exception() module.fail_json(msg="Failed to write to %s: %s" % (PORTS_CONF, to_native(e)))
module.fail_json(
msg="Failed to write to %s: %s" % (PORTS_CONF, error_msg))
finally: finally:
temp.close() temp.close()
@ -213,12 +210,5 @@ def main():
module.exit_json(changed=_changed, msg=_msg) module.exit_json(changed=_changed, msg=_msg)
# import module snippets
from ansible.module_utils.basic import *
# from ansible.module_utils.urls import *
import os
import tempfile
import shutil
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,18 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016-2017, Cumulus Networks <ce-ceng@cumulusnetworks.com> # (c) 2016-2017, Cumulus Networks <ce-ceng@cumulusnetworks.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -101,6 +94,8 @@ msg:
sample: "interface bond0 config updated" sample: "interface bond0 config updated"
''' '''
from ansible.module_utils.basic import AnsibleModule
def command_helper(module, command, errmsg=None): def command_helper(module, command, errmsg=None):
"""Run a command, catch any nclu errors""" """Run a command, catch any nclu errors"""
@ -118,7 +113,7 @@ def check_pending(module):
color1 = '\x1b[94m' color1 = '\x1b[94m'
if delimeter1 in pending: if delimeter1 in pending:
pending = pending.split(delimeter1)[0] pending = pending.split(delimeter1)[0]
pending = pending.replace('\x1b[94m', '') pending = pending.replace(color1, '')
return pending.strip() return pending.strip()
@ -193,7 +188,6 @@ def main(testing=False):
elif testing: elif testing:
return {"changed": _changed, "msg": output} return {"changed": _changed, "msg": output}
# import module snippets
from ansible.module_utils.basic import AnsibleModule
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,24 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# #
# (c) 2015 Peter Sprygada, <psprygada@ansible.com> # (c) 2015 Peter Sprygada, <psprygada@ansible.com>
#
# Copyright (c) 2017 Dell Inc. # Copyright (c) 2017 Dell Inc.
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -142,9 +130,9 @@ warnings:
""" """
import time import time
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.dellos10 import run_commands from ansible.module_utils.dellos10 import run_commands
from ansible.module_utils.dellos10 import dellos10_argument_spec, check_args from ansible.module_utils.dellos10 import dellos10_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network_common import ComplexList from ansible.module_utils.network_common import ComplexList
from ansible.module_utils.netcli import Conditional from ansible.module_utils.netcli import Conditional
from ansible.module_utils.six import string_types from ansible.module_utils.six import string_types

View file

@ -1,24 +1,13 @@
#!/usr/bin/python #!/usr/bin/python
# #
# (c) 2015 Peter Sprygada, <psprygada@ansible.com> # (c) 2015 Peter Sprygada, <psprygada@ansible.com>
#
# Copyright (c) 2017 Dell Inc. # Copyright (c) 2017 Dell Inc.
# #
# This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -196,11 +185,11 @@ saved:
""" """
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netcfg import NetworkConfig, dumps
from ansible.module_utils.dellos10 import get_config, get_sublevel_config from ansible.module_utils.dellos10 import get_config, get_sublevel_config
from ansible.module_utils.dellos10 import dellos10_argument_spec, check_args from ansible.module_utils.dellos10 import dellos10_argument_spec, check_args
from ansible.module_utils.dellos10 import load_config, run_commands from ansible.module_utils.dellos10 import load_config, run_commands
from ansible.module_utils.dellos10 import WARNING_PROMPTS_RE from ansible.module_utils.dellos10 import WARNING_PROMPTS_RE
from ansible.module_utils.netcfg import NetworkConfig, dumps
def get_candidate(module): def get_candidate(module):
@ -294,5 +283,6 @@ def main():
module.exit_json(**result) module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,24 +1,13 @@
#!/usr/bin/python #!/usr/bin/python
# #
# (c) 2015 Peter Sprygada, <psprygada@ansible.com> # (c) 2015 Peter Sprygada, <psprygada@ansible.com>
#
# Copyright (c) 2017 Dell Inc. # Copyright (c) 2017 Dell Inc.
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
'supported_by': 'community'} 'supported_by': 'community'}
@ -143,7 +132,6 @@ from ansible.module_utils.dellos10 import run_commands
from ansible.module_utils.dellos10 import dellos10_argument_spec, check_args from ansible.module_utils.dellos10 import dellos10_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems from ansible.module_utils.six import iteritems
from ansible.module_utils.six.moves import zip
class FactsBase(object): class FactsBase(object):
@ -239,8 +227,8 @@ class Hardware(FactsBase):
data = self.responses[1] data = self.responses[1]
match = self.parse_memory(data) match = self.parse_memory(data)
if match: if match:
self.facts['memtotal_mb'] = int(match[0]) / 1024 self.facts['memtotal_mb'] = int(match[0]) // 1024
self.facts['memfree_mb'] = int(match[2]) / 1024 self.facts['memfree_mb'] = int(match[2]) // 1024
def parse_cpu_arch(self, data): def parse_cpu_arch(self, data):
cpu_arch = data.find('./data/system-sw-state/sw-version/cpu-arch') cpu_arch = data.find('./data/system-sw-state/sw-version/cpu-arch')

View file

@ -1,24 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# #
# (c) 2015 Peter Sprygada, <psprygada@ansible.com> # (c) 2015 Peter Sprygada, <psprygada@ansible.com>
#
# Copyright (c) 2016 Dell Inc. # Copyright (c) 2016 Dell Inc.
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -1,24 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# #
# (c) 2015 Peter Sprygada, <psprygada@ansible.com> # (c) 2015 Peter Sprygada, <psprygada@ansible.com>
#
# Copyright (c) 2016 Dell Inc. # Copyright (c) 2016 Dell Inc.
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -195,11 +183,11 @@ saved:
""" """
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netcfg import NetworkConfig, dumps
from ansible.module_utils.dellos6 import get_config, get_sublevel_config, Dellos6NetworkConfig from ansible.module_utils.dellos6 import get_config, get_sublevel_config, Dellos6NetworkConfig
from ansible.module_utils.dellos6 import dellos6_argument_spec, check_args from ansible.module_utils.dellos6 import dellos6_argument_spec, check_args
from ansible.module_utils.dellos6 import load_config, run_commands from ansible.module_utils.dellos6 import load_config, run_commands
from ansible.module_utils.dellos6 import WARNING_PROMPTS_RE from ansible.module_utils.dellos6 import WARNING_PROMPTS_RE
from ansible.module_utils.netcfg import dumps
def get_candidate(module): def get_candidate(module):
@ -288,5 +276,6 @@ def main():
result['updates'] = commands result['updates'] = commands
module.exit_json(**result) module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,24 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# #
# (c) 2015 Peter Sprygada, <psprygada@ansible.com> # (c) 2015 Peter Sprygada, <psprygada@ansible.com>
#
# Copyright (c) 2016 Dell Inc. # Copyright (c) 2016 Dell Inc.
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -122,13 +110,11 @@ ansible_net_neighbors:
""" """
import re import re
import itertools
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.dellos6 import run_commands from ansible.module_utils.dellos6 import run_commands
from ansible.module_utils.dellos6 import dellos6_argument_spec, check_args from ansible.module_utils.dellos6 import dellos6_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems from ansible.module_utils.six import iteritems
from ansible.module_utils.six.moves import zip
class FactsBase(object): class FactsBase(object):
@ -201,8 +187,8 @@ class Hardware(FactsBase):
data = self.responses[0] data = self.responses[0]
match = re.findall('\s(\d+)\s', data) match = re.findall('\s(\d+)\s', data)
if match: if match:
self.facts['memtotal_mb'] = int(match[0]) / 1024 self.facts['memtotal_mb'] = int(match[0]) // 1024
self.facts['memfree_mb'] = int(match[1]) / 1024 self.facts['memfree_mb'] = int(match[1]) // 1024
class Config(FactsBase): class Config(FactsBase):
@ -348,7 +334,7 @@ class Interfaces(FactsBase):
match = re.search('^(\S+)\s+(\S+)\s+(\S+)', en) match = re.search('^(\S+)\s+(\S+)\s+(\S+)', en)
if match: if match:
strval = match.group(3) strval = match.group(3)
return match.group(3) return strval
if flag == 1: if flag == 1:
return "null" return "null"
@ -361,7 +347,7 @@ class Interfaces(FactsBase):
match = re.search('^(\S+)\s+(\S+)\s+(\S+)', en) match = re.search('^(\S+)\s+(\S+)\s+(\S+)', en)
if match: if match:
strval = match.group(2) strval = match.group(2)
return match.group(2) return strval
if flag == 1: if flag == 1:
return "null" return "null"
@ -471,5 +457,6 @@ def main():
module.exit_json(ansible_facts=ansible_facts, warnings=warnings) module.exit_json(ansible_facts=ansible_facts, warnings=warnings)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,24 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# #
# (c) 2015 Peter Sprygada, <psprygada@ansible.com> # (c) 2015 Peter Sprygada, <psprygada@ansible.com>
#
# Copyright (c) 2016 Dell Inc. # Copyright (c) 2016 Dell Inc.
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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 = {'status': ['preview'], ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community', 'supported_by': 'community',

View file

@ -1,24 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# #
# (c) 2015 Peter Sprygada, <psprygada@ansible.com> # (c) 2015 Peter Sprygada, <psprygada@ansible.com>
#
# Copyright (c) 2016 Dell Inc. # Copyright (c) 2016 Dell Inc.
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -202,11 +190,11 @@ saved:
""" """
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netcfg import NetworkConfig, dumps
from ansible.module_utils.dellos9 import get_config, get_sublevel_config from ansible.module_utils.dellos9 import get_config, get_sublevel_config
from ansible.module_utils.dellos9 import dellos9_argument_spec, check_args from ansible.module_utils.dellos9 import dellos9_argument_spec, check_args
from ansible.module_utils.dellos9 import load_config, run_commands from ansible.module_utils.dellos9 import load_config, run_commands
from ansible.module_utils.dellos9 import WARNING_PROMPTS_RE from ansible.module_utils.dellos9 import WARNING_PROMPTS_RE
from ansible.module_utils.netcfg import NetworkConfig, dumps
def get_candidate(module): def get_candidate(module):
@ -301,5 +289,6 @@ def main():
module.exit_json(**result) module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,24 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# #
# (c) 2015 Peter Sprygada, <psprygada@ansible.com> # (c) 2015 Peter Sprygada, <psprygada@ansible.com>
#
# Copyright (c) 2016 Dell Inc. # Copyright (c) 2016 Dell Inc.
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -142,11 +130,10 @@ ansible_net_neighbors:
import re import re
import itertools import itertools
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.dellos9 import run_commands from ansible.module_utils.dellos9 import run_commands
from ansible.module_utils.dellos9 import dellos9_argument_spec, check_args from ansible.module_utils.dellos9 import dellos9_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems from ansible.module_utils.six import iteritems
from ansible.module_utils.six.moves import zip
class FactsBase(object): class FactsBase(object):
@ -230,8 +217,8 @@ class Hardware(FactsBase):
data = self.responses[1] data = self.responses[1]
match = re.findall('\s(\d+)\s', data) match = re.findall('\s(\d+)\s', data)
if match: if match:
self.facts['memtotal_mb'] = int(match[0]) / 1024 self.facts['memtotal_mb'] = int(match[0]) // 1024
self.facts['memfree_mb'] = int(match[2]) / 1024 self.facts['memfree_mb'] = int(match[2]) // 1024
def parse_filesystems(self, data): def parse_filesystems(self, data):
return re.findall(r'\s(\S+):$', data, re.M) return re.findall(r'\s(\S+):$', data, re.M)

View file

@ -2,22 +2,11 @@
# #
# Ansible module to manage configuration on fortios devices # Ansible module to manage configuration on fortios devices
# (c) 2016, Benjamin Jolivot <bjolivot@gmail.com> # (c) 2016, Benjamin Jolivot <bjolivot@gmail.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -83,15 +72,10 @@ change_string:
type: string type: string
""" """
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.fortios import fortios_argument_spec, fortios_required_if from ansible.module_utils.fortios import fortios_argument_spec, fortios_required_if
from ansible.module_utils.fortios import backup from ansible.module_utils.fortios import backup
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
#check for pyFG lib #check for pyFG lib
try: try:
from pyFG import FortiOS, FortiConfig from pyFG import FortiOS, FortiConfig
@ -101,11 +85,13 @@ try:
except: except:
HAS_PYFG=False HAS_PYFG=False
# some blocks don't support update, so remove them # some blocks don't support update, so remove them
NOT_UPDATABLE_CONFIG_OBJECTS=[ NOT_UPDATABLE_CONFIG_OBJECTS=[
"vpn certificate local", "vpn certificate local",
] ]
def main(): def main():
argument_spec = dict( argument_spec = dict(
src = dict(type='str', default=None), src = dict(type='str', default=None),
@ -183,18 +169,16 @@ def main():
if module.check_mode is False and change_string != "": if module.check_mode is False and change_string != "":
try: try:
f.commit(change_string) f.commit(change_string)
except CommandExecutionException: except CommandExecutionException as e:
e = get_exception()
module.fail_json(msg="Unable to execute command, check your args, the error was {0}".format(e.message)) module.fail_json(msg="Unable to execute command, check your args, the error was {0}".format(e.message))
except FailedCommit: except FailedCommit as e:
e = get_exception()
module.fail_json(msg="Unable to commit, check your args, the error was {0}".format(e.message)) module.fail_json(msg="Unable to commit, check your args, the error was {0}".format(e.message))
except ForcedCommit: except ForcedCommit as e:
e = get_exception()
module.fail_json(msg="Failed to force commit, check your args, the error was {0}".format(e.message)) module.fail_json(msg="Failed to force commit, check your args, the error was {0}".format(e.message))
module.exit_json(**result) module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,11 @@
# #
# Ansible module to manage IPv4 policy objects in fortigate devices # Ansible module to manage IPv4 policy objects in fortigate devices
# (c) 2017, Benjamin Jolivot <bjolivot@gmail.com> # (c) 2017, Benjamin Jolivot <bjolivot@gmail.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -181,12 +170,10 @@ msg_error_list:
type: string type: string
""" """
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.fortios import fortios_argument_spec, fortios_required_if from ansible.module_utils.fortios import fortios_argument_spec, fortios_required_if
from ansible.module_utils.fortios import backup, AnsibleFortios from ansible.module_utils.fortios import backup, AnsibleFortios
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
def main(): def main():
argument_spec = dict( argument_spec = dict(
@ -214,7 +201,7 @@ def main():
logtraffic_start = dict(type='bool', default=False), logtraffic_start = dict(type='bool', default=False),
) )
#merge global required_if & argument_spec from module_utils/fortios.py # merge global required_if & argument_spec from module_utils/fortios.py
argument_spec.update(fortios_argument_spec) argument_spec.update(fortios_argument_spec)
ipv4_policy_required_if = [ ipv4_policy_required_if = [
@ -227,40 +214,40 @@ def main():
required_if=fortios_required_if + ipv4_policy_required_if , required_if=fortios_required_if + ipv4_policy_required_if ,
) )
#init forti object # init forti object
fortigate = AnsibleFortios(module) fortigate = AnsibleFortios(module)
#Security policies root path # Security policies root path
config_path = 'firewall policy' config_path = 'firewall policy'
#test params # test params
#NAT related # NAT related
if not module.params['nat']: if not module.params['nat']:
if module.params['poolname']: if module.params['poolname']:
module.fail_json(msg='Poolname param requires NAT to be true.') module.fail_json(msg='Poolname param requires NAT to be true.')
if module.params['fixedport']: if module.params['fixedport']:
module.fail_json(msg='Fixedport param requires NAT to be true.') module.fail_json(msg='Fixedport param requires NAT to be true.')
#log options # log options
if module.params['logtraffic_start']: if module.params['logtraffic_start']:
if not module.params['logtraffic'] == 'all': if not module.params['logtraffic'] == 'all':
module.fail_json(msg='Logtraffic_start param requires logtraffic to be set to "all".') module.fail_json(msg='Logtraffic_start param requires logtraffic to be set to "all".')
#id must be str(int) for pyFG to work # id must be str(int) for pyFG to work
policy_id = str(module.params['id']) policy_id = str(module.params['id'])
#load config # load config
fortigate.load_config(config_path) fortigate.load_config(config_path)
#Absent State # Absent State
if module.params['state'] == 'absent': if module.params['state'] == 'absent':
fortigate.candidate_config[config_path].del_block(policy_id) fortigate.candidate_config[config_path].del_block(policy_id)
#Present state # Present state
elif module.params['state'] == 'present': elif module.params['state'] == 'present':
new_policy = fortigate.get_empty_configuration_block(policy_id, 'edit') new_policy = fortigate.get_empty_configuration_block(policy_id, 'edit')
#src / dest / service / interfaces # src / dest / service / interfaces
new_policy.set_param('srcintf', '"%s"' % (module.params['src_intf'])) new_policy.set_param('srcintf', '"%s"' % (module.params['src_intf']))
new_policy.set_param('dstintf', '"%s"' % (module.params['dst_intf'])) new_policy.set_param('dstintf', '"%s"' % (module.params['dst_intf']))
@ -280,7 +267,7 @@ def main():
# action # action
new_policy.set_param('action', '%s' % (module.params['policy_action'])) new_policy.set_param('action', '%s' % (module.params['policy_action']))
#logging # logging
new_policy.set_param('logtraffic', '%s' % (module.params['logtraffic'])) new_policy.set_param('logtraffic', '%s' % (module.params['logtraffic']))
if module.params['logtraffic'] == 'all': if module.params['logtraffic'] == 'all':
if module.params['logtraffic_start']: if module.params['logtraffic_start']:
@ -291,7 +278,7 @@ def main():
# Schedule # Schedule
new_policy.set_param('schedule', '%s' % (module.params['schedule'])) new_policy.set_param('schedule', '%s' % (module.params['schedule']))
#NAT # NAT
if module.params['nat']: if module.params['nat']:
new_policy.set_param('nat', 'enable') new_policy.set_param('nat', 'enable')
if module.params['fixedport']: if module.params['fixedport']:
@ -300,7 +287,7 @@ def main():
new_policy.set_param('ippool', 'enable') new_policy.set_param('ippool', 'enable')
new_policy.set_param('poolname', '"%s"' % (module.params['poolname'])) new_policy.set_param('poolname', '"%s"' % (module.params['poolname']))
#security profiles: # security profiles:
if module.params['av_profile'] is not None: if module.params['av_profile'] is not None:
new_policy.set_param('av-profile', '"%s"' % (module.params['av_profile'])) new_policy.set_param('av-profile', '"%s"' % (module.params['av_profile']))
if module.params['webfilter_profile'] is not None: if module.params['webfilter_profile'] is not None:
@ -314,12 +301,12 @@ def main():
if module.params['comment'] is not None: if module.params['comment'] is not None:
new_policy.set_param('comment', '"%s"' % (module.params['comment'])) new_policy.set_param('comment', '"%s"' % (module.params['comment']))
#add the new policy to the device # add the new policy to the device
fortigate.add_block(policy_id, new_policy) fortigate.add_block(policy_id, new_policy)
#Apply changes # Apply changes
fortigate.apply_changes() fortigate.apply_changes()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2015, Adam Števko <adam.stevko@gmail.com> # (c) 2015, Adam Števko <adam.stevko@gmail.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -81,6 +70,7 @@ temporary:
type: boolean type: boolean
sample: "True" sample: "True"
''' '''
from ansible.module_utils.basic import AnsibleModule
class Etherstub(object): class Etherstub(object):
@ -176,7 +166,6 @@ def main():
module.exit_json(**result) module.exit_json(**result)
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Adam Števko <adam.stevko@gmail.com> # (c) 2016, Adam Števko <adam.stevko@gmail.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Adam Števko <adam.stevko@gmail.com> # (c) 2016, Adam Števko <adam.stevko@gmail.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Adam Števko <adam.stevko@gmail.com> # (c) 2016, Adam Števko <adam.stevko@gmail.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -3,21 +3,11 @@
# (c) 2015, Adam Števko <adam.stevko@gmail.com> # (c) 2015, Adam Števko <adam.stevko@gmail.com>
# #
# This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -125,6 +115,8 @@ vlan:
import re import re
from ansible.module_utils.basic import AnsibleModule
class VNIC(object): class VNIC(object):
@ -269,7 +261,6 @@ def main():
module.exit_json(**result) module.exit_json(**result)
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Adam Števko <adam.stevko@gmail.com> # (c) 2016, Adam Števko <adam.stevko@gmail.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -181,6 +170,9 @@ dsfield:
import socket import socket
from ansible.module_utils.basic import AnsibleModule
SUPPORTED_TRANSPORTS = ['tcp', 'udp', 'sctp', 'icmp', 'icmpv6'] SUPPORTED_TRANSPORTS = ['tcp', 'udp', 'sctp', 'icmp', 'icmpv6']
SUPPORTED_PRIORITIES = ['low', 'medium', 'high'] SUPPORTED_PRIORITIES = ['low', 'medium', 'high']
@ -518,7 +510,5 @@ def main():
module.exit_json(**result) module.exit_json(**result)
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Adam Števko <adam.stevko@gmail.com> # (c) 2016, Adam Števko <adam.stevko@gmail.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -117,8 +106,10 @@ wait:
''' '''
import socket import socket
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
SUPPORTED_TYPES = ['static', 'addrconf', 'dhcp'] SUPPORTED_TYPES = ['static', 'addrconf', 'dhcp']

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Adam Števko <adam.stevko@gmail.com> # (c) 2016, Adam Števko <adam.stevko@gmail.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2015, Adam Števko <adam.stevko@gmail.com> # (c) 2015, Adam Števko <adam.stevko@gmail.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -82,6 +71,7 @@ temporary:
type: boolean type: boolean
sample: "True" sample: "True"
''' '''
from ansible.module_utils.basic import AnsibleModule
class IPInterface(object): class IPInterface(object):
@ -227,7 +217,6 @@ def main():
module.exit_json(**result) module.exit_json(**result)
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Adam Števko <adam.stevko@gmail.com> # (c) 2016, Adam Števko <adam.stevko@gmail.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -109,6 +98,7 @@ value:
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
SUPPORTED_PROTOCOLS = ['ipv4', 'ipv6'] SUPPORTED_PROTOCOLS = ['ipv4', 'ipv6']

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2015, Adam Števko <adam.stevko@gmail.com> # (c) 2015, Adam Števko <adam.stevko@gmail.com>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -96,6 +85,9 @@ value:
sample: "'1024' or 'never'" sample: "'1024' or 'never'"
''' '''
from ansible.module_utils.basic import AnsibleModule
SUPPORTED_PROTOCOLS = ['ipv4', 'ipv6', 'icmp', 'tcp', 'udp', 'sctp'] SUPPORTED_PROTOCOLS = ['ipv4', 'ipv6', 'icmp', 'tcp', 'udp', 'sctp']
@ -265,7 +257,5 @@ def main():
module.exit_json(**result) module.exit_json(**result)
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc # (c) 2017, Ansible by Red Hat, inc
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible by Red Hat
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc # (c) 2017, Ansible by Red Hat, inc
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible by Red Hat
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc # (c) 2017, Ansible by Red Hat, inc
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible by Red Hat
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc # (c) 2017, Ansible by Red Hat, inc
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible by Red Hat
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -180,5 +169,6 @@ def main():
module.exit_json(**result) module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -132,19 +123,20 @@ failed_conditions:
import time import time
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.iosxr import run_commands from ansible.module_utils.iosxr import run_commands, iosxr_argument_spec, check_args
from ansible.module_utils.network_common import ComplexList
from ansible.module_utils.netcli import Conditional from ansible.module_utils.netcli import Conditional
from ansible.module_utils.network_common import ComplexList
from ansible.module_utils.six import string_types from ansible.module_utils.six import string_types
from ansible.module_utils.iosxr import iosxr_argument_spec, check_args
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native
def to_lines(stdout): def to_lines(stdout):
for item in stdout: for item in stdout:
if isinstance(item, string_types): if isinstance(item, string_types):
item = to_native(item, errors='surrogate_or_strict').split('\n') item = to_native(item, errors='surrogate_or_strict').split('\n')
yield item yield item
def parse_commands(module, warnings): def parse_commands(module, warnings):
command = ComplexList(dict( command = ComplexList(dict(
command=dict(key=True), command=dict(key=True),

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -187,10 +178,11 @@ backup_path:
sample: /playbooks/ansible/backup/iosxr01.2016-07-16@22:28:34 sample: /playbooks/ansible/backup/iosxr01.2016-07-16@22:28:34
""" """
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netcfg import NetworkConfig, dumps
from ansible.module_utils.iosxr import load_config,get_config from ansible.module_utils.iosxr import load_config,get_config
from ansible.module_utils.iosxr import iosxr_argument_spec from ansible.module_utils.iosxr import iosxr_argument_spec
from ansible.module_utils.iosxr import check_args as iosxr_check_args from ansible.module_utils.iosxr import check_args as iosxr_check_args
from ansible.module_utils.netcfg import NetworkConfig, dumps
DEFAULT_COMMIT_COMMENT = 'configured by iosxr_config' DEFAULT_COMMIT_COMMENT = 'configured by iosxr_config'
@ -205,12 +197,14 @@ def check_args(module, warnings):
'match=none instead. This argument will be ' 'match=none instead. This argument will be '
'removed in the future') 'removed in the future')
def get_running_config(module): def get_running_config(module):
contents = module.params['config'] contents = module.params['config']
if not contents: if not contents:
contents = get_config(module) contents = get_config(module)
return NetworkConfig(indent=1, contents=contents) return NetworkConfig(indent=1, contents=contents)
def get_candidate(module): def get_candidate(module):
candidate = NetworkConfig(indent=1) candidate = NetworkConfig(indent=1)
if module.params['src']: if module.params['src']:

View file

@ -1,20 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
'supported_by': 'core'} 'supported_by': 'core'}
@ -122,11 +114,10 @@ ansible_net_neighbors:
""" """
import re import re
from ansible.module_utils.iosxr import run_commands
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.iosxr import iosxr_argument_spec, check_args, run_commands
from ansible.module_utils.six import iteritems from ansible.module_utils.six import iteritems
from ansible.module_utils.six.moves import zip from ansible.module_utils.six.moves import zip
from ansible.module_utils.iosxr import iosxr_argument_spec, check_args
class FactsBase(object): class FactsBase(object):

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc # (c) 2017, Ansible by Red Hat, inc
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible by Red Hat
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -1,20 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc # (c) 2017, Ansible by Red Hat, inc
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible by Red Hat
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -122,13 +111,10 @@ commands:
- username admin secret admin - username admin secret admin
""" """
import re
from functools import partial from functools import partial
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.iosxr import get_config, load_config from ansible.module_utils.iosxr import get_config, load_config
from ansible.module_utils.six import iteritems
from ansible.module_utils.iosxr import iosxr_argument_spec, check_args from ansible.module_utils.iosxr import iosxr_argument_spec, check_args

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc # (c) 2017, Ansible by Red Hat, inc
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible by Red Hat
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc # (c) 2017, Ansible by Red Hat, inc
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible by Red Hat
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc # (c) 2017, Ansible by Red Hat, inc
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible by Red Hat
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc # (c) 2017, Ansible by Red Hat, inc
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible by Red Hat
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc # (c) 2017, Ansible by Red Hat, inc
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible by Red Hat
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -1,21 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# (c) 2016, Leandro Lisboa Penz <lpenz at lpenz.org> # (c) 2016, Leandro Lisboa Penz <lpenz at lpenz.org>
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -157,15 +147,17 @@ server_capabilities:
''' '''
import traceback
import xml.dom.minidom import xml.dom.minidom
try: try:
import ncclient.manager import ncclient.manager
HAS_NCCLIENT = True HAS_NCCLIENT = True
except ImportError: except ImportError:
HAS_NCCLIENT = False HAS_NCCLIENT = False
from ansible.module_utils.basic import AnsibleModule
import logging from ansible.module_utils._text import to_native
def netconf_edit_config(m, xml, commit, retkwargs, datastore): def netconf_edit_config(m, xml, commit, retkwargs, datastore):
@ -225,11 +217,8 @@ def main():
try: try:
xml.dom.minidom.parseString(config_xml) xml.dom.minidom.parseString(config_xml)
except: except Exception as e:
e = get_exception() module.fail_json(msg='error parsing XML: %s' % to_native(e), exception=traceback.format_exc())
module.fail_json(
msg='error parsing XML: ' + str(e)
)
nckwargs = dict( nckwargs = dict(
host=module.params['host'], host=module.params['host'],
@ -247,11 +236,8 @@ def main():
module.fail_json( module.fail_json(
msg='authentication failed while connecting to device' msg='authentication failed while connecting to device'
) )
except: except Exception as e:
e = get_exception() module.fail_json(msg='error connecting to the device: %s' % to_native(e), exception=traceback.format_exc())
module.fail_json(
msg='error connecting to the device: ' + str(e)
)
retkwargs = dict() retkwargs = dict()
retkwargs['server_capabilities'] = list(m.server_capabilities) retkwargs['server_capabilities'] = list(m.server_capabilities)
@ -304,18 +290,13 @@ def main():
) )
if changed and module.params['save']: if changed and module.params['save']:
m.copy_config(source="running", target="startup") m.copy_config(source="running", target="startup")
except: except Exception as e:
e = get_exception() module.fail_json(msg='error editing configuration: %s' % to_native(e), exception=traceback.format_exc())
module.fail_json(
msg='error editing configuration: ' + str(e)
)
finally: finally:
m.close_session() m.close_session()
module.exit_json(changed=changed, **retkwargs) module.exit_json(changed=changed, **retkwargs)
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2017 Citrix Systems # Copyright (c) 2017 Citrix Systems
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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 = {'status': ['preview'], ANSIBLE_METADATA = {'status': ['preview'],
@ -105,9 +93,16 @@ diff:
sample: "{ 'targetlbvserver': 'difference. ours: (str) server1 other: (str) server2' }" sample: "{ 'targetlbvserver': 'difference. ours: (str) server1 other: (str) server2' }"
''' '''
from ansible.module_utils.basic import AnsibleModule
import json import json
try:
from nssrc.com.citrix.netscaler.nitro.resource.config.cs.csaction import csaction
from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception
PYTHON_SDK_IMPORTED = True
except ImportError as e:
PYTHON_SDK_IMPORTED = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netscaler import ( from ansible.module_utils.netscaler import (
ConfigProxy, ConfigProxy,
get_nitro_client, get_nitro_client,
@ -117,13 +112,6 @@ from ansible.module_utils.netscaler import (
get_immutables_intersection get_immutables_intersection
) )
try:
from nssrc.com.citrix.netscaler.nitro.resource.config.cs.csaction import csaction
from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception
PYTHON_SDK_IMPORTED = True
except ImportError as e:
PYTHON_SDK_IMPORTED = False
def action_exists(client, module): def action_exists(client, module):
if csaction.count_filtered(client, 'name:%s' % module.params['name']) > 0: if csaction.count_filtered(client, 'name:%s' % module.params['name']) > 0:

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2017 Citrix Systems # Copyright (c) 2017 Citrix Systems
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -124,15 +113,15 @@ msg:
import copy import copy
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netscaler import get_nitro_client, log, loglines, netscaler_common_arguments
try: try:
from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception
PYTHON_SDK_IMPORTED = True PYTHON_SDK_IMPORTED = True
except ImportError as e: except ImportError as e:
PYTHON_SDK_IMPORTED = False PYTHON_SDK_IMPORTED = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netscaler import get_nitro_client, log, loglines, netscaler_common_arguments
def main(): def main():

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2017 Citrix Systems # Copyright (c) 2017 Citrix Systems
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -147,10 +136,6 @@ diff:
sample: { 'targetlbvserver': 'difference. ours: (str) server1 other: (str) server2' } sample: { 'targetlbvserver': 'difference. ours: (str) server1 other: (str) server2' }
''' '''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netscaler import ConfigProxy, get_nitro_client, netscaler_common_arguments, log, loglines, get_immutables_intersection
try: try:
from nssrc.com.citrix.netscaler.nitro.resource.config.basic.server import server from nssrc.com.citrix.netscaler.nitro.resource.config.basic.server import server
from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception
@ -158,6 +143,9 @@ try:
except ImportError as e: except ImportError as e:
PYTHON_SDK_IMPORTED = False PYTHON_SDK_IMPORTED = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netscaler import ConfigProxy, get_nitro_client, netscaler_common_arguments, log, loglines, get_immutables_intersection
def server_exists(client, module): def server_exists(client, module):
log('Checking if server exists') log('Checking if server exists')

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2017 Citrix Systems # Copyright (c) 2017 Citrix Systems
# # 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
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -413,8 +402,6 @@ diff:
sample: "{ 'clttimeout': 'difference. ours: (float) 10.0 other: (float) 20.0' }" sample: "{ 'clttimeout': 'difference. ours: (float) 10.0 other: (float) 20.0' }"
''' '''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netscaler import (ConfigProxy, get_nitro_client, netscaler_common_arguments, log, loglines, get_immutables_intersection)
import copy import copy
try: try:
@ -426,6 +413,10 @@ try:
except ImportError as e: except ImportError as e:
PYTHON_SDK_IMPORTED = False PYTHON_SDK_IMPORTED = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netscaler import (ConfigProxy, get_nitro_client, netscaler_common_arguments,
log, loglines, get_immutables_intersection)
def service_exists(client, module): def service_exists(client, module):
if service.count_filtered(client, 'name:%s' % module.params['name']) > 0: if service.count_filtered(client, 'name:%s' % module.params['name']) > 0:

View file

@ -2,20 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Nokia # (c) 2017, Nokia
# This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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 = {'status': ['preview'], ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community', 'supported_by': 'community',
@ -373,7 +364,6 @@ entities:
''' '''
import time import time
from ansible.module_utils.basic import AnsibleModule
try: try:
import importlib import importlib
@ -387,6 +377,9 @@ try:
except ImportError: except ImportError:
HAS_BAMBOU = False HAS_BAMBOU = False
from ansible.module_utils.basic import AnsibleModule
SUPPORTED_COMMANDS = ['find', 'change_password', 'wait_for_job', 'get_csp_enterprise'] SUPPORTED_COMMANDS = ['find', 'change_password', 'wait_for_job', 'get_csp_enterprise']
VSPK = None VSPK = None

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -133,12 +124,15 @@ failed_conditions:
type: list type: list
sample: ['...', '...'] sample: ['...', '...']
""" """
import traceback
import ansible.module_utils.openswitch import ansible.module_utils.openswitch
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcli import CommandRunner from ansible.module_utils.netcli import CommandRunner
from ansible.module_utils.netcli import AddCommandError, FailedConditionsError from ansible.module_utils.netcli import AddCommandError, FailedConditionsError
from ansible.module_utils.network import NetworkModule, NetworkError from ansible.module_utils.network import NetworkModule, NetworkError
from ansible.module_utils.six import string_types from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_native
VALID_KEYS = ['command', 'prompt', 'response'] VALID_KEYS = ['command', 'prompt', 'response']
@ -193,7 +187,6 @@ def main():
try: try:
runner.add_command(**cmd) runner.add_command(**cmd)
except AddCommandError: except AddCommandError:
exc = get_exception()
warnings.append('duplicate command detected: %s' % cmd) warnings.append('duplicate command detected: %s' % cmd)
for item in conditionals: for item in conditionals:
@ -205,12 +198,11 @@ def main():
try: try:
runner.run() runner.run()
except FailedConditionsError: except FailedConditionsError as e:
exc = get_exception() module.fail_json(msg=to_native(e), failed_conditions=e.failed_conditions,
module.fail_json(msg=str(exc), failed_conditions=exc.failed_conditions) exception=traceback.format_exc())
except NetworkError: except NetworkError as e:
exc = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(exc))
result = dict(changed=False, stdout=list()) result = dict(changed=False, stdout=list())

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -182,11 +173,12 @@ backup_path:
type: string type: string
sample: /playbooks/ansible/backup/ops_config.2016-07-16@22:28:34 sample: /playbooks/ansible/backup/ops_config.2016-07-16@22:28:34
""" """
import re import traceback
from ansible.module_utils.basic import get_exception
from ansible.module_utils.openswitch import NetworkModule, NetworkError from ansible.module_utils.openswitch import NetworkModule, NetworkError
from ansible.module_utils.netcfg import NetworkConfig, dumps from ansible.module_utils.netcfg import NetworkConfig, dumps
from ansible.module_utils._text import to_native
def check_args(module, warnings): def check_args(module, warnings):
if module.params['force']: if module.params['force']:
@ -304,9 +296,8 @@ def main():
try: try:
run(module, result) run(module, result)
except NetworkError: except NetworkError as e:
exc = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(exc))
module.exit_json(**result) module.exit_json(**result)

View file

@ -1,20 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
'supported_by': 'community'} 'supported_by': 'community'}

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -195,14 +186,14 @@ backup_path:
""" """
import re import re
import time import time
import traceback
from ansible.module_utils.basic import get_exception
from ansible.module_utils.six import iteritems
from ansible.module_utils.ordnance import get_config
from ansible.module_utils.network import NetworkModule, NetworkError from ansible.module_utils.network import NetworkModule, NetworkError
from ansible.module_utils.netcfg import NetworkConfig, dumps from ansible.module_utils.netcfg import NetworkConfig, dumps
from ansible.module_utils.netcli import Command from ansible.module_utils.netcli import Command
from ansible.module_utils.ordnance import get_config
from ansible.module_utils.six import iteritems
from ansible.module_utils._text import to_native
def check_args(module, warnings): def check_args(module, warnings):
@ -369,10 +360,9 @@ def main():
try: try:
run(module, result) run(module, result)
except NetworkError: except NetworkError as e:
exc = get_exception()
module.disconnect() module.disconnect()
module.fail_json(msg=str(exc)) module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.disconnect() module.disconnect()
module.exit_json(**result) module.exit_json(**result)

View file

@ -1,20 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# #
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
'supported_by': 'community'} 'supported_by': 'community'}
@ -101,7 +93,6 @@ ansible_net_interfaces:
returned: when interfaces is configured returned: when interfaces is configured
type: dict type: dict
""" """
import itertools
import re import re
import traceback import traceback
@ -124,6 +115,7 @@ class FactsBase(object):
except: except:
self.failed_commands.append(cmd) self.failed_commands.append(cmd)
class Config(FactsBase): class Config(FactsBase):
def populate(self): def populate(self):

View file

@ -2,25 +2,12 @@
#coding: utf-8 -*- #coding: utf-8 -*-
# (c) 2013, David Stygstra <david.stygstra@gmail.com> # (c) 2013, David Stygstra <david.stygstra@gmail.com>
#
# Portions copyright @ 2015 VMware, Inc. # Portions copyright @ 2015 VMware, Inc.
# # 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
# This module is free software: you can redistribute it and/or modify __metaclass__ = type
# 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.
#
# This software 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 this software. If not, see <http://www.gnu.org/licenses/>.
# pylint: disable=C0111
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -114,7 +101,7 @@ EXAMPLES = '''
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems from ansible.module_utils.six import iteritems
from ansible.module_utils.pycompat24 import get_exception
def _fail_mode_to_str(text): def _fail_mode_to_str(text):
if not text: if not text:
@ -246,10 +233,10 @@ def map_params_to_obj(module):
return obj return obj
# pylint: disable=E0602
def main(): def main():
""" Entry point. """ """ Entry point. """
argument_spec={ argument_spec = {
'bridge': {'required': True}, 'bridge': {'required': True},
'parent': {'default': None}, 'parent': {'default': None},
'vlan': {'default': None, 'type': 'int'}, 'vlan': {'default': None, 'type': 'int'},

View file

@ -1,27 +1,14 @@
#!/usr/bin/python #!/usr/bin/python
# coding: utf-8 -*- # coding: utf-8 -*-
# pylint: disable=C0111
# #
# (c) 2015, Mark Hamilton <mhamilton@vmware.com> # (c) 2015, Mark Hamilton <mhamilton@vmware.com>
#
# Portions copyright @ 2015 VMware, Inc. # Portions copyright @ 2015 VMware, Inc.
# # 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
# This module is free software: you can redistribute it and/or modify __metaclass__ = type
# 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.
#
# This software 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 this software. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -101,6 +88,9 @@ EXAMPLES = '''
col: other_config col: other_config
key: disable-in-band key: disable-in-band
''' '''
import re
from ansible.module_utils.basic import AnsibleModule
def map_obj_to_commands(want, have, module): def map_obj_to_commands(want, have, module):
@ -166,7 +156,6 @@ def map_params_to_obj(module):
return obj return obj
# pylint: disable=E0602
def main(): def main():
""" Entry point for ansible module. """ """ Entry point for ansible module. """
argument_spec = { argument_spec = {
@ -202,13 +191,5 @@ def main():
module.exit_json(**result) module.exit_json(**result)
# pylint: disable=W0614
# pylint: disable=W0401
# pylint: disable=W0622
# import module snippets
from ansible.module_utils.basic import *
import re
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,26 +1,13 @@
#!/usr/bin/python #!/usr/bin/python
#coding: utf-8 -*- #coding: utf-8 -*-
# pylint: disable=C0111
# (c) 2013, David Stygstra <david.stygstra@gmail.com> # (c) 2013, David Stygstra <david.stygstra@gmail.com>
#
# Portions copyright @ 2015 VMware, Inc. # Portions copyright @ 2015 VMware, Inc.
# # 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
# This module is free software: you can redistribute it and/or modify __metaclass__ = type
# 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.
#
# This software 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 this software. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -114,7 +101,7 @@ EXAMPLES = '''
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems from ansible.module_utils.six import iteritems
from ansible.module_utils.pycompat24 import get_exception
def _external_ids_to_dict(text): def _external_ids_to_dict(text):
text = text.strip() text = text.strip()
@ -239,7 +226,6 @@ def map_params_to_obj(module):
return obj return obj
# pylint: disable=E0602
def main(): def main():
""" Entry point. """ """ Entry point. """
argument_spec={ argument_spec={

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc # (c) 2017, Ansible by Red Hat, inc
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible by Red Hat
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc # (c) 2017, Ansible by Red Hat, inc
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible by Red Hat
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

Some files were not shown because too many files have changed in this diff Show more