Skip to content

Commit

Permalink
Update zos_blockinfile with complex examples (#727)
Browse files Browse the repository at this point in the history
* Update zos_blockinfile with complex examples

Signed-off-by: ddimatos <[email protected]>

* Add changelog fragement

Signed-off-by: ddimatos <[email protected]>

---------

Signed-off-by: ddimatos <[email protected]>
  • Loading branch information
ddimatos authored Apr 7, 2023
1 parent 20aad36 commit 1658630
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 6 deletions.
5 changes: 5 additions & 0 deletions changelogs/fragments/727-zos-blockinfile-examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trivial:
- zos_blockinfile - was missing examples using Jinja2 and files. This change
adds a Jinja2 example in both the src and block content. It also includes
an example using a file as source.
(https://github.com/ansible-collections/ibm_zos_core/pull/727)
38 changes: 35 additions & 3 deletions docs/source/modules/zos_blockinfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ src

state
Whether the block should be inserted/replaced (present) or removed (absent).
Whether the block should be inserted or replaced using *state=present*.

Whether the block should be removed using *state=absent*.

| **required**: False
| **type**: str
Expand Down Expand Up @@ -165,7 +167,7 @@ force

This is helpful when a data set is being used in a long running process such as a started task and you are wanting to update or read.

The ``-f`` option enables sharing of data sets through the disposition *DISP=SHR*.
The ``force`` option enables sharing of data sets through the disposition *DISP=SHR*.

| **required**: False
| **type**: bool
Expand Down Expand Up @@ -244,6 +246,36 @@ Examples
LIB('{{ DB2RUN }}.RUNLIB.LOAD')
indentation: 16

- name: Set facts for the following two tasks.
set_fact:
HLQ: 'ANSIBLE'
MLQ: 'MEMBER'
LLQ: 'TEST'
MEM: '(JCL)'
MSG: 'your first JCL program'
CONTENT: "{{ lookup('file', 'files/content.txt') }}"

- name: Update JCL in a PDS member with Jinja2 variable syntax.
zos_blockinfile:
src: "{{ HLQ }}.{{MLQ}}.{{LLQ}}{{MEM}}"
insertafter: "HELLO, WORLD"
marker: "//* {mark} *//"
marker_begin: "Begin Ansible Block Insertion 1"
marker_end: "End Ansible Block Insertion 1"
state: present
block: |
This is {{ MSG }}, and its now
managed by Ansible.
- name: Update JCL in PDS member with content from a file.
zos_blockinfile:
src: "{{ HLQ }}.{{MLQ}}.{{LLQ}}{{MEM}}"
insertafter: "End Ansible Block Insertion 1"
marker: "//* {mark} *//"
marker_begin: "Begin Ansible Block Insertion 2"
marker_end: "End Ansible Block Insertion 2"
block: "{{ CONTENT }}"



Expand All @@ -257,7 +289,7 @@ Notes

For supported character sets used to encode data, refer to the `documentation <https://ibm.github.io/z_ansible_collections_doc/ibm_zos_core/docs/source/resources/character_set.html>`_.

When using 'with_*' loops be aware that if you do not set a unique mark the block will be overwritten on each iteration.
When using ``with_*`` loops be aware that if you do not set a unique mark the block will be overwritten on each iteration.

When more then one block should be handled in a file you must change the *marker* per task.

Expand Down
38 changes: 35 additions & 3 deletions plugins/modules/zos_blockinfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
version_added: '1.3.0'
author:
- "Behnam (@balkajbaf)"
- "Demetrios Dimatos (@ddimatos)"
short_description: Manage block of multi-line textual data on z/OS
description:
- Manage block of multi-lines in z/OS UNIX System Services (USS) files,
Expand All @@ -42,7 +43,8 @@
required: true
state:
description:
- Whether the block should be inserted/replaced (present) or removed (absent).
- Whether the block should be inserted or replaced using I(state=present).
- Whether the block should be removed using I(state=absent).
type: str
choices:
- absent
Expand Down Expand Up @@ -156,7 +158,7 @@
updated by others.
- This is helpful when a data set is being used in a long running process
such as a started task and you are wanting to update or read.
- The C(-f) option enables sharing of data sets through the disposition
- The C(force) option enables sharing of data sets through the disposition
I(DISP=SHR).
required: false
type: bool
Expand All @@ -179,7 +181,7 @@
data sets.
- For supported character sets used to encode data, refer to the
L(documentation,https://ibm.github.io/z_ansible_collections_doc/ibm_zos_core/docs/source/resources/character_set.html).
- When using 'with_*' loops be aware that if you do not set a unique mark
- When using ``with_*`` loops be aware that if you do not set a unique mark
the block will be overwritten on each iteration.
- When more then one block should be handled in a file you must change
the I(marker) per task.
Expand Down Expand Up @@ -245,6 +247,36 @@
RUN PROGRAM(DSNTEP2) PLAN(DSNTEP12) -
LIB('{{ DB2RUN }}.RUNLIB.LOAD')
indentation: 16
- name: Set facts for the following two tasks.
set_fact:
HLQ: 'ANSIBLE'
MLQ: 'MEMBER'
LLQ: 'TEST'
MEM: '(JCL)'
MSG: 'your first JCL program'
CONTENT: "{{ lookup('file', 'files/content.txt') }}"
- name: Update JCL in a PDS member with Jinja2 variable syntax.
zos_blockinfile:
src: "{{ HLQ }}.{{MLQ}}.{{LLQ}}{{MEM}}"
insertafter: "HELLO, WORLD"
marker: "//* {mark} *//"
marker_begin: "Begin Ansible Block Insertion 1"
marker_end: "End Ansible Block Insertion 1"
state: present
block: |
This is {{ MSG }}, and its now
managed by Ansible.
- name: Update JCL in PDS member with content from a file.
zos_blockinfile:
src: "{{ HLQ }}.{{MLQ}}.{{LLQ}}{{MEM}}"
insertafter: "End Ansible Block Insertion 1"
marker: "//* {mark} *//"
marker_begin: "Begin Ansible Block Insertion 2"
marker_end: "End Ansible Block Insertion 2"
block: "{{ CONTENT }}"
'''

RETURN = r"""
Expand Down

0 comments on commit 1658630

Please sign in to comment.