Mainframe Path Start learning free
Beginner6 min readLesson 5 of 5

Ansible for z/OS

IBM's certified Ansible collection for z/OS, ibm.ibm_zos_core, lets the same playbooks manage datasets, submit jobs, copy files and issue operator commands on z/OS. Ansible connects over SSH to z/OS UNIX, and the z/OS system needs IBM Open Enterprise SDK for Python and IBM Z Open Automation Utilities (ZOAU) installed.

Same Ansible, z/OS modules

z/OS is managed like any other node, through Red Hat Ansible Certified Content for IBM Z. The core collection, ibm.ibm_zos_core, provides modules for everyday z/OS work. Other IBM collections cover areas such as IMS, CICS and z/OSMF.

ModuleWhat it does
zos_data_setCreate, delete or catalog datasets and members
zos_copyCopy files and datasets, converting the code page where needed
zos_job_submitSubmit JCL from a dataset, a z/OS UNIX file or the control node
zos_job_outputFetch a job's output from the spool
zos_operatorIssue a z/OS operator command and return the response
zos_tso_commandRun TSO commands

What the z/OS system needs

Each version of the collection supports particular versions of z/OS, ZOAU and Python, so check IBM's requirements table before you upgrade any of them.

A small z/OS playbook

build-and-run.yml
- name: Prepare a library and run the nightly job
  hosts: zos_test
  tasks:
    - name: Make sure the JCL library exists
      ibm.ibm_zos_core.zos_data_set:
        name: PAYROLL.TEST.JCL
        type: pds
        state: present
        record_format: fb
        record_length: 80

    - name: Copy the JCL from the repository to a member
      ibm.ibm_zos_core.zos_copy:
        src: jcl/nightly.jcl
        dest: PAYROLL.TEST.JCL(NIGHTLY)

    - name: Submit it and fail if any step ends above RC 4
      ibm.ibm_zos_core.zos_job_submit:
        src: PAYROLL.TEST.JCL(NIGHTLY)
        remote_src: true
        wait_time: 600
        max_rc: 4
      register: job

remote_src: true tells zos_job_submit that the JCL is already on z/OS. wait_time: 600 lets the task wait up to ten minutes for the job to finish (the default is only a few seconds). max_rc: 4 makes the task fail if any step ends with a return code above 4, which brings back the familiar z/OS rule from the JCL world. register: job keeps the result, including the job ID and step return codes, for later tasks to use. zos_copy converts text such as JCL from the control node's character set to EBCDIC on the way in, unless you mark the file as binary.

TRY IT YOURSELF

What is the name of IBM's core Ansible collection for z/OS? (namespace.collection)

Show a hint

ibm dot ibm underscore ...

Show the solution

ibm.ibm_zos_core.

Examples are for learning. Run commands and jobs only on a system you are authorised to use, such as a training or test system, and never on production without approval.

Common mistakes

Forgetting the z/OS prerequisites

Without Python and ZOAU on z/OS, the modules cannot run. Check them before blaming the playbook.

Running with a powerful shared user ID

Use a dedicated user ID with only the RACF access the automation needs, so every change can be traced.

Ignoring the job's return codes

A job that ends with RC 12 is still 'submitted'. Use max_rc or check the registered result.

What you will see at work

Key terms

Check your understanding.
Take this lesson's quiz and save your progress. Free.

Take the lesson quiz
← Run it twice: idempotence, roles and VaultBack to Ansible and playbooks