|
| 1 | + |
| 2 | +:github_url: https://github.com/ansible-collections/ibm_zos_core/blob/dev/plugins/modules/zos_replace.py |
| 3 | + |
| 4 | +.. _zos_replace_module: |
| 5 | + |
| 6 | + |
| 7 | +zos_replace -- Replace all instances of a pattern within a file or data set. |
| 8 | +============================================================================ |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +.. contents:: |
| 13 | + :local: |
| 14 | + :depth: 1 |
| 15 | + |
| 16 | + |
| 17 | +Synopsis |
| 18 | +-------- |
| 19 | +- The module `zos_replace. </zos_replace.html>`_ can replace all instances of a pattern in the contents of a data set. |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +Parameters |
| 26 | +---------- |
| 27 | + |
| 28 | + |
| 29 | +after |
| 30 | + If specified, only content after this match will be replaced/removed. |
| 31 | + |
| 32 | + Can be used in combination with *before*. |
| 33 | + |
| 34 | + | **required**: False |
| 35 | + | **type**: str |
| 36 | +
|
| 37 | + |
| 38 | +backup |
| 39 | + Specifies whether a backup of the destination should be created before editing the source *target*. |
| 40 | + |
| 41 | + When set to ``true``, the module creates a backup file or data set. |
| 42 | + |
| 43 | + The backup file name will be returned on either success or failure of module execution such that data can be retrieved. |
| 44 | + |
| 45 | + | **required**: False |
| 46 | + | **type**: bool |
| 47 | + | **default**: False |
| 48 | +
|
| 49 | + |
| 50 | +backup_name |
| 51 | + Specify the USS file name or data set name for the destination backup. |
| 52 | + |
| 53 | + If *src* is a USS file or path, backup_name must be a file or path name, and it must be an absolute path name. |
| 54 | + |
| 55 | + If the source is an MVS data set, *backup_name* must be an MVS data set name, and the data set must not be preallocated. |
| 56 | + |
| 57 | + If *backup_name* is not provided, a default name will be used. If the source is a USS file or path, the name of the backup file will be the source file or path name appended with a timestamp, e.g. ``/path/file_name.2020-04-23-08-32-29-bak.tar``. |
| 58 | + |
| 59 | + If *src* is a data set member and backup_name is not provided, the data set member will be backed up to the same partitioned data set with a randomly generated member name. |
| 60 | + |
| 61 | + If it is a Generation Data Set (GDS), use a relative positive name, e.g., *SOME.CREATION(+1*). |
| 62 | + |
| 63 | + | **required**: False |
| 64 | + | **type**: str |
| 65 | +
|
| 66 | + |
| 67 | +before |
| 68 | + If specified, only content before this match will be replaced/removed. |
| 69 | + |
| 70 | + Can be used in combination with *after*. |
| 71 | + |
| 72 | + | **required**: False |
| 73 | + | **type**: str |
| 74 | +
|
| 75 | + |
| 76 | +encoding |
| 77 | + The character set of the source *target*. `zos_replace <./zos_replace.html>`_ requires it to be provided with correct encoding to read the content of a USS file or data set. If this parameter is not provided, this module assumes that USS file or data set is encoded in IBM-1047. |
| 78 | + |
| 79 | + Supported character sets rely on the charset conversion utility (iconv) version; the most common character sets are supported. |
| 80 | + |
| 81 | + | **required**: False |
| 82 | + | **type**: str |
| 83 | + | **default**: IBM-1047 |
| 84 | +
|
| 85 | + |
| 86 | +disable_regex |
| 87 | + A list or string that allows the user to specify choices "before", "after", or "regexp" as regular strings instead of regex patterns. |
| 88 | + |
| 89 | + | **required**: False |
| 90 | + | **type**: raw |
| 91 | +
|
| 92 | + |
| 93 | +target |
| 94 | + The location can be a UNIX System Services (USS) file, PS (sequential data set), member of a PDS or PDSE, PDS, PDSE. |
| 95 | + |
| 96 | + The USS file must be an absolute pathname. |
| 97 | + |
| 98 | + It is possible to use a generation data set (GDS) relative name of generation already. created. e.g. *SOME.CREATION(-1*). |
| 99 | + |
| 100 | + | **required**: True |
| 101 | + | **type**: str |
| 102 | +
|
| 103 | + |
| 104 | +tmp_hlq |
| 105 | + Override the default High Level Qualifier (HLQ) for temporary and backup data sets. |
| 106 | + |
| 107 | + The default HLQ is the Ansible user used to execute the module and if that is not available, then the value of ``TMPHLQ`` is used. |
| 108 | + |
| 109 | + | **required**: False |
| 110 | + | **type**: str |
| 111 | +
|
| 112 | + |
| 113 | +regexp |
| 114 | + The regular expression to look for in the contents of the file. |
| 115 | + |
| 116 | + | **required**: True |
| 117 | + | **type**: str |
| 118 | +
|
| 119 | + |
| 120 | +replace |
| 121 | + The string to replace *regexp* matches with. |
| 122 | + |
| 123 | + If not set, matches are removed entirely. |
| 124 | + |
| 125 | + | **required**: False |
| 126 | + | **type**: str |
| 127 | +
|
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | +Examples |
| 134 | +-------- |
| 135 | + |
| 136 | +.. code-block:: yaml+jinja |
| 137 | + |
| 138 | + |
| 139 | + - name: Replace with blank space on a USS file any occurrences of the regex |
| 140 | + zos_replace: |
| 141 | + target: /tmp/src/somefile |
| 142 | + regexp: 'profile\/' |
| 143 | + |
| 144 | + - name: Replace using after on USS file |
| 145 | + zos_replace: |
| 146 | + target: "/tmp/source" |
| 147 | + regexp: '^MOUNTPOINT*' |
| 148 | + after: export ZOAU_ROOT |
| 149 | + |
| 150 | + - name: Replace a specific line with special character on a dataset after a line |
| 151 | + zos_replace: |
| 152 | + target: SAMPLE.SOURCE |
| 153 | + regexp: //*LIB DD UNIT=SYS,SPACE=(TRK,(1,1)),VOL=SER=vvvvvv |
| 154 | + replace: //*LIB DD UNIT=SYS,SPACE=(CYL,(1,1)) |
| 155 | + after: '^\$source base \([^\s]+\)' |
| 156 | + disable_regex: regexp |
| 157 | +
|
| 158 | + - name: Replace a specific line before a specific sentence with backup |
| 159 | + zos_replace: |
| 160 | + target: SAMPLE.SOURCE |
| 161 | + backup: True |
| 162 | + regexp: //SYSPRINT DD SYSOUT=* |
| 163 | + before: SAMPLES OUTPUT SYSIN *=$DSN |
| 164 | + disable_regex: |
| 165 | + - regexp |
| 166 | + - before |
| 167 | +
|
| 168 | + - name: Replace some words between two lines with a backup with tmp_hlq |
| 169 | + zos_replace: |
| 170 | + target: SAMPLE.DATASET |
| 171 | + tmp_hlq: ANSIBLE |
| 172 | + backup: True |
| 173 | + backup_name: BACKUP.DATASET |
| 174 | + regexp: var |
| 175 | + replace: vars |
| 176 | + after: ^/tmp/source* |
| 177 | + before: ^ if* |
| 178 | + |
| 179 | + - name: Replace lines on a GDS and generate a backup on the same GDG |
| 180 | + zos_replace: |
| 181 | + target: SOURCE.GDG(0) |
| 182 | + regexp: ^(IEE132I|IEA989I|IEA888I|IEF196I|IEA000I)\s.* |
| 183 | + after: ^IEE133I PENDING * |
| 184 | + before: ^IEE252I DEVICE * |
| 185 | + backup: True |
| 186 | + backup_name: "SOURCE.GDG(+1)" |
| 187 | + |
| 188 | + - name: Delete some calls to SYSTEM on a member using a backref |
| 189 | + zos_replace: |
| 190 | + target: PDS.SOURCE(MEM) |
| 191 | + regexp: '^(.*?SYSTEM.*?)SYSTEM(.*)' |
| 192 | + replace: '\1\2' |
| 193 | + after: IEE133I PENDING * |
| 194 | + before: IEF456I JOB12345 * |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | + |
| 204 | + |
| 205 | +Return Values |
| 206 | +------------- |
| 207 | + |
| 208 | + |
| 209 | +backup_name |
| 210 | + Name of the backup file or data set that was created. |
| 211 | + |
| 212 | + | **returned**: if backup=true |
| 213 | + | **type**: str |
| 214 | + | **sample**: /path/to/file.txt.2015-02-03@04:15 |
| 215 | +
|
| 216 | +changed |
| 217 | + Indicates if the source was modified. |
| 218 | + |
| 219 | + | **returned**: always |
| 220 | + | **type**: bool |
| 221 | + | **sample**: |
| 222 | +
|
| 223 | + .. code-block:: json |
| 224 | +
|
| 225 | + 1 |
| 226 | +
|
| 227 | +found |
| 228 | + Number of matches found |
| 229 | + |
| 230 | + | **returned**: success |
| 231 | + | **type**: int |
| 232 | + | **sample**: 5 |
| 233 | +
|
| 234 | +msg |
| 235 | + Error messages from the module |
| 236 | + |
| 237 | + | **returned**: failure |
| 238 | + | **type**: str |
| 239 | + | **sample**: Parameter verification failed |
| 240 | +
|
| 241 | +replaced |
| 242 | + Fragment of the file that was changed |
| 243 | + |
| 244 | + | **returned**: always |
| 245 | + | **type**: str |
| 246 | + | **sample**: IEE134I TRACE DISABLED - MONITORING STOPPED |
| 247 | +
|
| 248 | +target |
| 249 | + The data set name or USS path that was modified. |
| 250 | + |
| 251 | + | **returned**: always |
| 252 | + | **type**: str |
| 253 | + | **sample**: ANSIBLE.USER.TEXT |
| 254 | +
|
0 commit comments