Some of the more advanced regular expressions which are valid don't work with underlying dependency, this issue aims to update the documentation with equivalents or if that can not be achieved, remove them and consider new examples.
For example, many of the examples use \d this seems to be failing, one could use [0-9] , for example dsed -d -c IBM-1047 '/^(.*)Xms(\d+)m(.*)$/d' "ANSIBLE.TEST.PDS(MEMBER2)" could be replaced with one of the ones below but neither work:
We need to come up with new examples within the limitations of the dependency.
You an also view some of my examples here.
Also as part of this work item, describe our regex limitations in such a way it makes sense, the dependency will be determining their limitations. For example this description should get updated to not set expectations that all expressions are handled:
regexp
The regular expression to look for in every line of the USS file or data set.
For state=present, the pattern to replace if found. Only the last line found will be replaced.
For state=absent, the pattern of the line(s) to remove.
If the regular expression is not matched, the line will be added to the USS file or data set in keeping with insertbefore or insertafter settings.
When modifying a line the regexp should typically match both the initial state of the line as well as its state after replacement by line to ensure idempotence.
required: False
type: str
Lastly I am including a rough playbook that I used to validate the examples, it uses ansible --tags so not all the tasks will run , as you should run them individually.
---
- hosts: zvm
collections:
- ibm.ibm_zos_core
gather_facts: false
environment: "{{ environment_vars }}"
tasks:
# ------------------------------------------------
# Load the data set with something to test against
# ------------------------------------------------
- name: Create a PDS data set if it does not exist
zos_data_set:
name: ANSIBLE.TEST.PDS
type: pds
space_primary: 5
space_type: M
record_format: fba
record_length: 144
replace: yes
volumes: "DIMATO"
register: result
tags: setup_pds
- name: Results
debug:
var: result
tags: setup_pds
- name: Create a MEMBER
zos_data_set:
name: ANSIBLE.TEST.PDS(MEMBER1)
state: present
replace: true
type: MEMBER
register: result
tags: setup_mem_1
- name: Results
debug:
var: result
tags: setup_mem_1
# Each line will start with space
- name: Put data on pdse MEMBER1
zos_copy:
content: |
//HELLO JOB (T043JM,JM00,1,0,0,0),'HELLO WORLD - JRM',
// MSGCLASS=H,MSGLEVEL=1,NOTIFY=&SYSUID
//*
//STEP0001 EXEC PGM=IEBGENER
//SYSIN DD DUMMY
//SYSPRINT DD SYSOUT=*
#/SYSUT1 DD *
HELLO, WORLD
/*
//SYSUT2 DD SYSOUT=*
//
dest: ANSIBLE.TEST.PDS(MEMBER1)
force: yes
register: result
tags: setup_mem_1
- name: Results
debug:
var: result
tags: setup_mem_1
# (1) Same as: dsed -d -c IBM-1047 '/^SYSOUT=/c\\SYSOUT=FOOBAR/$' "ANSIBLE.TEST.PDS(MEMBER1)"
- name: Set value of a variable SYSOUT equal to FOOBAR, does not work
zos_lineinfile:
src: ANSIBLE.TEST.PDS(MEMBER1)
state: present
regexp: '^SYSOUT='
line: "SYSOUT=FOOBAR"
register: result
tags: task_1
- name: Results
debug:
var: result
tags: task_1
- name: Use ZOAU 'dcat' to show data after editing
command: "dcat 'ANSIBLE.TEST.PDS(MEMBER1)'"
register: result
tags: task_1
- name: Response
debug:
msg: "{{ result.stdout_lines }}"
tags: task_1
# (2) dsed -d -c IBM-1047 '/^#/d' "ANSIBLE.TEST.PDS(MEMBER1)"
- name: Remove all lines that begin with a single space followed by hash tag using '^ #' works
zos_lineinfile:
src: ANSIBLE.TEST.PDS(MEMBER1)
state: absent
regexp: '^ #'
register: result
tags: task_2
- name: Results
debug:
var: result
tags: task_2
- name: Use ZOAU 'dcat' to show data after editing
command: "dcat 'ANSIBLE.TEST.PDS(MEMBER1)'"
register: result
tags: task_2
- name: Response
debug:
msg: "{{ result.stdout_lines }}"
tags: task_2
# (3) dsed -d -c IBM-1047 '/^[ \\t]+/d' "ANSIBLE.TEST.PDS(MEMBER1)"
- name: Remove all lines that begin with a space using '^[ \t]+' does not work
zos_lineinfile:
src: ANSIBLE.TEST.PDS(MEMBER1)
state: absent
regexp: '^[ \t]+'
register: result
tags: task_3
- name: Results
debug:
var: result
tags: task_3
- name: Use ZOAU 'dcat' to show data after editing
command: "dcat 'ANSIBLE.TEST.PDS(MEMBER1)'"
register: result
tags: task_3
- name: Response
debug:
msg: "{{ result.stdout_lines }}"
tags: task_3
# (4) dsed -d -c IBM-1047 '/^#/d' "ANSIBLE.TEST.PDS(MEMBER1)"
- name: Remove all lines that begin with a space using '^ ' works.
zos_lineinfile:
src: ANSIBLE.TEST.PDS(MEMBER1)
state: absent
regexp: '^ '
register: result
tags: task_4
- name: Results
debug:
var: result
tags: task_4
- name: Use ZOAU 'dcat' to show data after editing
command: "dcat 'ANSIBLE.TEST.PDS(MEMBER1)'"
register: result
tags: task_4
- name: Response
debug:
msg: "{{ result.stdout_lines }}"
tags: task_4
- name: Create a MEMBER
zos_data_set:
name: ANSIBLE.TEST.PDS(MEMBER2)
state: present
replace: true
type: MEMBER
register: result
tags: setup_mem_2
- name: Results
debug:
var: result
tags: setup_mem_2
- name: Put data on pdse MEMBER2
zos_copy:
content: |
#JAVA_OPTS
JAVA_OPTS="-Xms64m -Xmx1G -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=512m -Djava.net.preferIPv4Stack=true"
dest: ANSIBLE.TEST.PDS(MEMBER2)
force: yes
register: result
tags: setup_mem_2
- name: Results
debug:
var: result
tags: setup_mem_2
# (5) dsed -d -c IBM-1047 '/^(.*)Xms(\\d+)m(.*)$/d' "ANSIBLE.TEST.PDS(MEMBER2)"
- name: Remove all comments in the USS file
zos_lineinfile:
src: ANSIBLE.TEST.PDS(MEMBER2)
state: absent
regexp: '^(.*)Xms(\d+)m(.*)$'
force: true
register: result
tags: task_5
- name: Results
debug:
var: result
tags: task_5
- name: Use ZOAU 'dcat' to show data after editing
command: "dcat 'ANSIBLE.TEST.PDS(MEMBER2)'"
register: result
tags: task_5
- name: Response
debug:
msg: "{{ result.stdout_lines }}"
tags: task_5
# (6) This one fails as well, it differs from task_5 in that it will execute multiple sed commands
- name: Remove all comments in the USS file
zos_lineinfile:
src: ANSIBLE.TEST.PDS(MEMBER2)
state: absent
regexp: '^(.*)Xms(\d+)m(.*)$'
insertafter: '^#JAVA_OPTS'
line: JAVA_OPTS="-Xms128m -Xmx1G -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=512m -Djava.net.preferIPv4Stack=true"
register: result
tags: task_6
- name: Results
debug:
var: result
tags: task_6
- name: Use ZOAU 'dcat' to show data after editing
command: "dcat 'ANSIBLE.TEST.PDS(MEMBER2)'"
register: result
tags: task_6
- name: Response
debug:
msg: "{{ result.stdout_lines }}"
tags: task_6
# (7) dsed -d -f -c IBM-1047 '$ a\\Forcing an update on a data set that is locked' "ANSIBLE.TEST.PDS(MEMBER1)"
- name: Add a line to a member PDS is in use
zos_lineinfile:
src: ANSIBLE.TEST.PDS(MEMBER1)
insertafter: EOF
line: 'Forcing an update on a data set that is locked'
force: True
register: result
tags: task_7
- name: Results
debug:
var: result
tags: task_7
- name: Use ZOAU 'dcat' to show data after editing is working
command: "dcat 'ANSIBLE.TEST.PDS(MEMBER1)'"
register: result
tags: task_7
- name: Response
debug:
msg: "{{ result.stdout_lines }}"
tags: task_7
Is there an existing issue for this?
Are the dependencies a supported version?
IBM Z Open Automation Utilities
v1.2.5
IBM Enterprise Python
v3.10.x
IBM z/OS Ansible core Version
v1.8.0-beta.1
ansible-version
v2.15.x
z/OS version
v2.5
Ansible module
zos_lineinfile
Bug description
Some of the more advanced regular expressions which are valid don't work with underlying dependency, this issue aims to update the documentation with equivalents or if that can not be achieved, remove them and consider new examples. For example, many of the examples use
\d
this seems to be failing, one could use[0-9]
, for exampledsed -d -c IBM-1047 '/^(.*)Xms(\d+)m(.*)$/d' "ANSIBLE.TEST.PDS(MEMBER2)"
could be replaced with one of the ones below but neither work:See tracker 10417.
We need to come up with new examples within the limitations of the dependency. You an also view some of my examples here.
Also as part of this work item, describe our regex limitations in such a way it makes sense, the dependency will be determining their limitations. For example this description should get updated to not set expectations that all expressions are handled:
Lastly I am including a rough playbook that I used to validate the examples, it uses
ansible --tags
so not all the tasks will run , as you should run them individually.Playbook verbosity output.
No response
Ansible configuration.
No response
Contents of the inventory
No response
Contents of
group_vars
orhost_vars
No response