Generating Operator Report in Red Hat Openshift cluster version : 4.14.31

Hello Team,
I’m Evarist from Canada fairly new with Ansible reporting.

Objective:
I want to generate a report in openshift with jinja template for operators installed and available operators version from openshift marketplace.
openshift version : 4.14.31

  • mycode

  • name: “Operator Report”
    hosts: localhost
    gather_facts: false
    vars:
    template_src: op-report.csv.j2
    report_dest: /tmp/report.csv

    tasks:

    • name: get cluster installed operator in csv
      kubernetes.core.k8s_info:
      api_version: operators.coreos.com/v1alpha1
      kind: ClusterServiceVersion
      register: operator

    • name: Get available operators Packagemanifest in Marketplace
      kubernetes.core.k8s_info:
      api_version: packages.operators.coreos.com/v1
      kind: PackageManifest
      register: package

    • name: Output the report with the template
      ansible.builtin.template:
      src: “{{ template_src }}”
      dest: “{{ report_dest }}”


My j2 template:
$ cat op-report.csv.j2
Marketplace Operators,Marketplace Catalog Source Publisher,Marketplace Operator version,Installed Operators version
{% for PackageManifest in package.resources %}
{{ PackageManifest.metadata.name }}, {{ PackageManifest.status.catalogSourcePublisher }}, {{ PackageManifest.status.channels[0].currentCSV}}
{% endfor %}


Success:
This jinja template is able to produce the required report for marketplace place operators details by looping in the “register: package variable” and print the result in csv column as reference in the j2 template correctly.
“Marketplace Operators,Marketplace Catalog Source Publisher,Marketplace Operator version”

Question/Issue:
How can i pass the second variable “register: operator” in the Jinja template so it can loop and print the installed operator in the clusterserviceversion onto the column “Installed Operators version” as reference in the jinja template in the same csv file?

Your help will be much appreciated.
Thanks

CSV report for marketplace operators generated.