4

I'm using the IBM z/OS CICS collection for Ansible. I need to be able to find all CICS regions that contain a particular program, and automate that on a regular basis.

I have CMCI set up and have tested that. I can also get all programs like this:

  tasks:
    - name: 'Get all programs'
      delegate_to: 'localhost'
      ibm.ibm_zos_cics.cmci_get:
        type: 'CICSProgram'
        scope: [redacted]

I'm not quite sure how I should filter the programs or how I should map the result into the CICS region name, and return it as a comma-separated list.

Ben Cox
  • 1,393
  • 10
  • 28

1 Answers1

4

You can try a playbook something like this, which uses filter to find all instances of a PROGRAM resource with a specific name.

It then uses the built-in debug module combined with a Jinja filter to extract the name of the region each PROGRAM was found in, finally joining them into a comma-separated list:

---
- name:  CICS CMCI Report

  collections:
      - ibm.ibm_zos_cics

  hosts: 'localhost'
  gather_facts: 'false'

  vars:
    program_name: MYPROG
    context: CICSPLEX
    cmci_host: 'example.com'
    cmci_port: 12345

  tasks:
    - name: Make sure CMCI module dependencies are installed
      pip:
        name:
          - requests
          - xmltodict

    - name: Find all instances of a particular program
      cmci_get:
        context: '{{ context }}'
        cmci_host: '{{ cmci_host }}'
        cmci_port: '{{ cmci_port }}'
        type: 'CICSProgram'
        resources:
          filter:
            program: '{{ program_name }}'
      register: result

    - name: Extract the CICS region names from the program records
      debug:
        msg: "{{ result.records | map(attribute='eyu_cicsname') | join(',') }}"
Ben Cox
  • 1,393
  • 10
  • 28
Stewart Francis
  • 735
  • 5
  • 10