community.general/lib/ansible/modules/network/nxos/nxos_reboot.py

94 lines
2.4 KiB
Python
Raw Normal View History

2016-09-03 00:47:22 +00:00
#!/usr/bin/python
#
# 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/>.
#
2017-08-16 03:16:38 +00:00
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'network'}
2016-12-06 10:35:05 +00:00
2016-09-03 00:47:22 +00:00
DOCUMENTATION = '''
---
module: nxos_reboot
extends_documentation_fragment: nxos
2016-09-03 00:47:22 +00:00
version_added: 2.2
short_description: Reboot a network device.
description:
- Reboot a network device.
2016-09-03 00:47:22 +00:00
author:
- Jason Edelman (@jedelman8)
- Gabriele Gerbino (@GGabriele)
notes:
- Tested against NXOSv 7.3.(0)D1(1) on VIRL
2016-09-03 00:47:22 +00:00
- The module will fail due to timeout issues, but the reboot will be
performed anyway.
options:
confirm:
description:
- Safeguard boolean. Set to true if you're sure you want to reboot.
required: false
default: false
type: bool
2016-09-03 00:47:22 +00:00
'''
EXAMPLES = '''
- nxos_reboot:
confirm: true
'''
RETURN = '''
rebooted:
description: Whether the device was instructed to reboot.
returned: success
type: bool
2016-09-03 00:47:22 +00:00
sample: true
'''
from ansible.module_utils.network.nxos.nxos import load_config
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
2016-09-03 00:47:22 +00:00
def reboot(module):
cmds = 'terminal dont-ask ; reload'
opts = {'ignore_timeout': True}
load_config(module, cmds, False, opts)
2016-09-03 00:47:22 +00:00
2016-09-03 00:47:22 +00:00
def main():
argument_spec = dict(
confirm=dict(default=False, type='bool')
)
argument_spec.update(nxos_argument_spec)
2016-09-03 00:47:22 +00:00
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
2016-09-03 00:47:22 +00:00
warnings = list()
check_args(module, warnings)
results = dict(changed=False, warnings=warnings)
2016-09-03 00:47:22 +00:00
if module.params['confirm']:
if not module.check_mode:
reboot(module)
results['changed'] = True
2016-09-03 00:47:22 +00:00
module.exit_json(**results)
2016-09-03 00:47:22 +00:00
if __name__ == '__main__':
main()