Debian Codegraph @

ansible_collections/cisco/nxos/plugins/modules/nxos_reboot.py

raw
1 #!/usr/bin/python
2 #
3 # This file is part of Ansible
4 #
5 # Ansible is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Ansible is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
17 #
18 from __future__ import absolute_import, division, print_function
19
20
21 __metaclass__ = type
22
23
24 DOCUMENTATION = """
25 module: nxos_reboot
26 extends_documentation_fragment:
27 - cisco.nxos.nxos
28 short_description: Reboot a network device.
29 description:
30 - Reboot a network device.
31 version_added: 1.0.0
32 author:
33 - Jason Edelman (@jedelman8)
34 - Gabriele Gerbino (@GGabriele)
35 notes:
36 - Tested against NXOSv 7.3.(0)D1(1) on VIRL
37 - Tested against Cisco MDS NX-OS 9.2(1)
38 - The module will fail due to timeout issues, but the reboot will be performed anyway.
39 options:
40 confirm:
41 description:
42 - Safeguard boolean. Set to true if you're sure you want to reboot.
43 required: false
44 default: false
45 type: bool
46 """
47
48 EXAMPLES = """
49 - cisco.nxos.nxos_reboot:
50 confirm: true
51 """
52
53 RETURN = """
54 rebooted:
55 description: Whether the device was instructed to reboot.
56 returned: success
57 type: bool
58 sample: true
59 """
60
61 from ansible.module_utils.basic import AnsibleModule
62
63 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import load_config
64
65
66 def reboot(module):
67 cmds = "terminal dont-ask ; reload"
68 opts = {"ignore_timeout": True}
69 load_config(module, cmds, False, opts)
70
71
72 def main():
73 argument_spec = dict(confirm=dict(default=False, type="bool"))
74
75 module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
76
77 warnings = list()
78 results = dict(changed=False, warnings=warnings)
79
80 if module.params["confirm"]:
81 if not module.check_mode:
82 reboot(module)
83 results["changed"] = True
84
85 module.exit_json(**results)
86
87
88 if __name__ == "__main__":
89 main()