| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Copyright: (c) 2018, Ansible Project |
| 3 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
|
| 5 |
from __future__ import annotations |
| 6 |
|
| 7 |
|
| 8 |
DOCUMENTATION = r""" |
| 9 |
module: reboot |
| 10 |
short_description: Reboot a machine |
| 11 |
notes: |
| 12 |
- E(PATH) is ignored on the remote node when searching for the C(shutdown) command. Use O(search_paths) |
| 13 |
to specify locations to search if the default paths do not work. |
| 14 |
description: |
| 15 |
- Reboot a machine, wait for it to go down, come back up, and respond to commands. |
| 16 |
- For Windows targets, use the M(ansible.windows.win_reboot) module instead. |
| 17 |
version_added: "2.7" |
| 18 |
options: |
| 19 |
pre_reboot_delay: |
| 20 |
description: |
| 21 |
- Seconds to wait before reboot. Passed as a parameter to the reboot command. |
| 22 |
- On Linux, macOS and OpenBSD, this is converted to minutes and rounded down. If less than 60, it will be set to 0. |
| 23 |
- On Solaris and FreeBSD, this will be seconds. |
| 24 |
type: int |
| 25 |
default: 0 |
| 26 |
post_reboot_delay: |
| 27 |
description: |
| 28 |
- Seconds to wait after the reboot command was successful before attempting to validate the system rebooted successfully. |
| 29 |
- This is useful if you want wait for something to settle despite your connection already working. |
| 30 |
type: int |
| 31 |
default: 0 |
| 32 |
reboot_timeout: |
| 33 |
description: |
| 34 |
- Maximum seconds to wait for machine to reboot and respond to a test command. |
| 35 |
- This timeout is evaluated separately for both reboot verification and test command success so the |
| 36 |
maximum execution time for the module is twice this amount. |
| 37 |
type: int |
| 38 |
default: 600 |
| 39 |
connect_timeout: |
| 40 |
description: |
| 41 |
- Maximum seconds to wait for a successful connection to the managed hosts before trying again. |
| 42 |
- If unspecified, the default setting for the underlying connection plugin is used. |
| 43 |
type: int |
| 44 |
test_command: |
| 45 |
description: |
| 46 |
- Command to run on the rebooted host and expect success from to determine the machine is ready for |
| 47 |
further tasks. |
| 48 |
type: str |
| 49 |
default: whoami |
| 50 |
msg: |
| 51 |
description: |
| 52 |
- Message to display to users before reboot. |
| 53 |
type: str |
| 54 |
default: Reboot initiated by Ansible |
| 55 |
|
| 56 |
search_paths: |
| 57 |
description: |
| 58 |
- Paths to search on the remote machine for the C(shutdown) command. |
| 59 |
- I(Only) these paths will be searched for the C(shutdown) command. E(PATH) is ignored in the remote node when searching for the C(shutdown) command. |
| 60 |
type: list |
| 61 |
elements: str |
| 62 |
default: ['/sbin', '/bin', '/usr/sbin', '/usr/bin', '/usr/local/sbin'] |
| 63 |
version_added: '2.8' |
| 64 |
|
| 65 |
boot_time_command: |
| 66 |
description: |
| 67 |
- Command to run that returns a unique string indicating the last time the system was booted. |
| 68 |
- Setting this to a command that has different output each time it is run will cause the task to fail. |
| 69 |
type: str |
| 70 |
default: 'cat /proc/sys/kernel/random/boot_id' |
| 71 |
version_added: '2.10' |
| 72 |
|
| 73 |
reboot_command: |
| 74 |
description: |
| 75 |
- Command to run that reboots the system, including any parameters passed to the command. |
| 76 |
- Can be an absolute path to the command or just the command name. If an absolute path to the |
| 77 |
command is not given, O(search_paths) on the target system will be searched to find the absolute path. |
| 78 |
- This will cause O(pre_reboot_delay), O(post_reboot_delay), and O(msg) to be ignored. |
| 79 |
type: str |
| 80 |
default: '[determined based on target OS]' |
| 81 |
version_added: '2.11' |
| 82 |
extends_documentation_fragment: |
| 83 |
- action_common_attributes |
| 84 |
- action_common_attributes.flow |
| 85 |
attributes: |
| 86 |
action: |
| 87 |
support: full |
| 88 |
async: |
| 89 |
support: none |
| 90 |
bypass_host_loop: |
| 91 |
support: none |
| 92 |
check_mode: |
| 93 |
support: full |
| 94 |
diff_mode: |
| 95 |
support: none |
| 96 |
platform: |
| 97 |
platforms: posix |
| 98 |
seealso: |
| 99 |
- module: ansible.windows.win_reboot |
| 100 |
author: |
| 101 |
- Matt Davis (@nitzmahone) |
| 102 |
- Sam Doran (@samdoran) |
| 103 |
""" |
| 104 |
|
| 105 |
EXAMPLES = r""" |
| 106 |
- name: Unconditionally reboot the machine with all defaults |
| 107 |
ansible.builtin.reboot: |
| 108 |
|
| 109 |
- name: Reboot a slow machine that might have lots of updates to apply |
| 110 |
ansible.builtin.reboot: |
| 111 |
reboot_timeout: 3600 |
| 112 |
|
| 113 |
- name: Reboot a machine with shutdown command in unusual place |
| 114 |
ansible.builtin.reboot: |
| 115 |
search_paths: |
| 116 |
- '/lib/molly-guard' |
| 117 |
|
| 118 |
- name: Reboot machine using a custom reboot command |
| 119 |
ansible.builtin.reboot: |
| 120 |
reboot_command: launchctl reboot userspace |
| 121 |
boot_time_command: uptime | cut -d ' ' -f 5 |
| 122 |
|
| 123 |
- name: Reboot machine and send a message |
| 124 |
ansible.builtin.reboot: |
| 125 |
msg: "Rebooting machine in 5 seconds" |
| 126 |
|
| 127 |
""" |
| 128 |
|
| 129 |
RETURN = r""" |
| 130 |
rebooted: |
| 131 |
description: true if the machine was rebooted |
| 132 |
returned: always |
| 133 |
type: bool |
| 134 |
sample: true |
| 135 |
elapsed: |
| 136 |
description: The number of seconds that elapsed waiting for the system to be rebooted. |
| 137 |
returned: always |
| 138 |
type: int |
| 139 |
sample: 23 |
| 140 |
""" |