# Z/os ansible find multiple string

**URL:** <https://forum.ansible.com/t/z-os-ansible-find-multiple-string/6070>\
**Category:** Get Help\
**Created:** [May 29, 2024, 7:45pm UTC](https://forum.ansible.com/t/z-os-ansible-find-multiple-string/6070 "2024-05-29T19:45:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![U6crgb0](https://avatars.discourse-cdn.com/v4/letter/u/2bfe46/32.png) [@U6crgb0](https://forum.ansible.com/u/U6crgb0)\
**Post date:** [May 29, 2024, 7:45pm UTC](https://forum.ansible.com/t/z-os-ansible-find-multiple-string/6070/1 "2024-05-29T19:45:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [May 31, 2024, 7:11pm UTC](https://forum.ansible.com/t/z-os-ansible-find-multiple-string/6070/2 "2024-05-31T19:11:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![U6crgb0](https://avatars.discourse-cdn.com/v4/letter/u/2bfe46/32.png) [@U6crgb0](https://forum.ansible.com/u/U6crgb0)\
**Post date:** [June 1, 2024, 10:13pm UTC](https://forum.ansible.com/t/z-os-ansible-find-multiple-string/6070/3 "2024-06-01T22:13:10Z")

</div>

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:

* * *

* * *

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

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [June 2, 2024, 3:24am UTC](https://forum.ansible.com/t/z-os-ansible-find-multiple-string/6070/4 "2024-06-02T03:24:32Z")

</div>

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.

```yaml
    - 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]_)

---

<div class="post-metadata">

**Author:** ![U6crgb0](https://avatars.discourse-cdn.com/v4/letter/u/2bfe46/32.png) [@U6crgb0](https://forum.ansible.com/u/U6crgb0)\
**Post date:** [June 2, 2024, 1:10pm UTC](https://forum.ansible.com/t/z-os-ansible-find-multiple-string/6070/5 "2024-06-02T13:10:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 2, 2024, 1:11pm UTC](https://forum.ansible.com/t/z-os-ansible-find-multiple-string/6070/6 "2024-07-02T13:11:07Z")

</div>

Closed on July 2, 2024, 1:11pm UTC

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