expect docs - improve responses description (#82544)

* consolidate notes describing the structure of `responses` with the option description

* include a link to Python regex syntax
pull/82551/head
Sloane Hertel 4 months ago committed by GitHub
parent 6b9f49b6c5
commit 0429520790
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -37,9 +37,11 @@ options:
responses:
type: dict
description:
- Mapping of expected string/regex and string to respond with. If the
response is a list, successive matches return successive
responses. List functionality is new in 2.1.
- Mapping of prompt regular expressions and corresponding answer(s).
- Each key in O(responses) is a Python regex U(https://docs.python.org/3/library/re.html#regular-expression-syntax).
- The value of each key is a string or list of strings.
If the value is a string and the prompt is encountered multiple times, the answer will be repeated.
Provide the value as a list to give different answers for successive matches.
required: true
timeout:
type: raw
@ -68,15 +70,10 @@ notes:
- If you want to run a command through the shell (say you are using C(<),
C(>), C(|), and so on), you must specify a shell in the command such as
C(/bin/bash -c "/path/to/something | grep else").
- The question, or key, under O(responses) is a python regex match. Case
insensitive searches are indicated with a prefix of C(?i).
- Case insensitive searches are indicated with a prefix of C(?i).
- The C(pexpect) library used by this module operates with a search window
of 2000 bytes, and does not use a multiline regex match. To perform a
start of line bound match, use a pattern like ``(?m)^pattern``
- By default, if a question is encountered multiple times, its string
response will be repeated. If you need different responses for successive
question matches, instead of a string response, use a list of strings as
the response. The list functionality is new in 2.1.
- The M(ansible.builtin.expect) module is designed for simple scenarios.
For more complex needs, consider the use of expect code with the M(ansible.builtin.shell)
or M(ansible.builtin.script) modules. (An example is part of the M(ansible.builtin.shell) module documentation).
@ -97,14 +94,17 @@ EXAMPLES = r'''
# you don't want to show passwords in your logs
no_log: true
- name: Generic question with multiple different responses
- name: Match multiple regular expressions and demonstrate individual and repeated responses
ansible.builtin.expect:
command: /path/to/custom/command
responses:
Question:
# give a unique response for each of the 3 hypothetical prompts matched
- response1
- response2
- response3
# give the same response for every matching prompt
"^Match another prompt$": "response"
- name: Multiple questions with responses
ansible.builtin.expect:

Loading…
Cancel
Save