-
Notifications
You must be signed in to change notification settings - Fork 43
[Documentation][2234]update_zos_replace_documentation #2239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 7 commits
cb0671a
1aca7d0
6cc4ac8
a198ca8
254bdce
d32fe82
4714e2c
7b154bd
8d8cf87
d4b4bc2
e84c153
222734c
600e18d
092731d
c555448
3761d7f
487522d
3d97e6f
5173ef0
12f26de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
trivial: | ||
- zos_replace_func.py - Update documentation adding default values and add verbosity for after, before and literal options. | ||
(https://github.com/ansible-collections/ibm_zos_core/pull/2239). |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,17 @@ | |
options: | ||
after: | ||
description: | ||
- If specified, only content after this match will be replaced/removed. | ||
- A regular expression that if specified, only content after this match will be replaced/removed. | ||
fernandofloresg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- I(after) works as the opening bracket for a search block where the module will search for I(regexp) and | ||
if found, replace it with I(replace). | ||
fernandofloresg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- By default works as a regular expression based on re python library L(re python library,https://docs.python.org/es/3.13/library/re.html). | ||
fernandofloresg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- Can be used in combination with I(before). | ||
- If I(after) is empty, the module will start searching from the beginning of the file till the line match of I(before). | ||
fernandofloresg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Within that range, it will look for a match with I(regexp) and replace it with I(replace) if found. | ||
- The I(after) value can be treated as a literal string instead of a regular expression by using the I(literal) option. | ||
- To disable the regex behavior of I(after) only, set the I(literal) option to 'after'. | ||
fernandofloresg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
required: false | ||
default: '' | ||
type: str | ||
backup: | ||
description: | ||
|
@@ -63,9 +71,17 @@ | |
type: str | ||
before: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since there are pending reviews, I can not multi select the entire section of text for
|
||
description: | ||
- If specified, only content before this match will be replaced/removed. | ||
- A regular expression that if specified, only content before this match will be replaced/removed. | ||
fernandofloresg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- I(before) works as the closing bracket for a search block where the module will search for I(regexp) and | ||
if found, replace it with I(replace). | ||
- By default works as a regular expression based on L(re python library,https://docs.python.org/es/3.13/library/re.html). | ||
fernandofloresg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- Can be used in combination with I(after). | ||
- If I(before) is empty, the module will start searching from the line that matches I(after) and continue to the end of the file. | ||
Within that range, it will look for a match with I(regexp) and replace it with I(replace) if found. | ||
fernandofloresg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- The I(before) value can be treated as a literal string instead of a regular expression by using the I(literal) option. | ||
- To disable the regex behavior of I(before) only, set the I(literal) option to 'before'. | ||
fernandofloresg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
required: false | ||
default: '' | ||
type: str | ||
encoding: | ||
description: | ||
|
@@ -81,7 +97,10 @@ | |
literal: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since there are pending reviews, I can not multi select the entire section of text for
|
||
description: | ||
- A list or string that allows the user to specify choices "before", "after", or "regexp" as regular strings instead of regex patterns. | ||
- To treat multiple options as literal strings disabling regex, include them in the I(literal) list e.g., C(['before', 'after']). | ||
fernandofloresg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- To treat only one option as a literal string disabling regex, set I(literal) to one of the choices "before", "after" or "regexp". | ||
fernandofloresg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
required: false | ||
default: [] | ||
type: raw | ||
target: | ||
description: | ||
|
@@ -112,34 +131,35 @@ | |
- If not set, matches are removed entirely. | ||
required: false | ||
type: str | ||
default: "" | ||
default: '' | ||
|
||
notes: | ||
- For supported character sets used to encode data, refer to the | ||
L(documentation,https://ibm.github.io/z_ansible_collections_doc/ibm_zos_core/docs/source/resources/character_set.html). | ||
""" | ||
|
||
EXAMPLES = r""" | ||
- name: Replace with blank space on a USS file any occurrences of the regex | ||
- name: Replace 'profile/' pattern from USS file via blank substitution. | ||
fernandofloresg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
zos_replace: | ||
target: /tmp/src/somefile | ||
regexp: 'profile\/' | ||
|
||
- name: Replace using after on USS file | ||
- name: Replace regexp match with blank after line match in USS file. | ||
zos_replace: | ||
target: "/tmp/source" | ||
regexp: '^MOUNTPOINT*' | ||
after: export ZOAU_ROOT | ||
|
||
- name: Replace a specific line with special character on a dataset after a line | ||
- name: Replace a specific line with special character on a dataset after a line, treating the text specified | ||
for regexp as a literal string and after as regular expression. | ||
zos_replace: | ||
target: SAMPLE.SOURCE | ||
regexp: //*LIB DD UNIT=SYS,SPACE=(TRK,(1,1)),VOL=SER=vvvvvv | ||
replace: //*LIB DD UNIT=SYS,SPACE=(CYL,(1,1)) | ||
after: '^\$source base \([^\s]+\)' | ||
literal: regexp | ||
|
||
- name: Replace a specific line before a specific sentence with backup | ||
- name: Replace a specific line before a specific sentence with backup, treating the text specified for regexp and before as literal strings. | ||
zos_replace: | ||
target: SAMPLE.SOURCE | ||
backup: true | ||
|
@@ -149,7 +169,7 @@ | |
- regexp | ||
- before | ||
|
||
- name: Replace some words between two lines with a backup with tmp_hlq | ||
- name: Replace 'var' with 'vars' between matched lines after and before with backup. | ||
zos_replace: | ||
target: SAMPLE.DATASET | ||
tmp_hlq: ANSIBLE | ||
|
@@ -160,7 +180,7 @@ | |
after: ^/tmp/source* | ||
before: ^ if* | ||
|
||
- name: Replace lines on a GDS and generate a backup on the same GDG | ||
- name: Replace lines on a GDS and generate a backup on the same GDG. | ||
zos_replace: | ||
target: SOURCE.GDG(0) | ||
regexp: ^(IEE132I|IEA989I|IEA888I|IEF196I|IEA000I)\s.* | ||
|
@@ -169,7 +189,7 @@ | |
backup: true | ||
backup_name: "SOURCE.GDG(+1)" | ||
|
||
- name: Delete some calls to SYSTEM on a member using a backref | ||
- name: Delete 'SYSTEM' calls via backref between matched lines in PDS member. | ||
fernandofloresg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
zos_replace: | ||
target: PDS.SOURCE(MEM) | ||
regexp: '^(.*?SYSTEM.*?)SYSTEM(.*)' | ||
|
@@ -183,13 +203,13 @@ | |
description: Name of the backup file or data set that was created. | ||
returned: if backup=true | ||
type: str | ||
sample: /path/to/file.txt.2015-02-03@04:15 | ||
sample: "/path/to/file.txt.2015-02-03@04:15" | ||
changed: | ||
description: | ||
Indicates if the source was modified. | ||
returned: always | ||
type: bool | ||
sample: 1 | ||
sample: True | ||
found: | ||
description: Number of matches found | ||
returned: success | ||
|
@@ -557,28 +577,28 @@ def replace_func(file, regexp, replace, module, uss, literal, encoding="cp1047", | |
def run_module(): | ||
module = AnsibleModule( | ||
argument_spec=dict( | ||
after=dict(type='str'), | ||
after=dict(type='str', default=''), | ||
backup=dict(type='bool', default=False, required=False), | ||
backup_name=dict(type='str', default=None, required=False), | ||
before=dict(type='str'), | ||
before=dict(type='str', default=''), | ||
encoding=dict(type='str', default='IBM-1047', required=False), | ||
target=dict(type="str", required=True, aliases=['src', 'path', 'destfile']), | ||
tmp_hlq=dict(type='str', required=False, default=None), | ||
literal=dict(type="raw", required=False, default=None), | ||
literal=dict(type="raw", required=False, default=[]), | ||
regexp=dict(type="str", required=True), | ||
replace=dict(type='str', default=""), | ||
), | ||
supports_check_mode=False | ||
) | ||
args_def = dict( | ||
after=dict(type='str'), | ||
after=dict(type='str', default=''), | ||
backup=dict(type='bool', default=False, required=False), | ||
backup_name=dict(type='data_set_or_path', default=None, required=False), | ||
before=dict(type='str'), | ||
before=dict(type='str', default=''), | ||
encoding=dict(type='str', default='IBM-1047', required=False), | ||
target=dict(type="data_set_or_path", required=True, aliases=['src', 'path', 'destfile']), | ||
tmp_hlq=dict(type='qualifier_or_empty', required=False, default=None), | ||
literal=dict(type=literals, required=False, default=None), | ||
literal=dict(type=literals, required=False, default=[]), | ||
regexp=dict(type="str", required=True), | ||
replace=dict(type='str', default=""), | ||
) | ||
|
@@ -708,6 +728,8 @@ def literals(contents, dependencies): | |
allowed_values = {"after", "before", "regexp"} | ||
if not contents: | ||
return None | ||
if contents == []: | ||
return None | ||
if not isinstance(contents, list): | ||
contents = [contents] | ||
for val in contents: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there are pending reviews, I can not multi select the entire section of text for
after
so I am going to offer my rewrite that also updates the URL so there is no version embedded, also makes the latest Ansible markupO(...)
and other things likeB(bold)
. This is for the entireafter
section of text.