Getting started with the analysis of the deployment results

You can analyze the Wazi Deploy deployment process and the content of the target deployment environment to create reports. For example, you can list the names of the deployed artifacts or the names of the environments where a specified artifact was deployed.

When the Wazi Deploy building blocks are run with The Ansible deployment command or The Python deployment command, data about the deployment steps implemented by these building blocks is automatically documented in YAML files. These files are stored to the file system as output files of the deployment commands. The documented data, named evidences, can be for example the name, path, or type of a deployed artifact, the result of the execution of a deployment step, or some deployment-related data (such as the timestamp or the deployment environment).

You analyze the created evidences by using the Wazi Deploy query language, which requires YAML and possibly Jinja coding. You trigger an analysis with The Wazi Deploy evidence command.

This getting started scenario provides ready-made examples of deployment analyses.

For an easy use of the deployment analysis, predefined queries are provided in the product. For more information, see The predefined queries in the product.

Before you start a deployment analysis

Before you can run the following getting started scenario, you must have completed the scenario in Getting started with a static deployment to get evidence files.

The name of the evidence file is constituted of a prefix, followed by the date and time of the deployment. For Ansible, the prefix is the inventory host. For Python, the prefix is the name in the metadata of the Python environment variables file. The evidence file is stored in a folder named evidences.
Example: If the environment name is zos_env_test and if the deployment completed on 10 May 2023 at 12h45m30s, the complete path of the evidence file is ./evidences/zos_env_test_evidences_20230510_124530.yml.
To start a deployment analysis, complete the following steps:
  1. Locate the folder where the evidence files were generated.

    In this scenario, this folder is designated as evidences.

  2. Navigate to or create a test folder and enter the following command to index the evidence files and make them searchable:
    wazideploy-evidence -df evidences -if indexes i

    This command creates a subfolder named indexes.

