ibm.ibm_zos_core.zos_lineinfile (1.9.0) — module

Manage textual data on z/OS

| "added in version" 1.2.0 of ibm.ibm_zos_core"

Authors: Behnam (@balkajbaf)

Install collection

Install with ansible-galaxy collection install ibm.ibm_zos_core:==1.9.0


Add to requirements.yml

  collections:
    - name: ibm.ibm_zos_core
      version: 1.9.0

Description

Manage lines in z/OS UNIX System Services (USS) files, PS (sequential data set), PDS, PDSE, or member of a PDS or PDSE.

This module ensures a particular line is in a USS file or data set, or replace an existing line using a back-referenced regular expression.

This is primarily useful when you want to change a single line in a USS file or data set only.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Ensure value of a variable in the sequential data set
  zos_lineinfile:
    src: SOME.DATA.SET
    regexp: '^VAR='
    line: VAR="some value"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove all comments in the USS file
  zos_lineinfile:
    src: /tmp/src/somefile
    state: absent
    regexp: '^#'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Ensure the https port is 8080
  zos_lineinfile:
    src: /tmp/src/somefile
    regexp: '^Listen '
    insertafter: '^#Listen '
    line: Listen 8080
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Ensure we have our own comment added to the partitioned data set member
  zos_lineinfile:
    src: SOME.PARTITIONED.DATA.SET(DATA)
    regexp: '#^VAR='
    insertbefore: '^VAR='
    line: '# VAR default value'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Ensure the user working directory for liberty is set as needed
  zos_lineinfile:
    src: /tmp/src/somefile
    regexp: '^(.*)User(\d+)m(.*)$'
    line: '\1APPUser\3'
    backrefs: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Add a line to a member while a task is in execution
  zos_lineinfile:
    src: SOME.PARTITIONED.DATA.SET(DATA)
    insertafter: EOF
    line: 'Should be a working test now'
    force: True

Inputs

    
src:
    aliases:
    - path
    - destfile
    - name
    description:
    - The location can be a UNIX System Services (USS) file, PS (sequential data set),
      member of a PDS or PDSE, PDS, PDSE.
    - The USS file must be an absolute pathname.
    required: true
    type: str

line:
    description:
    - The line to insert/replace into the USS file or data set.
    - Required for C(state=present).
    - If C(backrefs) is set, may contain backreferences that will get expanded with the
      C(regexp) capture groups if the regexp matches.
    required: false
    type: str

force:
    default: false
    description:
    - Specifies that the data set can be shared with others during an update which results
      in the data set you are updating to be simultaneously updated by others.
    - This is helpful when a data set is being used in a long running process such as
      a started task and you are wanting to update or read.
    - The C(force) option enables sharing of data sets through the disposition I(DISP=SHR).
    required: false
    type: bool

state:
    choices:
    - absent
    - present
    default: present
    description:
    - Whether the line should be inserted/replaced(present) or removed(absent).
    type: str

backup:
    default: false
    description:
    - Creates a backup file or backup data set for I(src), including the timestamp information
      to ensure that you retrieve the original file.
    - I(backup_name) can be used to specify a backup file name if I(backup=true).
    - The backup file name will be return on either success or failure of module execution
      such that data can be retrieved.
    required: false
    type: bool

regexp:
    description:
    - The regular expression to look for in every line of the USS file or data set.
    - For C(state=present), the pattern to replace if found. Only the last line found
      will be replaced.
    - For C(state=absent), the pattern of the line(s) to remove.
    - If the regular expression is not matched, the line will be added to the USS file
      or data set in keeping with C(insertbefore) or C(insertafter) settings.
    - When modifying a line the regexp should typically match both the initial state of
      the line as well as its state after replacement by C(line) to ensure idempotence.
    required: false
    type: str

tmp_hlq:
    description:
    - Override the default high level qualifier (HLQ) for temporary and backup datasets.
    - The default HLQ is the Ansible user used to execute the module and if that is not
      available, then the value C(TMPHLQ) is used.
    required: false
    type: str

