| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2017, Ansible Project |
| 5 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
DOCUMENTATION = r''' |
| 8 |
--- |
| 9 |
module: win_wait_for_process |
| 10 |
short_description: Waits for a process to exist or not exist before continuing. |
| 11 |
description: |
| 12 |
- Waiting for a process to start or stop. |
| 13 |
- This is useful when Windows services behave poorly and do not enumerate external dependencies in their manifest. |
| 14 |
options: |
| 15 |
process_name_exact: |
| 16 |
description: |
| 17 |
- The name of the process(es) for which to wait. The name of the process(es) should not include the file extension suffix. |
| 18 |
type: list |
| 19 |
elements: str |
| 20 |
process_name_pattern: |
| 21 |
description: |
| 22 |
- RegEx pattern matching desired process(es). |
| 23 |
type: str |
| 24 |
sleep: |
| 25 |
description: |
| 26 |
- Number of seconds to sleep between checks. |
| 27 |
- Only applies when waiting for a process to start. Waiting for a process to start |
| 28 |
does not have a native non-polling mechanism. Waiting for a stop uses native PowerShell |
| 29 |
and does not require polling. |
| 30 |
type: int |
| 31 |
default: 1 |
| 32 |
process_min_count: |
| 33 |
description: |
| 34 |
- Minimum number of process matching the supplied pattern to satisfy C(present) condition. |
| 35 |
- Only applies to C(present). |
| 36 |
type: int |
| 37 |
default: 1 |
| 38 |
pid: |
| 39 |
description: |
| 40 |
- The PID of the process. |
| 41 |
default: 0 |
| 42 |
type: int |
| 43 |
owner: |
| 44 |
description: |
| 45 |
- The owner of the process. |
| 46 |
- Requires PowerShell version 4.0 or newer. |
| 47 |
type: str |
| 48 |
pre_wait_delay: |
| 49 |
description: |
| 50 |
- Seconds to wait before checking processes. |
| 51 |
type: int |
| 52 |
default: 0 |
| 53 |
post_wait_delay: |
| 54 |
description: |
| 55 |
- Seconds to wait after checking for processes. |
| 56 |
type: int |
| 57 |
default: 0 |
| 58 |
state: |
| 59 |
description: |
| 60 |
- When checking for a running process C(present) will block execution |
| 61 |
until the process exists, or until the timeout has been reached. |
| 62 |
C(absent) will block execution until the process no longer exists, |
| 63 |
or until the timeout has been reached. |
| 64 |
- When waiting for C(present), the module will return changed only if |
| 65 |
the process was not present on the initial check but became present on |
| 66 |
subsequent checks. |
| 67 |
- If, while waiting for C(absent), new processes matching the supplied |
| 68 |
pattern are started, these new processes will not be included in the |
| 69 |
action. |
| 70 |
type: str |
| 71 |
default: present |
| 72 |
choices: [ absent, present ] |
| 73 |
timeout: |
| 74 |
description: |
| 75 |
- The maximum number of seconds to wait for a for a process to start or stop |
| 76 |
before erroring out. |
| 77 |
type: int |
| 78 |
default: 300 |
| 79 |
seealso: |
| 80 |
- module: ansible.builtin.wait_for |
| 81 |
- module: ansible.windows.win_wait_for |
| 82 |
author: |
| 83 |
- Charles Crossan (@crossan007) |
| 84 |
''' |
| 85 |
|
| 86 |
EXAMPLES = r''' |
| 87 |
- name: Wait 300 seconds for all Oracle VirtualBox processes to stop. (VBoxHeadless, VirtualBox, VBoxSVC) |
| 88 |
community.windows.win_wait_for_process: |
| 89 |
process_name_pattern: 'v(irtual)?box(headless|svc)?' |
| 90 |
state: absent |
| 91 |
timeout: 500 |
| 92 |
|
| 93 |
- name: Wait 300 seconds for 3 instances of cmd to start, waiting 5 seconds between each check |
| 94 |
community.windows.win_wait_for_process: |
| 95 |
process_name_exact: cmd |
| 96 |
state: present |
| 97 |
timeout: 500 |
| 98 |
sleep: 5 |
| 99 |
process_min_count: 3 |
| 100 |
''' |
| 101 |
|
| 102 |
RETURN = r''' |
| 103 |
elapsed: |
| 104 |
description: The elapsed seconds between the start of poll and the end of the module. |
| 105 |
returned: always |
| 106 |
type: float |
| 107 |
sample: 3.14159265 |
| 108 |
matched_processes: |
| 109 |
description: List of matched processes (either stopped or started). |
| 110 |
returned: always |
| 111 |
type: complex |
| 112 |
contains: |
| 113 |
name: |
| 114 |
description: The name of the matched process. |
| 115 |
returned: always |
| 116 |
type: str |
| 117 |
sample: svchost |
| 118 |
owner: |
| 119 |
description: The owner of the matched process. |
| 120 |
returned: when supported by PowerShell |
| 121 |
type: str |
| 122 |
sample: NT AUTHORITY\SYSTEM |
| 123 |
pid: |
| 124 |
description: The PID of the matched process. |
| 125 |
returned: always |
| 126 |
type: int |
| 127 |
sample: 7908 |
| 128 |
''' |