ansible-collections / ibm_zos_core

Red Hat Ansible Certified Content for IBM Z
76 stars 44 forks source link

[Bug] [zos_lineinfile] is unable to use advanced regular expressions #913

Open ddimatos opened 1 year ago

ddimatos commented 1 year ago

Is there an existing issue for this?

Are the dependencies a supported version?

IBM Z Open Automation Utilities

v1.2.3

IBM Enterprise Python

v3.9.x

IBM z/OS Ansible core Version

v1.6.0

ansible-version

v2.15.x

z/OS version

v2.5

Ansible module

zos_lineinfile

Bug description

I have a data set with content

D160882
D160882 with more info
ED160882
This is a line 

When using a regex to match like so regexp: '[A-Za-z][0-9]{6}' , no match occurs yet if i change the regex to a compatible string like regexp: 'D160882' it matches.

This issue has been diagnosed and exists in ZOAU, thus this git issue is in place to add a test case because this should have never passed our regression and to validate a fix when available.

The second part of this issue that needs validating is the response, when I used the regex string match, zoau reported it found 3 {"cmd": "dsedhelper -d -c IBM-1047 /D160882/d ANSIBLE.LISTCAT.INPUT ", "found": 3, "changed": 1} and changed only 1, yet it actually changed 3 by deleting all 3 of these:

D160882
D160882 with more info
ED160882

Related to discussion #907

My recreate is:

    - name: Create seq data set
      zos_data_set:
        name: ANSIBLE.LINEFILE.SEQ
        type: SEQ
        space_primary: 3
        space_type: M
        record_format: FB
        record_length: 1024
        replace: yes
      register: result

    - debug:
       var: result

    - name: Populate data set
      zos_copy:
        content: |1
          D160882
          D160882 with more info
          ED160882
          This is a line
        dest: ANSIBLE.LINEFILE.SEQ
        force: yes
      register: result

    - debug:
       var: result

    - name: Update Data set by deleting a line
      zos_lineinfile:
        src: ANSIBLE.LINEFILE.SEQ
        regexp: '[A-Za-z][0-9]{6}'
        state: absent
      register: result

    - name: Response
      debug:
        msg: "{{ result }}"

    - name: Cat the data set
      command: "dcat 'ANSIBLE.LINEFILE.SEQ'"
      register: result

    - name: Response
      debug:
        msg: "{{ result }}"

Playbook verbosity output.

No response

Ansible configuration.

No response

Contents of the inventory

No response

Contents of group_vars or host_vars

No response

ddimatos commented 1 year ago

Tracker NAZARE-10029

ddimatos commented 10 months ago

Tracker 10029 has updated the doc to include curly braces need to be escaped, this is something we need to try:

 regexp: '[A-Za-z][0-9]\\{6\\}'

Then decide on if this is sufficient to put the onus on users to escape or should we push escaping to down to the utils or dependency.

storfibm commented 10 months ago

Add'l tracker NAZARE-10268 for the 2nd portion of the problem