backrefs:
    default: false
    description:
    - Used with C(state=present).
    - If set, C(line) can contain backreferences (both positional and named) that will
      get populated if the C(regexp) matches.
    - This parameter changes the operation of the module slightly; C(insertbefore) and
      C(insertafter) will be ignored, and if the C(regexp) does not match anywhere in
      the USS file or data set, the USS file or data set will be left unchanged.
    - If the C(regexp) does match, the last matching line will be replaced by the expanded
      line parameter.
    required: false
    type: bool

encoding:
    default: IBM-1047
    description:
    - The character set of the source I(src). L(zos_lineinfile,./zos_lineinfile.html)
      requires to be provided with correct encoding to read the content of 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.
    - Supported character sets rely on the charset conversion utility (iconv) version;
      the most common character sets are supported.
    required: false
    type: str

firstmatch:
    default: false
    description:
    - Used with C(insertafter) or C(insertbefore).
    - If set, C(insertafter) and C(insertbefore) will work with the first line that matches
      the given regular expression.
    required: false
    type: bool

backup_name:
    description:
    - Specify the USS file name or data set name for the destination backup.
    - If the source I(src) is a USS file or path, the backup_name must be a file or path
      name, and the USS file or path must be an absolute path name.
    - If the source is an MVS data set, the backup_name must be an MVS data set name.
    - If the backup_name is not provided, the default backup_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. C(/path/file_name.2020-04-23-08-32-29-bak.tar).
    - If the source is an MVS data set, it will be a data set with a random name generated
      by calling the ZOAU API. The MVS backup data set recovery can be done by renaming
      it.
    required: false
    type: str

insertafter:
    description:
    - Used with C(state=present).
    - If specified, the line will be inserted after the last match of specified regular
      expression.
    - If the first match is required, use(firstmatch=yes).
    - A special value is available; C(EOF) for inserting the line at the end of the USS
      file or data set.
    - If the specified regular expression has no matches, EOF will be used instead.
    - If C(insertbefore) is set, default value C(EOF) will be ignored.
    - If regular expressions are passed to both C(regexp) and C(insertafter), C(insertafter)
      is only honored if no match for C(regexp) is found.
    - May not be used with C(backrefs) or C(insertbefore).
    - Choices are EOF or '*regex*'
    - Default is EOF
    required: false
    type: str

insertbefore:
    description:
    - Used with C(state=present).
    - If specified, the line will be inserted before the last match of specified regular
      expression.
    - If the first match is required, use C(firstmatch=yes).
    - A value is available; C(BOF) for inserting the line at the beginning of the USS
      file or data set.
    - If the specified regular expression has no matches, the line will be inserted at
      the end of the USS file or data set.
    - If regular expressions are passed to both C(regexp) and C(insertbefore), C(insertbefore)
      is only honored if no match for C(regexp) is found.
    - May not be used with C(backrefs) or C(insertafter).
    - Choices are BOF or '*regex*'
    required: false
    type: str

Outputs

backup_name:
  description: Name of the backup file or data set that was created.
  returned: if backup=true
  sample: /path/to/file.txt.2015-02-03@04:15~
  type: str
changed:
  description: Indicates if the source was modified. Value of 1 represents `true`,
    otherwise `false`.
  returned: success
  sample: 1
  type: bool
cmd:
  description: constructed dsed shell cmd based on the parameters
  returned: success
  sample: dsedhelper -d -en IBM-1047 /^PATH=/a\\PATH=/dir/bin:$PATH/$ /etc/profile
  type: str
found:
  description: Number of the matching patterns
  returned: success
  sample: 5
  type: int
msg:
  description: The module messages
  returned: failure
  sample: Parameter verification failed
  type: str
return_content:
  description: The error messages from ZOAU dsed
  returned: failure
  sample: BGYSC1311E Iconv error, cannot open converter from ISO-88955-1 to IBM-1047
  type: str