template

With this building block, you can write templates to create shell scripts, JCLs, or any type of file. This building block is not related to artifacts.

You create your own templates in the folder of your choice. You must write them in Jinja2. For more information, see the Jinja2 documentation.

Then, you run the template building block to transform the Jinja2 files into the target files.

To trigger the execution of this building block, you can enter the following code in the deployment method from which the deployment plan is generated. See How to trigger the execution of a building block. The following code is an example.
actions:
    - name: CREATE FILES FROM A TEMPLATE
      short_name: CREATE_FROM_TEMPLATE 
      steps:
      - name: TEST STEP FOR TEMPLATE
        short_name: TEST_TEMPLATE
        properties:
        - key: template
          value: template
        - key: var_template_name
          value: templ01jcl

In this example, the value of the var_template_name property is templ01jcl, but it can be any other string.

To run correctly, this building block requires environment variables. Indicate them in a .yml file. Indicate The generic environment variables for the Ansible and Python building blocks and adapt their values to your target z/OS environment. Indicate also the variables that are specific to this building block.

The Ansible variables

In the Ansible variables file, you must assign values to the specific variables that are used by the var_template_name property:
  • The src variable, which indicates a full or relative path to the Jinja2 source file, named a Jinja2 template, on the Ansible controller. This variable is required.

    To know how to define the variables in your Jinja2 template, see Coding the variables in the Jinja2 templates.

  • The dest variable, which indicates a full or relative path to the target file to be created on the Ansible controller. This variable is required.
  • The mode variable, which indicates the permissions on the target file. For example, it can be 0755. This variable is optional.
  • The owner variable, which indicates the default name of the user that the target file belongs to. This variable is optional.
  • The group variable, which indicates the default name of the group that the target file belongs to. This variable is optional.
For example, in the deployment method sample code, you declared templ01jcl as the value of the var_template_name property. So, you can enter the following lines in the variables file:
templ01jcl:
  src: "source_templates/test01-jcl.j2"
  dest: "source_templates/test01.jcl
  mode: 0777
  owner: testuser
  group: test_team
If you did not indicate a var_template_name property in the deployment method, then the template_name_default group variable is used. This variable must be declared in the environment variables file.
For example, you can declare the template_name_default variable with the following values in the environment variables file:
template_name_default:
   src: "spec_templates/ex01-sh.j2"
   dest: "spec_templates/ex01.sh"
   owner: user01
   group: wd_devteam
   mode: 0755

The Python variables

To run this building block, indicate the following specific variables in a Python environment variables file. The whole path to this file is indicated in the --envFile argument of The Python deployment command.

The var_template_name property uses the following variables:
  • The src variable, which indicates a full or relative path to the Jinja2 source file, named a Jinja2 template, on the local file system. This variable is required.

    To know how to define the variables in your Jinja2 template, see Coding the variables in the Jinja2 templates.

  • The dest variable, which indicates a full or relative path to the target file to be created on the Ansible controller. This variable is required.
  • The mode variable, which indicates the permissions on the target file. For example, it can be 0755. This variable is optional.
For example, in the deployment method sample code, you declared templ01jcl as the value of the var_template_name property. So, you can enter the following lines in the variables file:
templ01jcl:
  src: "source_templates/test01-jcl.j2"
  dest: "wd_test/inventory_hostname_test01.jcl"
  mode: 0777
If you did not indicate a var_template_name property in the deployment method, then the template_name_default group variable is used. This variable must be declared in the environment variables file.
For example, you can declare the template_name_default variable with the following values in the environment variables file:
template_name_default:
   src: "HELLO-jcl.j2"
   dest: "/tmp/my_jcl/HELLO.jcl"
   mode: 0755

Return values

The result of each building block task is displayed in the evidence file, in The results level that is embedded in step_result.