Debian Codegraph @

test/support/windows-integration/plugins/modules/win_reboot.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 ANSIBLE_METADATA = {'metadata_version': '1.1',
7 'status': ['stableinterface'],
8 'supported_by': 'core'}
9
10 DOCUMENTATION = r"""
11 ---
12 module: win_reboot
13 short_description: Reboot a windows machine
14 description:
15 - Reboot a Windows machine, wait for it to go down, come back up, and respond to commands.
16 - For non-Windows targets, use the M(reboot) module instead.
17 version_added: '2.1'
18 options:
19 pre_reboot_delay:
20 description:
21 - Seconds to wait before reboot. Passed as a parameter to the reboot command.
22 type: int
23 default: 2
24 aliases: [ pre_reboot_delay_sec ]
25 post_reboot_delay:
26 description:
27 - Seconds to wait after the reboot command was successful before attempting to validate the system rebooted successfully.
28 - This is useful if you want wait for something to settle despite your connection already working.
29 type: int
30 default: 0
31 version_added: '2.4'
32 aliases: [ post_reboot_delay_sec ]
33 shutdown_timeout:
34 description:
35 - Maximum seconds to wait for shutdown to occur.
36 - Increase this timeout for very slow hardware, large update applications, etc.
37 - This option has been removed since Ansible 2.5 as the win_reboot behavior has changed.
38 type: int
39 default: 600
40 aliases: [ shutdown_timeout_sec ]
41 reboot_timeout:
42 description:
43 - Maximum seconds to wait for machine to re-appear on the network and respond to a test command.
44 - This timeout is evaluated separately for both reboot verification and test command success so maximum clock time is actually twice this value.
45 type: int
46 default: 600
47 aliases: [ reboot_timeout_sec ]
48 connect_timeout:
49 description:
50 - Maximum seconds to wait for a single successful TCP connection to the WinRM endpoint before trying again.
51 type: int
52 default: 5
53 aliases: [ connect_timeout_sec ]
54 test_command:
55 description:
56 - Command to expect success for to determine the machine is ready for management.
57 type: str
58 default: whoami
59 msg:
60 description:
61 - Message to display to users.
62 type: str
63 default: Reboot initiated by Ansible
64 boot_time_command:
65 description:
66 - Command to run that returns a unique string indicating the last time the system was booted.
67 - Setting this to a command that has different output each time it is run will cause the task to fail.
68 type: str
69 default: '(Get-WmiObject -ClassName Win32_OperatingSystem).LastBootUpTime'
70 version_added: '2.10'
71 notes:
72 - If a shutdown was already scheduled on the system, C(win_reboot) will abort the scheduled shutdown and enforce its own shutdown.
73 - Beware that when C(win_reboot) returns, the Windows system may not have settled yet and some base services could be in limbo.
74 This can result in unexpected behavior. Check the examples for ways to mitigate this.
75 - The connection user must have the C(SeRemoteShutdownPrivilege) privilege enabled, see
76 U(https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/force-shutdown-from-a-remote-system)
77 for more information.
78 seealso:
79 - module: reboot
80 author:
81 - Matt Davis (@nitzmahone)
82 """
83
84 EXAMPLES = r"""
85 - name: Reboot the machine with all defaults
86 win_reboot:
87
88 - name: Reboot a slow machine that might have lots of updates to apply
89 win_reboot:
90 reboot_timeout: 3600
91
92 # Install a Windows feature and reboot if necessary
93 - name: Install IIS Web-Server
94 win_feature:
95 name: Web-Server
96 register: iis_install
97
98 - name: Reboot when Web-Server feature requires it
99 win_reboot:
100 when: iis_install.reboot_required
101
102 # One way to ensure the system is reliable, is to set WinRM to a delayed startup
103 - name: Ensure WinRM starts when the system has settled and is ready to work reliably
104 win_service:
105 name: WinRM
106 start_mode: delayed
107
108
109 # Additionally, you can add a delay before running the next task
110 - name: Reboot a machine that takes time to settle after being booted
111 win_reboot:
112 post_reboot_delay: 120
113
114 # Or you can make win_reboot validate exactly what you need to work before running the next task
115 - name: Validate that the netlogon service has started, before running the next task
116 win_reboot:
117 test_command: 'exit (Get-Service -Name Netlogon).Status -ne "Running"'
118 """
119
120 RETURN = r"""
121 rebooted:
122 description: True if the machine was rebooted.
123 returned: always
124 type: bool
125 sample: true
126 elapsed:
127 description: The number of seconds that elapsed waiting for the system to be rebooted.
128 returned: always
129 type: float
130 sample: 23.2
131 """