Note: All the files that are used as input to the Wazi Deploy deployment evidence command must be UTF-8 encoded.
You are now ready to analyze the contents of the evidence files. You can get started by using the analysis examples that are provided below. Each of these examples is constituted of the following elements:
  1. A query file that contains the extraction criteria for the analysis.
  2. A renderer file that transforms the analysis results into a specified output format such as HTML or JSON. Specifying a renderer is optional. You can remove it by deleting the renderer line at the end of the queries or by commenting this line with a pound (#) sign in the first position of the line. If you do not specify the renderer, the retrieved data is presented in a raw YAML format, which is less compact.
  3. The Wazi Deploy command line that you enter to trigger the analysis.
You can copy and paste the code lines of the following examples, where the following values are used:
  • evidences is the path to the Wazi Deploy evidences
  • CICS is the name of the application
  • zos_env_test is the name of the environment
  • LGIPOL01 is the name of an artifact to deploy

List the names of the deployment environments

In this example, you list the names of all the deployment environments that are mentioned in your evidence files. Listing these names is useful because you can then easily copy and paste them as arguments in the analysis command line when you want to base an analysis on a specified name.

Complete the following tasks for this analysis:

  1. Create an env-names.yml query file with the following contents:
    ---
    select:
       metadata:
          annotations:
             environment_name: '*'
    output:
       unique: true
       fields:
          metadata:
             annotations:
                environment_name: +1
    renderer: env-names-renderer.yml
  2. Create an env-names-renderer.yml renderer file with the following contents:
    Environments:
    {% for result in results %}- {{result.metadata.annotations.environment_name}}
    {% endfor %}
  3. Enter the following command line to trigger the analysis:
    wazideploy-evidence -q env-names.yml -if indexes -o - r
    This command lists the names of your deployment environments in the console:
    Environments:
    - zos_env_test

List the names of the deployed applications

In this example, you list the names of all the deployed applications that are mentioned in your evidence files. Listing these names is useful because you can then easily copy and paste them as arguments in the analysis command line when you want to base an analysis on a specified name.

Complete the following tasks for this analysis:

  1. Create an app-names.yml query file with the following contents:
    ---
    select:
       metadata:
          name: '*'
    output:
       unique: true
       fields:
          metadata:
             name: +1
    renderer: app-names-renderer.yml
  2. Create an app-names-renderer.yml renderer file with the following contents:
    Applications:
    {% for result in results %}- {{result.metadata.name}}
    {% endfor %}
  3. Enter the following command line to trigger the analysis:
    wazideploy-evidence -q app-names.yml -if indexes -o - r
    This command lists the names of the deployed applications in the console:
    Applications:
    - CICS

List the names of the deployed artifacts with a parameterized query

In this example, you list the names of the deployed artifacts that are mentioned in your evidence files. Listing these names is useful because you can then easily copy and paste them as arguments in the analysis command line when you want to base an analysis on a specified name. This example uses a parameterized query that enables you to specify arguments in the command line.

Complete the following tasks for this analysis:

  1. Create an artifact-names.yml query file with the following contents:
    ---
    select:
       ymli_category~: ^ activities:[0-9]* actions:[0-9]* steps:[0-9]* artifacts:[0-9]* $
       name: '*'
    #{% if type is defined %}
       properties:
          key: type
          value: '{{type}}*'
    #{% endif %}
    #{% if app is defined %}
       ymli_parent:
          metadata:
             name: '{{app}}*'
    #{% endif %}
    #{% if env is defined %}
       ymli_parent:
          metadata:
             annotations:
                environment_name: '{{env}}*'
    #{% endif %}
    output:
       unique: true
       fields:
          name: +1
          properties:
            key: true
            value: true
    renderer: artifact-names-renderer.yml
  2. Create an artifact-names-renderer.yml renderer file with the following contents:
    {% if type is defined -%}
    {% if env is defined -%}
    {% if app is defined -%}
    Artifacts of type {{type}} for application {{app}} in environment {{env}}:
    {% else -%}
    Artifacts of type {{type}} in environment {{env}}:
    {% endif -%}
    {% else -%}
    {% if app is defined -%}
    Artifacts of type {{type}} for {{app}}:
    {% else -%}
    Artifacts of type {{type}}:
    {% endif -%}
    {% endif -%}
    {% else -%}
    {% if env is defined -%}
    {% if app is defined -%}
    Artifacts for {{app}} in {{env}}:
    {% else -%}
    Artifacts in {{env}}:
    {% endif -%}
    {% else -%}
    {% if app is defined -%}
    Artifacts for {{app}}:
    {% else -%}
    Artifacts:
    {% endif -%}
    {% endif -%}
    {% endif -%}
    {% for result in results %}- {{result.name}}.{{result.properties | selectattr('key', 'equalto', 'type') | map(attribute='value') | list | first }}
    {% endfor %}
  3. Enter one of the following command lines to trigger the analysis and display the result in the console.
    • Enter the following command line to display the names of all the deployed artifacts.
      wazideploy-evidence -q artifact-names.yml -if indexes -o - r
      This command lists the names of the deployed artifacts in the console:
      Artifacts:
      - SSMAP.MAPLOAD
      - LGUPVS01.CICSLOAD
      - LGUPOL01.CICSLOAD
      - LGUPDB01.DBRM
      - LGUPDB01.CICSLOAD
      - LGUCVS01.CICSLOAD
      - LGUCUS01.CICSLOAD
      - LGUCDB01.DBRM
      - LGUCDB01.CICSLOAD
      - LGSTSQ.CICSLOAD
      - LGSETUP.CICSLOAD
      - LGIPVS01.CICSLOAD
      - LGIPOL01.CICSLOAD
      - LGIPDB01.DBRM
      - LGIPDB01.CICSLOAD
      - LGICVS01.CICSLOAD
      - LGICUS01.CICSLOAD
      - LGICDB01.DBRM
      - LGICDB01.CICSLOAD
      - LGDPVS01.CICSLOAD
      - LGDPOL01.CICSLOAD
      - LGDPDB01.DBRM
      - LGDPDB01.CICSLOAD
      - LGAPVS01.CICSLOAD
      - LGAPOL01.CICSLOAD
      - LGAPDB01.DBRM
      - LGAPDB01.CICSLOAD
      - LGACVS01.CICSLOAD
      - LGACUS01.CICSLOAD
      - LGACDB02.DBRM
      - LGACDB02.CICSLOAD
      - LGACDB01.DBRM
      - LGACDB01.CICSLOAD
      
    • Enter the following command line to display the names of the deployed artifacts that have a CICSLOAD type.
      wazideploy-evidence -q artifact-names.yml -if indexes -o - r type=CICSLOAD
    • Enter the following command line to display the names of the deployed artifacts of a specified application (CICS in the example). To know all the application names that you can specify, refer to the list that was produced by the command that listed the application names.
      wazideploy-evidence -q artifact-names.yml -if indexes -o - r app=CICS 
    • Enter the following command line to display the names of the deployed artifacts in a specified environment (zos_env_test in the example). To know all the environment names that you can specify, refer to the list that was produced by the command that listed the environment names.
      wazideploy-evidence -q artifact-names.yml -if indexes -o - r env=zos_env_test
    • Enter the following command line to combine the previous three arguments (type, application name, and environment name).
      wazideploy-evidence -q artifact-names.yml -if indexes -o - r type=CICSLOAD app=CICS env=zos_env_test

List basic information about the deployments

In this example, you list basic information about each deployment in a .csv file. This information is constituted of the name of the application, the name of the environment, and the deployment timestamp. This example uses a parameterized query that enables you to specify arguments in the command line.

Complete the following tasks for this analysis:

  1. Create a deployments.yml query file with the following contents:
    ---
    select:
      kind: Evidence
      activities:
        actions:
          steps:
            artifacts:
              #{% if artifact is defined %}
              name: '{{artifact}}'
              #{% else %}
              name: '*'
              #{% endif %}
      metadata:
        #{% if app is defined %}
        name: '{{app}}'
        #{% else %}
        name: '*'
        #{% endif %}
        #{% if env is defined %}
        annotations:
          environment_name: '{{env}}'
        #{% endif %}
    output:
      fields:
        metadata:
          name: true
          annotations:
             environment_name: true
             deploy_timestamp: -1
        activities:
          actions:
            steps:
              artifacts:
                name: true
                properties:
                  key: true
                  value: true
        status: true
    #{% if renderer is defined %}
    renderer: '{{renderer}}'
    #{% endif %}
  2. Create a deployments-renderer.csv renderer file with the following contents:
    Application; Environment; Deploy Date; Status; Artifacts;
    {% set artifacts = [] -%}
    {%- for result in results -%}
    {%- for activity in result.activities -%}
    {%- for action in activity.actions -%}
    {%- for step in action.steps -%}
    {%- for artifact in step.artifacts -%}
    {%- set type = artifact.properties | selectattr('key', 'equalto', 'type') | map(attribute='value') | list | first -%}
    {%- set artifacts = artifacts.append(artifact.name+'.'+type) -%}
    {%- endfor -%}
    {%- endfor -%}
    {%- endfor -%}
    {%- endfor -%}
    {{result.metadata.name}}; {{result.metadata.annotations.environment_name}}; {{result.metadata.annotations.deploy_timestamp}}; {{ result.status }}; {{ artifacts | unique| join(' ') }}
    {% endfor %}
  3. Enter one of the following command lines to trigger the analysis and display the result in a .csv file, which will be created. This file is named deployments.csv in the examples.
    • Enter the following command line to list the basic information for all the deployments.
      wazideploy-evidence -q deployments.yml -if indexes -o deployments.csv r renderer=deployments-renderer.csv
    • Enter the following command line to list the basic information for the deployments in a specified environment (zos_env_test in the example).
      wazideploy-evidence -q deployments.yml -if indexes -o deployments.csv r env=zos_env_test renderer=deployments-renderer.csv
    • Enter the following command line to list the basic information for the deployments of a specified application (CICS in the example).;
      wazideploy-evidence -q deployments.yml -if indexes -o deployments.csv r app=CICS renderer=deployments-renderer.csv
    • Enter the following command line to list the basic information for the deployments that include a specified artifact (LGIPOL01 in the example).
      
      wazideploy-evidence -q deployments.yml -if indexes -o deployments.csv r artifact=LGIPOL01 renderer=deployments-renderer.csv

Populate a SQL database with a SQL renderer

In this example, you use the Wazi Deploy deployment analysis to generate the SQL statements to persist information in a database. You use a SQL renderer. This basic sample uses Db2 Community Edition for Docker.

Complete the following tasks for this analysis:

  1. Create a deployments-renderer.sql renderer file with the following contents:
    CONNECT TO DEPLOY;
    {% set artifacts = [] -%}
    {%- for result in results -%}
    {%- for activity in result.activities -%}
    {%- for action in activity.actions -%}
    {%- for step in action.steps -%}
    {%- for artifact in step.artifacts -%}
    {%- set type = artifact.properties | selectattr('key', 'equalto', 'type') | map(attribute='value') | list | first -%}
    {%- set artifacts = artifacts.append(artifact.name+'.'+type) -%}
    {%- endfor -%}
    {%- endfor -%}
    {%- endfor -%}
    {%- endfor -%}
    INSERT INTO DEPLOY values ('{{result.metadata.name}}', '{{result.metadata.annotations.environment_name}}', '{{result.metadata.annotations.deploy_timestamp}}', '{{result.status}}', '{{ artifacts| unique| join(' ') }}');
    {% endfor %}
  2. Enter the following command lines to trigger the analysis and display the result in a .sql file, which will be created. This file is named deployments.sql in the examples.
    1. Enter the following command line to list the basic information for all the deployments.
      wazideploy-evidence -q deployments.yml -if indexes -o deployments.sql r renderer=deployments-renderer.sql
    2. In your db2 instance, create a create_db.sql SQL script file with the following contents:
      DROP DATABASE DEPLOY;
      CREATE DATABASE DEPLOY;
      CONNECT TO DEPLOY;
      CREATE TABLE DEPLOY (
       APPLICATION_NAME VARCHAR(50) NOT NULL,
       ENVIRONMENT_NAME VARCHAR(50) NOT NULL,
       CREATION_DATE VARCHAR(50),
       STATUS VARCHAR(10),
       ARTIFACTS_NAME VARCHAR(1000) NOT NULL
      );
    3. Enter the following command line to create the database.
      db2 -stvf create_db.sql
    4. Enter the following command line to populate the database with the contents of deployments.sql.
      db2 -stvf deployments.sql
    5. You can now query the db2 database with the following sample commands.
      db2 "SELECT APPLICATION_NAME,ENVIRONMENT_NAME,CREATION_DATE,STATUS  FROM DEPLOY WHERE REGEXP_LIKE(ARTIFACTS_NAME,'LGAPVS01.CICSLOAD') = 1"
      db2 "SELECT APPLICATION_NAME,ENVIRONMENT_NAME,CREATION_DATE,STATUS  FROM DEPLOY WHERE REGEXP_LIKE(STATUS,'Failed') = 1"
      db2 "SELECT APPLICATION_NAME,ENVIRONMENT_NAME,CREATION_DATE,STATUS  FROM DEPLOY WHERE REGEXP_LIKE(APPLICATION_NAME,'CICS') = 1"

Create your own deployment analysis files

To create your own deployment analysis, you must use the Wazi Deploy query language. For more information, see The query language for the deployment analysis.