Creating an Ansible building block
You can extend the Wazi Deploy Ansible® translator that runs the Ansible building blocks. You can create your own Ansible building blocks and call them from the deployment method to implement your own action steps.
This scenario is the continuation of the Static deployment with the Ansible translator scenario.
For example, you might want to implement a new action after the copy to the target PDS. This action submits the JCL that was deployed from the package. Implementing a new action consists in providing a new Ansible task that complies with the Wazi Deploy API.
- Create a folder at the same level as your deploy.yml
Ansible root playbook and name it
tasks. - In this folder, create a
my_job_submit.ymlAnsible building block with the following contents:# From a building block you can access the following variables: # - wd_deployment_plan (dict): The Full Deployment Plan. # - wd_activity (dict): The current activity in the Deployment Plan. # - wd_action (dict): The current action in the Deployment Plan. # - wd_step (dict): The current step in the Deployment Plan. # - wd_log (bool): The verbose output flag. # - wd_deploy_dir_uss: The remote working folder (z/OS). # - wd_deploy_dir_local: The local working folder on the Ansible controller. # - wd_evidences: The evidences at the beginning of the execution of the building block. You can't modify this dictionary. # Job submit sample task --- - name: "[{{current_step_name}}]" collections: - ibm.ibm_zos_core environment: "{{ environment_vars }}" block: - set_fact: joblist_items: "{{ wd_step['artifacts'] |\ ibm.ibm_zos_wazi_deploy.wd_artifact_list (wd_deploy_dir_uss, wd_types, False, True, wd_log )}}" vars: # The types to use in the inventory (default `'types'). It can be overridden in a step in the Deployment Method wd_var_type: "{{ wd_step | json_query (\"properties[?key == 'var_type'].value\") | first | default('types') }}" wd_types: "{{ lookup('vars', wd_var_type )}}" - name: "[{{current_step_name}}]: Submit JOBs" with_items: "{{ joblist_items | default([]) }}" zos_job_submit: src: "{{item.src}}" location: DATA_SET max_rc: 4 tags: - my_job_submit - At the end of the static-deployment-method.yml deployment method, add the
following activity to submit the JCL that was deployed from the
package:
- name: "Job Submit Activity" description: | This activity will submit JOBs in the package actions: - name: "Job Submit Action" states: - UNDEFINED steps: - name: "Job Submit Action" properties: - key: template value: my_job_submit types: - name: 'jcl' is_artifact: True - Provide a new .tar file named package.v3.tar.
This file must contain a JCL with the .jcl extension.In order for the JCL to be correctly processed, add the new JCL type definition in the Ansible environment variables file in inventories/group_vars/all.yml.
- Enter the common characteristics for this new type as
follows:
common_pds_text_spec: type: LIBRARY space_primary: 5 space_secondary: 10 space_type: CYL record_format: FB record_length: 80 - Under the types root variable, enter the jcl
type as follows:
types: - type: 'jcl' pds: name: '{{ hlq }}.JCL' spec: "{{common_pds_text_spec}}" backup: '{{ hlq }}.BACK.JCL' # encoding: # from: UTF-8 # to: IBM-1047
- Enter the common characteristics for this new type as
follows:
- Generate the deployment plan with the following
command:
wazideploy-generate -dm static-deployment-method.yml -dp deployment_plan.yml -pif package.v3.tar - Trigger the deployment of the last version of the package by entering the following
commands:
ansible-playbook \ deploy.yml\ -i inventories\ -e wd_deployment_plan_file=deployment_plan.yml\ -e wd_package_file=package.v3.tar
At this stage, the JCLs should be deployed and automatically submitted.