Skip to content

Commit 2f2296c

Browse files
Custom templating fix (#156)
* Add integration test for custom templating * Change template to do_template * Add doc note for templating limitation and correct ansible-core version in requirements
1 parent 5ea2403 commit 2f2296c

File tree

9 files changed

+125
-2
lines changed

9 files changed

+125
-2
lines changed

docs/source/modules.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ To override the data set location or name for a specific task, you can provide a
6060
additional parameter to the ``region_data_sets`` group as shown in the example
6161
for a global catalog data set below.
6262

63+
N.B. There is a known limitation with ansible-core version 2.15.0 and 2.15.1, where the custom templating may fail.
64+
6365
.. code-block:: yaml+jinja
6466

6567

docs/source/requirements.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ A control node is any machine with Ansible® installed. You can run commands and
1717

1818
The following software must be installed on the control node:
1919

20-
* `Ansible version`_ 2.14 or later
20+
* `Ansible version`_ 2.15 or later
2121
* `Python`_ 3.9 or later
2222
* z/OS core collection 1.5.0 or later, if you want to use the provisioning tasks provided by the **IBM® z/OS® CICS® collection**
2323

plugins/plugin_utils/_module_action_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def _template_dsn(_templar, task_vars, var_name, replace_val, template):
155155
variable_start_string="<<",
156156
variable_end_string=">>",
157157
available_variables=cpy,
158-
).template(template)
158+
).do_template(template, overrides=dict(variable_start_string="<<", variable_end_string=">>"))
159159

160160

161161
def _check_template(module_args, arg_dict):
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# (c) Copyright IBM Corp. 2025
2+
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
3+
---
4+
- name: Test custom templating
5+
hosts: all
6+
gather_facts: false
7+
environment: "{{ environment_vars }}"
8+
9+
# The data set path is cretaed from {{ ansible_user }}.{{ data_set_unique }}.<< data_set_name >>
10+
# e.g. USER.TEST1.DFHTEMP
11+
vars:
12+
data_set_unique: "{{ region_data_set_unique }}"
13+
14+
tasks:
15+
- name: Create and delete auxiliary temporary storage data set
16+
ansible.builtin.include_role:
17+
name: aux_temp_storage
18+
vars:
19+
aux_temp_region_data_set_hlq: "{{ data_set_unique }}"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# (c) Copyright IBM Corp. 2025
2+
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
3+
4+
from __future__ import (absolute_import, division, print_function)
5+
__metaclass__ = type
6+
7+
from ansible.plugins.action import ActionBase
8+
9+
10+
class ActionModule(ActionBase):
11+
12+
# Simple action plugin that just returns the ansible_user var
13+
14+
def run(self, tmp=None, task_vars=None):
15+
super(ActionModule, self).run(tmp, task_vars)
16+
17+
processed_ouput = {
18+
"name": task_vars["ansible_user"]
19+
}
20+
21+
return processed_ouput
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# (c) Copyright IBM Corp. 2025
2+
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
3+
---
4+
argument_specs:
5+
main:
6+
short_description: Templating test
7+
description:
8+
- Test custom templating
9+
author:
10+
- ibm_zos_cics
11+
options:
12+
aux_temp_region_data_set_hlq:
13+
type: "str"
14+
required: false
15+
description: "HLQ to create the auxiliary temporary storage data set"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# (c) Copyright IBM Corp. 2025
2+
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
3+
---
4+
galaxy_info:
5+
author: ibm_zos_cics
6+
description: Templating test
7+
company: IBM
8+
license: Apache-2.0
9+
min_ansible_version: "2.1"
10+
galaxy_tags: []
11+
dependencies: []
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# (c) Copyright IBM Corp. 2025
2+
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
3+
---
4+
- name: Process Input data
5+
process_input:
6+
register: processed_input
7+
8+
- name: Delete the DFHTEMP data set if it exists already
9+
ibm.ibm_zos_core.zos_data_set:
10+
name: "{{ processed_input.name }}.{{ aux_temp_region_data_set_hlq }}.DFHTEMP"
11+
state: absent
12+
13+
- name: Create the auxiliary temporary storage data set (DFHTEMP)
14+
ibm.ibm_zos_cics.aux_temp_storage:
15+
state: initial
16+
region_data_sets:
17+
template: "{{ processed_input.name }}.{{ aux_temp_region_data_set_hlq }}.<< data_set_name >>"
18+
register: result
19+
20+
- name: Assert data set created
21+
ansible.builtin.assert:
22+
that:
23+
- result.failed == false
24+
- result.changed == true
25+
- result.start_state.exists == false
26+
- result.end_state.exists == true
27+
- result.msg == ""
28+
29+
- name: Delete the auxiliary temporary storage data set (DFHTEMP)
30+
ibm.ibm_zos_cics.aux_temp_storage:
31+
state: absent
32+
region_data_sets:
33+
template: "{{ processed_input.name }}.{{ aux_temp_region_data_set_hlq }}.<< data_set_name >>"
34+
register: result
35+
36+
- name: Assert data set deleted (changed is true)
37+
ansible.builtin.assert:
38+
that:
39+
- result.failed == false
40+
- result.changed == true
41+
- result.start_state.exists == true
42+
- result.end_state.exists == false
43+
- result.msg == ""
44+
- "'executions' in result"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
# (c) Copyright IBM Corp. 2025
3+
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
4+
5+
set -eux
6+
7+
VAR_PATH="$ANSIBLE_COLLECTIONS_PATH/ansible_collections/ibm/ibm_zos_cics/tests/integration/variables/provisioning.yml"
8+
INV_PATH="$ANSIBLE_COLLECTIONS_PATH/ansible_collections/ibm/ibm_zos_cics/tests/integration/inventory_zos.yml"
9+
ZOS_ENV="$ANSIBLE_COLLECTIONS_PATH/ansible_collections/ibm/ibm_zos_cics/tests/integration/variables/zos.yml"
10+
11+
ansible-playbook -i "$INV_PATH" -e "@$VAR_PATH" -e "@$ZOS_ENV" playbook.yml

0 commit comments

Comments
 (0)