Z/os ansible find multiple string

here is my code it i don’t know if I’m on the right track

tasks:

- name: Submit a long running PDS job and wait up to 30 seconds for completion.
  zos_job_submit:
#   src: SYS2.DR.VERIFY.JCL(TESTANS) 
    src: XXC91.JCL.CNTL(TEST1) 
    location: DATA_SET
    wait_time_s: 10  

vars:
SEARCH_STRING: “active”

  - name: Search for string
    lineinfile:
      path: "{{ d_symbol_output }}"
      regexp: '^{{ SEARCH_STRING }}: (.*)'
      line: "SEARCH_STRING FOUND"
      state: present
    register: result   

in the below SYSTSPRT DR#CHECK example there are 5 task that say active.

how do i write this with logic that said
continue if active
if more one is not active do something

JESMSGLG JES2
JESJCL JES2
JESYSMSG JES2
SYSTSPRT DR#CHECK

================================================

5 Tasks Must be Active

**CAENF is active on T001 S0192669 Initialization Verified **
**CCISSLGW is active on T001 S0192845 Initialization Verified **
**DATACOM is active on T001 S0192601 Initialization Verified **
**CA11 is active on T001 S0192834 Initialization Verified **
CA11DB is active on T001 S0192600 Initialization Verified

T001 - Initialization COmplete Messages

CAENF : 01.33.46 S0192669 IEF403I CAENF - STARTED - TIME=01.33.46
: 01.33.53 S0192669 CAS9218I - ENF DB initialization complete
CA11 : 01.34.08 S0192834 IEF403I CA11 - STARTED - TIME=01.34.08
: 01.34.10 S0192834 U11D-0200-1 CA-11 DBAS INITIALIZATION COMPLETE

Ignore for now that fact that the last time I touched JCL or JES, z/os wasn’t called z/os and most of the Ansible core team wasn’t born yet…

Could you back up a step and try to explain how you see this working? I’ve been reading your initial post a few times and can’t quite make the pieces fit into a story.

For example: “{{ d_symbol_output }}”. I’m not sure what the contents of that file is supposed to look like. At any rate, what you show below that doesn’t match the regexp: from your “Search for string” task. Worse, lineinfile doesn’t count lines that match a pattern. It changes at most one (of possibly many) matching lines, or in case none of the existing lines matches it appends the specified line: to the file. Somehow I don’t think that’s what you have in mind.

I’m not asking you to give us a tutorial on z/os; that’s clearly out of scope for this forum. But perhaps if you can explain what you have to work with and what you’re trying to achieve, we may be able to give some hints about how to get there with Ansible.

1 Like

i simplify the code to work it found
“msg”: “CAENF is active on T001” active
i dont know if this the best way to code this and how to find the other task in this list.

in the below systprt it show 5 acitive task
i’m trying to capture all 5 task in the systprt
the logic is if this systprt show any else then active then do something.

**CAENF is active on T001 S0192669 Initialization Verified **
**CCISSLGW is active on T001 S0192845 Initialization Verified **
**DATACOM is active on T001 S0192601 Initialization Verified **
**CA11 is active on T001 S0192834 Initialization Verified **

  • name: Submit a long running PDS job and wait up to 30 seconds for completion.
    zos_job_submit:

    src: SYS2.DR.VERIFY.JCL(TESTANS)

     src: XXC91.JCL.CNTL(TEST1) 
     location: DATA_SET
     wait_time_s: 50 
    

    register: display_output

    • name: Print Displaying system activity to logs
      ansible.builtin.debug:

    msg: “{{ display_output }}”

     msg: "{{ display_output | regex_search('CAENF     is active on  T001') }}" 
    


TASK [Print Displaying system activity to logs] ********************************
task path: /runner/project/zos-display-stuff.yml:26
ok: [smtsftp.dtcc.com] => {
“msg”: “CAENF is active on T001”
}

Your last post - prior to editing - showed the structure of display_output, from which I could construct the following tasks. They should show you how to determine the number of “is active on” lines in display_output’s SYSTSPRT DD.

    - name: Select SYSTSPRT 'is active on' lines
      ansible.builtin.set_fact:
        is_active_on: "{{ display_output.jobs[0].ddnames
                          | selectattr('ddname','eq','SYSTSPRT')
                          | map(attribute='content')
                          | map('select', 'match', '.* is active on ')
                          | flatten
                       }}"

    - name: Show the 'is active on' lines, and count them
      ansible.builtin.debug:
        msg:
          - "{{ is_active_on }}"
          - "{{ is_active_on | length }}"

(I haven’t seen “IEF” messages since December of 1996. [shivers])

2 Likes

Todd , thank you so much i’m very new to ansible but i’m trying.
I tried the code this morning and it worked perfectly .
you are a live saver

thanks again

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.