ibm.ibm_zos_core.zos_script (1.9.0) — module

Run scripts in z/OS

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

Authors: Ivan Moreno (@rexemin)

This plugin has a corresponding action plugin.

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

The L(zos_script,./zos_script.html) module runs a local or remote script in the remote machine.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run a local REXX script on the managed z/OS node.
  zos_script:
    cmd: ./scripts/HELLO
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run a local REXX script with args on the managed z/OS node.
  zos_script:
    cmd: ./scripts/ARGS "1,2"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run a remote REXX script while changing its working directory.
  zos_script:
    cmd: /u/user/scripts/ARGS "1,2"
    remote_src: true
    chdir: /u/user/output_dir
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run a local Python script in the temporary directory specified in the Ansible environment variable 'remote_tmp'.
  zos_script:
    cmd: ./scripts/program.py
    executable: /usr/bin/python3
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run a local script made from a template.
  zos_script:
    cmd: ./templates/PROGRAM
    use_template: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run a script only when a file is not present.
  zos_script:
    cmd: ./scripts/PROGRAM
    creates: /u/user/pgm_result.txt
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run a script only when a file is already present on the remote machine.
  zos_script:
    cmd: ./scripts/PROGRAM
    removes: /u/user/pgm_input.txt

Inputs

    
cmd:
    description:
    - Path to the local or remote script followed by optional arguments.
    - If the script path contains spaces, make sure to enclose it in two pairs of quotes.
    - Arguments may need to be escaped so the shell in the remote machine handles them
      correctly.
    required: true
    type: str

chdir:
    description:
    - Change the script's working directory to this path.
    - When not specified, the script will run in the user's home directory on the remote
      machine.
    required: false
    type: str

creates:
    description:
    - Path to a file in the remote machine. If it exists, the script will not be executed.
    required: false
    type: str

removes:
    description:
    - Path to a file in the remote machine. If it does not exist, the script will not
      be executed.
    required: false
    type: str

encoding:
    description:
    - Specifies which encodings the script should be converted from and to.
    - If C(encoding) is not provided, the module determines which local and remote charsets
      to convert the data from and to.
    required: false
    suboptions:
      from:
        description:
        - The encoding to be converted from.
        required: true
        type: str
      to:
        description:
        - The encoding to be converted to.
        required: true
        type: str
    type: dict

executable:
    description:
    - Path of an executable in the remote machine to invoke the script with.
    - When not specified, the system will assume the script is interpreted REXX and try
      to run it as such. Make sure to include a comment identifying the script as REXX
      at the start of the file in this case.
    required: false
    type: str

remote_src:
    description:
    - If set to C(false), the module will search the script in the controller.
    - If set to C(true), the module will search the script in the remote machine.
    required: false
    type: bool

use_template:
    default: false
    description:
    - Whether the module should treat C(src) as a Jinja2 template and render it before
      continuing with the rest of the module.
    - Only valid when C(src) is a local file or directory.
    - All variables defined in inventory files, vars files and the playbook will be passed
      to the template engine, as well as L(Ansible special variables,https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html#special-variables),
      such as C(playbook_dir), C(ansible_version), etc.
    - If variables defined in different scopes share the same name, Ansible will apply
      variable precedence to them. You can see the complete precedence order L(in Ansible's
      documentation,https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#understanding-variable-precedence)
    type: bool

template_parameters:
    description:
    - Options to set the way Jinja2 will process templates.
    - Jinja2 already sets defaults for the markers it uses, you can find more information
      at its L(official documentation,https://jinja.palletsprojects.com/en/latest/templates/).
    - These options are ignored unless C(use_template) is true.
    required: false
    suboptions:
      auto_reload:
        default: false
        description:
        - Whether to reload a template file when it has changed after the task has started.
        type: bool
      block_end_string:
        default: '%}'
        description:
        - Marker for the end of a block in Jinja2.
        type: str
      block_start_string:
        default: '{%'
        description:
        - Marker for the beginning of a block in Jinja2.
        type: str
      comment_end_string:
        default: '#}'
        description:
        - Marker for the end of a comment in Jinja2.
        type: str
      comment_start_string:
        default: '{#'
        description:
        - Marker for the beginning of a comment in Jinja2.
        type: str
      keep_trailing_newline:
        default: false
        description:
        - Whether Jinja2 should keep the first trailing newline at the end of a template
          after rendering.
        type: bool
      line_comment_prefix:
        description:
        - Prefix used by Jinja2 to identify comment lines.
        required: false
        type: str
      line_statement_prefix:
        description:
        - Prefix used by Jinja2 to identify line-based statements.
        required: false
        type: str
      lstrip_blocks:
        default: false
        description:
        - Whether Jinja2 should strip leading spaces from the start of a line to a block.
        type: bool
      newline_sequence:
        choices:
        - '

          '
        - "\r"
        - "\r\n"
        default: '

          '
        description:
        - Sequence that starts a newline in a template.
        type: str
      trim_blocks:
        default: true
        description:
        - Whether Jinja2 should remove the first newline after a block is removed.
        - Setting this option to C(False) will result in newlines being added to the rendered
          template. This could create invalid code when working with JCL templates or
          empty records in destination data sets.
        type: bool
      variable_end_string:
        default: '}}'
        description:
        - Marker for the end of a statement to print a variable in Jinja2.
        type: str
      variable_start_string:
        default: '{{'
        description:
        - Marker for the beginning of a statement to print a variable in Jinja2.
        type: str
    type: dict

Outputs

cmd:
  description: Original command issued by the user.
  returned: changed
  sample: ./scripts/PROGRAM
  type: str
msg:
  description: Failure or skip message returned by the module.
  returned: failure or skipped
  sample: File /u/user/file.txt is already missing on the system, skipping script
  type: str
rc:
  description: Return code of the script.
  returned: changed
  sample: 16
  type: int
remote_cmd:
  description: Command executed on the remote machine. Will show the executable path
    used, and when running local scripts, will also show the temporary file used.
  returned: changed
  sample: /tmp/zos_script.jycqqfny.ARGS 1,2
  type: str
stderr:
  description: The STDERR from the script, may be empty.
  returned: changed
  sample: An error has ocurred.
  type: str
stderr_lines:
  description: List of strings containing individual lines from STDERR.
  returned: changed
  sample:
  - An error has ocurred
  type: list
stdout:
  description: The STDOUT from the script, may be empty.
  returned: changed
  sample: Allocation to SYSEXEC completed.
  type: str
stdout_lines:
  description: List of strings containing individual lines from STDOUT.
  returned: changed
  sample:
  - Allocation to SYSEXEC completed.
  type: list

See also