diff options
author | Ivan Bojer <ivanbojer@users.noreply.github.com> | 2017-01-03 08:00:15 -0800 |
---|---|---|
committer | Peter Sprygada <privateip@users.noreply.github.com> | 2017-01-03 11:00:15 -0500 |
commit | 660fab6bea06d13c0b1c8b8684c6b4f164d14c42 (patch) | |
tree | 03fada54a9c18d0e8d506d4c2ad2149bc8fa3fc8 | |
parent | c252ac1a7d1290cc170b190a40b628b959cfa91c (diff) | |
download | ansible-660fab6bea06d13c0b1c8b8684c6b4f164d14c42.tar.gz |
panos_restart (#19245)
* new module
* support latest METADATA requirements
-rwxr-xr-x | lib/ansible/modules/network/panos/panos_restart.py | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/lib/ansible/modules/network/panos/panos_restart.py b/lib/ansible/modules/network/panos/panos_restart.py new file mode 100755 index 0000000000..dd25f9a4ab --- /dev/null +++ b/lib/ansible/modules/network/panos/panos_restart.py @@ -0,0 +1,114 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Ansible module to manage PaloAltoNetworks Firewall +# (c) 2016, techbizdev <techbizdev@paloaltonetworks.com> +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +DOCUMENTATION = ''' +--- +module: panos_restart +short_description: restart a device +description: + - Restart a device +author: "Luigi Mori (@jtschichold), Ivan Bojer (@ivanbojer)" +version_added: "2.3" +requirements: + - pan-python +options: + ip_address: + description: + - IP address (or hostname) of PAN-OS device + required: true + password: + description: + - password for authentication + required: true + username: + description: + - username for authentication + required: false + default: "admin" +''' + +EXAMPLES = ''' +- panos_restart: + ip_address: "192.168.1.1" + username: "admin" + password: "admin" +''' + +RETURN = ''' +status: + description: success status + returned: success + type: string + sample: "okey dokey" +''' + +ANSIBLE_METADATA = {'status': ['preview'], + 'supported_by': 'community', + 'version': '1.0'} + +from ansible.module_utils.basic import AnsibleModule +import sys + +try: + import pan.xapi + HAS_LIB = True +except ImportError: + HAS_LIB = False + +def main(): + argument_spec = dict( + ip_address=dict(), + password=dict(no_log=True), + username=dict(default='admin') + ) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False) + + if not HAS_LIB: + module.fail_json(msg='pan-python required for this module') + + ip_address = module.params["ip_address"] + if not ip_address: + module.fail_json(msg="ip_address should be specified") + password = module.params["password"] + if not password: + module.fail_json(msg="password is required") + username = module.params['username'] + + xapi = pan.xapi.PanXapi( + hostname=ip_address, + api_username=username, + api_password=password + ) + + try: + xapi.op(cmd="<request><restart><system></system></restart></request>") + except Exception: + x = sys.exc_info()[1] + if 'succeeded' in str(x): + module.exit_json(changed=True, msg=str(msg)) + else: + module.fail_json(msg=x) + raise + + module.exit_json(changed=True, msg="okey dokey") + +if __name__ == '__main__': + main() |