From 1bf9293df3f394b8e3b76902f5626dc12a6e02ee Mon Sep 17 00:00:00 2001 From: matt Date: Tue, 28 May 2024 12:05:52 -0600 Subject: [PATCH] this now --- .../openshift/roles/cluster_config/README.md | 131 ++++++++++++++++++ .../roles/cluster_config/defaults/main.yml | 23 +++ .../roles/cluster_config/handlers/main.yml | 2 + .../roles/cluster_config/meta/main.yml | 52 +++++++ .../roles/cluster_config/tasks/main.yml | 3 + .../cluster_config/tasks/ocp_install/main.yml | 5 + .../tasks/ocp_install/ocp_install.yml | 9 ++ .../cluster_config/tasks/ocp_install/prep.yml | 109 +++++++++++++++ .../tasks/operators/_operator_config_item.yml | 36 +++++ .../tasks/operators/catalog_sources.yml | 6 + .../tasks/operators/node-health-check.yml | 60 ++++++++ .../tasks/operators/operator_config.yml | 6 + .../templates/operators/catalog_source.j2 | 35 +++++ .../templates/operators/namespace.yml.j2 | 10 ++ .../templates/operators/operator_group.yml.j2 | 12 ++ .../templates/operators/subscription.yml.j2 | 14 ++ .../roles/cluster_config/tests/inventory | 2 + .../roles/cluster_config/tests/test.yml | 5 + .../roles/cluster_config/vars/main.yml | 2 + openshift/cnv/install.yml | 10 +- 20 files changed, 531 insertions(+), 1 deletion(-) create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/README.md create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/defaults/main.yml create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/handlers/main.yml create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/meta/main.yml create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/main.yml create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/ocp_install/main.yml create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/ocp_install/ocp_install.yml create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/ocp_install/prep.yml create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/_operator_config_item.yml create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/catalog_sources.yml create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/node-health-check.yml create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/operator_config.yml create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/catalog_source.j2 create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/namespace.yml.j2 create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/operator_group.yml.j2 create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/subscription.yml.j2 create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/tests/inventory create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/tests/test.yml create mode 100644 collections/ansible_collections/demo/openshift/roles/cluster_config/vars/main.yml diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/README.md b/collections/ansible_collections/demo/openshift/roles/cluster_config/README.md new file mode 100644 index 000000000..460d26c0a --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/README.md @@ -0,0 +1,131 @@ +Role Name +========= + +This Ansible role helps configure Operators on the Openshift Cluster to support VM migrations. Tasks include +- Configure Catalog Sources to use mirroring repository for Operators +- Create and configure Operators + + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +The task `operators/catalog_sources.yml` needs following variables: + +- **Variable Name**: `cluster_config_catalog_sources` + - **Type**: List + - **Description**: A list of custom CatalogSources configurations used as loop variables to generate Kubernetes manifest files from the template `catalog_source.j2` for CatalogSource. If the variable is not available, no manifest is created. + - **Example**: + ```yaml + cluster_config_catalog_sources: + - name: redhat-marketplace2 + source_type: grpc + display_name: Mirror to Red Hat Marketplace + image_path: internal-registry.example.com/operator:v1 + priority: '-300' + icon: + base64data: '' + mediatype: '' + publisher: redhat + address: '' + grpc_pod_config: | + nodeSelector: + kubernetes.io/os: linux + node-role.kubernetes.io/master: '' + priorityClassName: system-cluster-critical + securityContextConfig: restricted + tolerations: + - effect: NoSchedule + key: node-role.kubernetes.io/master + operator: Exists + - effect: NoExecute + key: node.kubernetes.io/unreachable + operator: Exists + tolerationSeconds: 120 + - effect: NoExecute + key: node.kubernetes.io/not-ready + operator: Exists + tolerationSeconds: 120 + registry_poll_interval: 10m + ``` + +The task `operators/operator_config.yaml` needs following variables: + +- **Variable Name**: `cluster_config_operators` + - **Type**: List + - **Description**: A list of operators to be installed on OCP cluster +- **Variable Name**: `cluster_config_[OPERATOR_NAME]` + - **Type**: Dict + - **Description**: Configuration specific to each operator listed in `cluster_config_operators`. Includes settings for namespace, operator group, subscription, and any extra resources + - **Example**: Assume the `cluster_config_operators` specifies these operators: + ```yaml + cluster_config_operators: + - cnv + - oadp + ``` + then the corresponding `cluster_config_mtv` and `cluster_config_cnv` can be configured as following: + ```yaml + cluster_config_cnv_namespace: openshift-cnv + cluster_config_cnv: + namespace: + name: "{{ cluster_config_cnv_namespace }}" + operator_group: + name: kubevirt-hyperconverged-group + target_namespaces: + - "{{ cluster_config_cnv_namespace }}" + subscription: + name: kubevirt-hyperconverged + starting_csv: kubevirt-hyperconverged-operator.v4.13.8 + extra_resources: + - apiVersion: hco.kubevirt.io/v1beta1 + kind: HyperConverged + metadata: + name: kubevirt-hyperconverged + namespace: "{{ cluster_config_cnv_namespace }}" + spec: + BareMetalPlatform: true + + cluster_config_oadp_namespace: openshift-adp + cluster_config_oadp: + namespace: + name: "{{ cluster_config_oadp_namespace }}" + operator_group: + name: redhat-oadp-operator-group + target_namespaces: + - "{{ cluster_config_oadp_namespace }}" + subscription: + name: redhat-oadp-operator-subscription + spec_name: redhat-oadp-operator + ``` +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +An example of configuring a CatalogSource resource: +``` +- name: Configure Catalog Sources for Operators + hosts: localhost + gather_facts: false + tasks: + - ansible.builtin.include_role: + name: cluster_config + tasks_from: operators/catalog_sources +``` + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/defaults/main.yml b/collections/ansible_collections/demo/openshift/roles/cluster_config/defaults/main.yml new file mode 100644 index 000000000..6e40fd38d --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/defaults/main.yml @@ -0,0 +1,23 @@ +--- +# defaults file for cluster_config +cluster_config_operators: + - cnv + +cluster_config_cnv: + checkplan: true + namespace: + name: &cluster_config_cnv_namespace openshift-cnv + operator_group: + name: kubevirt-hyperconverged-group + target_namespaces: + - *cluster_config_cnv_namespace + subscription: + name: kubevirt-hyperconverged + extra_resources: + - apiVersion: hco.kubevirt.io/v1beta1 + kind: HyperConverged + metadata: + name: kubevirt-hyperconverged + namespace: *cluster_config_cnv_namespace + spec: + BareMetalPlatform: true diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/handlers/main.yml b/collections/ansible_collections/demo/openshift/roles/cluster_config/handlers/main.yml new file mode 100644 index 000000000..252ae124e --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for cluster_config diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/meta/main.yml b/collections/ansible_collections/demo/openshift/roles/cluster_config/meta/main.yml new file mode 100644 index 000000000..c572acc9f --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/main.yml b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/main.yml new file mode 100644 index 000000000..05fa4d6ec --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/main.yml @@ -0,0 +1,3 @@ +--- +- name: Configure Operators + ansible.builtin.import_tasks: operators/operator_config.yml diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/ocp_install/main.yml b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/ocp_install/main.yml new file mode 100644 index 000000000..195351596 --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/ocp_install/main.yml @@ -0,0 +1,5 @@ +--- +- import_tasks: prep.yml + +- import_tasks: ocp_install.yml +... diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/ocp_install/ocp_install.yml b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/ocp_install/ocp_install.yml new file mode 100644 index 000000000..4def4946e --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/ocp_install/ocp_install.yml @@ -0,0 +1,9 @@ +--- +- name: Run IPI Installer + command: openshift-baremetal-install --dir={{ cluster_deploy_dir }}/{{ cluster_name }} create cluster + register: cluster_deploy + become_user: kni + +- debug: + var: cluster_deploy +... \ No newline at end of file diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/ocp_install/prep.yml b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/ocp_install/prep.yml new file mode 100644 index 000000000..bf3b1fceb --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/ocp_install/prep.yml @@ -0,0 +1,109 @@ +--- +- name: Create new sudo user + shell: | + useradd kni + passwd kni + echo "kni ALL=(root) NOPASSWD:ALL" | tee -a /etc/sudoers.d/kni + chmod 0440 /etc/sudoers.d/kni + su - kni -c "ssh-keygen -t ed25519 -f /home/kni/.ssh/id_rsa -N ''" + become: true + +- name: Register provisioner node with RH subscription manager + shell: | + sudo subscription-manager register --username={{ rh_subscription_manager_user }} --password={{ rh_subscription_manager_pass }} --auto-attach + sudo subscription-manager repos --enable=rhel-9-for-{{ ansible_architecture }}-appstream-rpms --enable=rhel-9-for-{{ ansible_architecture }}-baseos-rpms + become_user: kni + +- name: Install packages using DNF + become_user: kni + dnf: + name: "{{ item }}" + state: present + loop: + - libvirt + - qemu-kvm + - mkisofs + - python3-devel + - jq + - ipmitool + +- name: Restart the firewalld service + become_user: kni + service: + name: firewalld + state: restarted + +- name: Add user to libvirt group + become_user: kni + user: + name: "kni" + groups: "libvirt" + append: yes + +- name: Enable firewalld http service + become_user: kni + shell: | + sudo firewall-cmd --zone=public --add-service=http --permanent + sudo firewall-cmd + +- name: Start and enable libvirtd + become_user: kni + service: + name: libvirtd + enabled: yes + state: started + +- name: Create default storage pool and start + become_user: kni + shell: | + sudo virsh pool-define-as --name default --type dir --target /var/lib/libvirt/images + sudo virsh pool-start default + sudo virsh pool-autostart default + +- name: Configure provisioner node networking + shell: | + sudo nohup bash -c " + nmcli con down \"{{ baremetal_nic_name }}\" + nmcli con delete \"{{ baremetal_nic_name }}\" + nmcli con down \"System {{ baremetal_nic_name }}\" + nmcli con delete \"System {{ baremetal_nic_name }}\" + nmcli connection add ifname baremetal type bridge con-name baremetal bridge.stp no + nmcli con add type bridge-slave ifname \"{{ baremetal_nic_name }}\" master baremetal + pkill dhclient;dhclient baremetal + become_user: kni + +- name: Create OCP deployment dir + file: + path: "{{ cluster_deploy_dir }}" + state: directory + recurse: yes + mode: '0755' + +- name: Create pull secret text file + copy: + content: "{{ ocp_pull_secret }}" + dest: "{{ cluster_deploy_dir }}/pull-secret.txt" + +- name: Retrieve OCP Install binary + shell: | + export RELEASE_IMAGE=$(curl -s https://mirror.openshift.com/pub/openshift-v4/{{ ansible_architecture }}/clients/ocp/{{ ocp_version }}/release.txt | grep 'Pull From: quay.io' | awk -F ' ' '{print $3}') + curl -s https://mirror.openshift.com/pub/openshift-v4/clients/ocp/$VERSION/openshift-client-linux.tar.gz | tar zxvf - oc + sudo cp oc /usr/local/bin + chmod +x /usr/local/bin/oc + oc adm release extract --registry-config "{{ cluster_deploy_dir }}/pull-secret.txt" --command=openshift-baremetal-install --to "{{ cluster_deploy_dir }}" ${RELEASE_IMAGE} + sudo cp {{ cluster_deploy_dir }}/openshift-baremetal-install /usr/local/bin + chmod +x /usr/local/bin/openshift-baremetal-install + become_user: kni + +- name: Create OCP cluster deployment dir + file: + path: "{{ cluster_deploy_dir }}/{{ cluster_name }}" + state: directory + recurse: yes + mode: '0755' + +- name: Copy install-config.yaml into cluster_deploy_dir + copy: + content: "{{ ocp_install_config }}" + dest: "{{ cluster_deploy_dir }}/{{ cluster_name }}/install-config.yaml" +... diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/_operator_config_item.yml b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/_operator_config_item.yml new file mode 100644 index 000000000..eb1fc9e9f --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/_operator_config_item.yml @@ -0,0 +1,36 @@ +- name: Retrieve Operator name + ansible.builtin.set_fact: + _operator: "{{ vars['cluster_config_' + _operator_name] }}" +- name: Configure Operator {{ _operator_name }} + redhat.openshift.k8s: + state: present + template: + - operators/namespace.yml.j2 + - operators/operator_group.yml.j2 + - operators/subscription.yml.j2 +- name: Query for install plan + kubernetes.core.k8s_info: + api_version: operators.coreos.com/v1alpha1 + kind: InstallPlan + namespace: "{{ _operator.namespace.name }}" + register: r_install_plans + retries: 30 + delay: 5 + until: + - r_install_plans.resources | default([]) | length > 0 + - r_install_plans.resources[0].status is defined + - r_install_plans.resources[0].status.phase == "Complete" + when: + - _operator.checkplan is defined + - _operator.checkplan | bool + +- name: Configure extra resources for Operator {{ _operator_name }} + redhat.openshift.k8s: + state: present + definition: "{{ item }}" + register: creation_result + loop: "{{ _operator.extra_resources }}" + retries: 30 + delay: 5 + until: creation_result is success + when: _operator.extra_resources is defined diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/catalog_sources.yml b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/catalog_sources.yml new file mode 100644 index 000000000..65dac8209 --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/catalog_sources.yml @@ -0,0 +1,6 @@ +- name: Configure custom CatalogSource for Operators + redhat.openshift.k8s: + state: present + template: operators/catalog_source.j2 + loop: "{{ cluster_config_catalog_sources }}" + when: cluster_config_catalog_sources is defined diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/node-health-check.yml b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/node-health-check.yml new file mode 100644 index 000000000..39138cd4d --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/node-health-check.yml @@ -0,0 +1,60 @@ +--- + +- name: Create node-health-check operator namespace + redhat.openshift.k8s: + name: openshift-workload-availability + api_version: v1 + kind: Namespace + state: present + +- name: Create node-health-check operator group + redhat.openshift.k8s: + state: present + definition: + apiVersion: operators.coreos.com/v1 + kind: OperatorGroup + metadata: + generateName: openshift-workload-availability- + annotations: + olm.providedAPIs: >- + NodeHealthCheck.v1alpha1.remediation.medik8s.io,SelfNodeRemediation.v1alpha1.self-node-remediation.medik8s.io,SelfNodeRemediationConfig.v1alpha1.self-node-remediation.medik8s.io,SelfNodeRemediationTemplate.v1alpha1.self-node-remediation.medik8s.io + namespace: openshift-workload-availability + spec: + upgradeStrategy: Default + +- name: Create node-health-check operator subscription + redhat.openshift.k8s: + state: present + definition: + apiVersion: operators.coreos.com/v1alpha1 + kind: Subscription + metadata: + labels: + operators.coreos.com/node-healthcheck-operator.openshift-workload-availability: '' + name: node-health-check-operator + namespace: openshift-workload-availability + spec: + channel: stable + installPlanApproval: Automatic + name: node-healthcheck-operator + source: redhat-operators + sourceNamespace: openshift-marketplace + +- name: Create Self Node Remediation subscription + redhat.openshift.k8s: + state: present + definition: + apiVersion: operators.coreos.com/v1alpha1 + kind: Subscription + metadata: + name: self-node-remediation-stable-redhat-operators-openshift-marketplace + namespace: openshift-workload-availability + labels: + operators.coreos.com/self-node-remediation.openshift-workload-availability: '' + spec: + channel: stable + installPlanApproval: Automatic + name: self-node-remediation + source: redhat-operators + sourceNamespace: openshift-marketplace + startingCSV: self-node-remediation.v0.8.0 diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/operator_config.yml b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/operator_config.yml new file mode 100644 index 000000000..f00e24ade --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/tasks/operators/operator_config.yml @@ -0,0 +1,6 @@ +--- +- name: Configure Operators + ansible.builtin.include_tasks: _operator_config_item.yml + loop: "{{ cluster_config_operators }}" + loop_control: + loop_var: _operator_name diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/catalog_source.j2 b/collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/catalog_source.j2 new file mode 100644 index 000000000..c2dafb102 --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/catalog_source.j2 @@ -0,0 +1,35 @@ +apiVersion: operators.coreos.com/v1alpha1 +kind: CatalogSource +metadata: + name: {{ item.name }} + namespace: openshift-marketplace +spec: + sourceType: {{ item.source_type | d('grpc',true) }} + image: {{ item.image_path }} + {% if item.display_name is defined -%} + displayName: {{ item.display_name }} + {% endif -%} + {% if item.priority is defined -%} + priority: {{ item.priority }} + {% endif -%} + {% if item.grpc_pod_config is defined -%} + grpcPodConfig: + {{ item.grpc_pod_config | indent(4) }} + {% endif -%} + {% if item.icon is defined -%} + icon: + base64data: '{{ item.icon.base64data or '' }}' + mediatype: '{{ item.icon.mediatype or '' }}' + {% endif -%} + {% if item.publisher is defined -%} + publisher: {{ item.publisher }} + {% endif -%} + {% if item.address is defined -%} + address: {{ item.address }} + {% endif -%} + {% if item.registry_poll_interval is defined -%} + updateStrategy: + registryPoll: + interval: {{ item.registry_poll_interval }} + {% endif -%} + diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/namespace.yml.j2 b/collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/namespace.yml.j2 new file mode 100644 index 000000000..9736a06ad --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/namespace.yml.j2 @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: {{ _operator.namespace.name }} +{% if _operator.namespace.labels is defined %} + labels: + {% for key, value in _operator.namespace.labels.items() -%} + {{ key }}: "{{ value }}" + {% endfor -%} +{% endif -%} \ No newline at end of file diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/operator_group.yml.j2 b/collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/operator_group.yml.j2 new file mode 100644 index 000000000..22a9f9b0e --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/operator_group.yml.j2 @@ -0,0 +1,12 @@ +apiVersion: operators.coreos.com/v1 +kind: OperatorGroup +metadata: + name: {{ _operator.operator_group.name }} + namespace: {{ _operator.operator_group.namespace | d(_operator.namespace.name, true) }} +spec: + {% if _operator.operator_group.target_namespaces is defined -%} + targetNamespaces: + {% for item in _operator.operator_group.target_namespaces %} + - {{ item }} + {% endfor %} + {% endif -%} \ No newline at end of file diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/subscription.yml.j2 b/collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/subscription.yml.j2 new file mode 100644 index 000000000..c7d6dd451 --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/templates/operators/subscription.yml.j2 @@ -0,0 +1,14 @@ +apiVersion: operators.coreos.com/v1alpha1 +kind: Subscription +metadata: + name: {{ _operator.subscription.name }} + namespace: "{{ _operator.subscription.namespace | d(_operator.namespace.name, true) }}" +spec: + channel: {{ _operator.subscription.channel | d('stable', true) }} + installPlanApproval: {{ _operator.subscription.install_plan_approval | d('Automatic', true) }} + name: {{ _operator.subscription.spec_name | d(_operator.subscription.name, true) }} + source: {{ _operator.subscription.source | d('redhat-operators', true) }} + sourceNamespace: {{ _operator.subscription.source_namespace | d('openshift-marketplace', true) }} +{% if _operator.subscription.starting_csv is defined %} + startingCSV: {{ _operator.subscription.starting_csv }} +{% endif -%} \ No newline at end of file diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/tests/inventory b/collections/ansible_collections/demo/openshift/roles/cluster_config/tests/inventory new file mode 100644 index 000000000..878877b07 --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/tests/test.yml b/collections/ansible_collections/demo/openshift/roles/cluster_config/tests/test.yml new file mode 100644 index 000000000..6b1bb92bf --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - cluster_config diff --git a/collections/ansible_collections/demo/openshift/roles/cluster_config/vars/main.yml b/collections/ansible_collections/demo/openshift/roles/cluster_config/vars/main.yml new file mode 100644 index 000000000..470cae4ef --- /dev/null +++ b/collections/ansible_collections/demo/openshift/roles/cluster_config/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for cluster_config \ No newline at end of file diff --git a/openshift/cnv/install.yml b/openshift/cnv/install.yml index 26179a642..b2403e3b0 100644 --- a/openshift/cnv/install.yml +++ b/openshift/cnv/install.yml @@ -4,6 +4,14 @@ gather_facts: false tasks: - name: Include role - ansible.builtin.incdlue_role: + ansible.builtin.include_role: name: demo.openshift.cluster_config + - name: Display message to user + ansible.builtin.debug: + msg: "Note: wait for the operator to be installed" + + - name: Wait for the operator to be installed + ansible.builtin.pause: + seconds: 90 +