Add OCP-CNV patching demo (#140)
This commit is contained in:
committed by
GitHub
parent
65936930c0
commit
40807f1eab
101
openshift/cnv/install.yml
Normal file
101
openshift/cnv/install.yml
Normal file
@@ -0,0 +1,101 @@
|
||||
---
|
||||
- name: Deploy OpenShift CNV Operator and create the Hyperconverged object, provision VM to prove funciontality
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
vars:
|
||||
vm_name: ocpvtest
|
||||
vm_namespace: openshift-cnv
|
||||
tasks:
|
||||
- name: Include role
|
||||
ansible.builtin.include_role:
|
||||
name: demo.openshift.cluster_config
|
||||
|
||||
- name: Attempt to Provision a VM
|
||||
kubernetes.core.k8s:
|
||||
wait: true
|
||||
state: "{{ instance_state | default('present') }}"
|
||||
definition:
|
||||
apiVersion: kubevirt.io/v1
|
||||
kind: VirtualMachine
|
||||
metadata:
|
||||
name: "{{ vm_name }}"
|
||||
namespace: "{{ vm_namespace }}"
|
||||
labels:
|
||||
app: "{{ vm_name }}"
|
||||
vm.kubevirt.io/name: "{{ vm_name }}"
|
||||
spec:
|
||||
dataVolumeTemplates:
|
||||
- apiVersion: cdi.kubevirt.io/v1beta1
|
||||
kind: DataVolume
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: "{{ vm_name }}"
|
||||
spec:
|
||||
sourceRef:
|
||||
kind: DataSource
|
||||
name: "{{ os_version | default('fedora') }}"
|
||||
namespace: openshift-virtualization-os-images
|
||||
storage:
|
||||
resources:
|
||||
requests:
|
||||
storage: 30Gi
|
||||
running: true
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
vm.kubevirt.io/flavor: small
|
||||
vm.kubevirt.io/os: "{{ os_version | default('fedora') }}"
|
||||
vm.kubevirt.io/workload: server
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
kubevirt.io/domain: "{{ vm_name }}"
|
||||
kubevirt.io/size: small
|
||||
spec:
|
||||
domain:
|
||||
cpu:
|
||||
cores: 4
|
||||
sockets: 1
|
||||
threads: 1
|
||||
devices:
|
||||
disks:
|
||||
- disk:
|
||||
bus: virtio
|
||||
name: rootdisk
|
||||
interfaces:
|
||||
- masquerade: {}
|
||||
model: virtio
|
||||
name: default
|
||||
networkInterfaceMultiqueue: true
|
||||
rng: {}
|
||||
machine:
|
||||
type: pc-q35-rhel9.2.0
|
||||
resources:
|
||||
requests:
|
||||
memory: 8Gi
|
||||
evictionStrategy: LiveMigrate
|
||||
networks:
|
||||
- name: default
|
||||
pod: {}
|
||||
terminationGracePeriodSeconds: 180
|
||||
volumes:
|
||||
- dataVolume:
|
||||
name: "{{ vm_name }}"
|
||||
name: rootdisk
|
||||
retries: 60
|
||||
delay: 5
|
||||
register: provision
|
||||
until: provision.changed
|
||||
|
||||
- name: Clean up test VM
|
||||
kubernetes.core.k8s:
|
||||
wait: true
|
||||
state: absent
|
||||
definition:
|
||||
apiVersion: kubevirt.io/v1
|
||||
kind: VirtualMachine
|
||||
metadata:
|
||||
name: "{{ vm_name }}"
|
||||
namespace: "{{ vm_namespace }}"
|
||||
labels:
|
||||
app: "{{ vm_name }}"
|
||||
vm.kubevirt.io/name: "{{ vm_name }}"
|
||||
37
openshift/cnv/patch.yml
Normal file
37
openshift/cnv/patch.yml
Normal file
@@ -0,0 +1,37 @@
|
||||
---
|
||||
- name: Linux server patching for OpenShift Virtalized Hosts
|
||||
hosts: "{{ _hosts | default(omit) }}"
|
||||
become: true
|
||||
tasks:
|
||||
# Install yum-utils if it's not there
|
||||
- name: Install yum-utils
|
||||
ansible.builtin.yum:
|
||||
name: yum-utils
|
||||
state: installed
|
||||
|
||||
- name: Include patching role
|
||||
ansible.builtin.include_role:
|
||||
name: demo.patching.patch_linux
|
||||
|
||||
- name: Tell user when Insights Client is not configured
|
||||
ansible.builtin.debug:
|
||||
msg: "Insights client does not appear to be configured. Scan will be skipped"
|
||||
when:
|
||||
- ansible_local.insights.system_id is not defined
|
||||
|
||||
- name: Run the Insights Client Scan # noqa: no-changed-when
|
||||
ansible.builtin.command: insights-client
|
||||
when:
|
||||
- not ansible_check_mode
|
||||
- ansible_local.insights.system_id is defined
|
||||
|
||||
- name: Create nginx container
|
||||
when: not ansible_check_mode
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
connection: local
|
||||
run_once: true # noqa: run-once[task]
|
||||
block:
|
||||
- name: Publish landing page
|
||||
ansible.builtin.include_role:
|
||||
name: demo.patching.report_ocp_patching
|
||||
76
openshift/cnv/provision.yml
Normal file
76
openshift/cnv/provision.yml
Normal file
@@ -0,0 +1,76 @@
|
||||
---
|
||||
- name: De-Provision OCP-CNV VM
|
||||
hosts: localhost
|
||||
tasks:
|
||||
- name: Define resources
|
||||
kubernetes.core.k8s:
|
||||
wait: true
|
||||
state: "{{ instance_state | default('present') }}"
|
||||
definition:
|
||||
apiVersion: kubevirt.io/v1
|
||||
kind: VirtualMachine
|
||||
metadata:
|
||||
name: "{{ vm_name }}"
|
||||
namespace: "{{ vm_namespace }}"
|
||||
labels:
|
||||
app: "{{ vm_name }}"
|
||||
os.template.kubevirt.io/fedora36: 'true'
|
||||
vm.kubevirt.io/name: "{{ vm_name }}"
|
||||
spec:
|
||||
dataVolumeTemplates:
|
||||
- apiVersion: cdi.kubevirt.io/v1beta1
|
||||
kind: DataVolume
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: "{{ vm_name }}"
|
||||
spec:
|
||||
sourceRef:
|
||||
kind: DataSource
|
||||
name: "{{ os_version |default('rhel9') }}"
|
||||
namespace: openshift-virtualization-os-images
|
||||
storage:
|
||||
resources:
|
||||
requests:
|
||||
storage: 30Gi
|
||||
running: true
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
vm.kubevirt.io/flavor: small
|
||||
vm.kubevirt.io/os: "{{ os_version | default('rhel9') }}"
|
||||
vm.kubevirt.io/workload: server
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
kubevirt.io/domain: "{{ vm_name }}"
|
||||
kubevirt.io/size: small
|
||||
spec:
|
||||
domain:
|
||||
cpu:
|
||||
cores: 4
|
||||
sockets: 1
|
||||
threads: 1
|
||||
devices:
|
||||
disks:
|
||||
- disk:
|
||||
bus: virtio
|
||||
name: rootdisk
|
||||
interfaces:
|
||||
- masquerade: {}
|
||||
model: virtio
|
||||
name: default
|
||||
networkInterfaceMultiqueue: true
|
||||
rng: {}
|
||||
machine:
|
||||
type: pc-q35-rhel9.2.0
|
||||
resources:
|
||||
requests:
|
||||
memory: 8Gi
|
||||
evictionStrategy: LiveMigrate
|
||||
networks:
|
||||
- name: default
|
||||
pod: {}
|
||||
terminationGracePeriodSeconds: 180
|
||||
volumes:
|
||||
- dataVolume:
|
||||
name: "{{ vm_name }}"
|
||||
name: rootdisk
|
||||
96
openshift/cnv/provision_rhel.yml
Normal file
96
openshift/cnv/provision_rhel.yml
Normal file
@@ -0,0 +1,96 @@
|
||||
---
|
||||
- name: Provision OCP-CNV RHEL VM
|
||||
hosts: localhost
|
||||
tasks:
|
||||
- name: Define resources
|
||||
redhat.openshift.k8s:
|
||||
wait: true
|
||||
state: "{{ instance_state | default('present') }}"
|
||||
definition:
|
||||
apiVersion: kubevirt.io/v1
|
||||
kind: VirtualMachine
|
||||
metadata:
|
||||
name: "{{ vm_name }}"
|
||||
namespace: "{{ vm_namespace }}"
|
||||
labels:
|
||||
app: "{{ vm_name }}"
|
||||
os.template.kubevirt.io/fedora36: 'true'
|
||||
vm.kubevirt.io/name: "{{ vm_name }}"
|
||||
spec:
|
||||
dataVolumeTemplates:
|
||||
- apiVersion: cdi.kubevirt.io/v1beta1
|
||||
kind: DataVolume
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: "{{ vm_name }}"
|
||||
spec:
|
||||
sourceRef:
|
||||
kind: DataSource
|
||||
name: "{{ os_version }}"
|
||||
namespace: openshift-virtualization-os-images
|
||||
storage:
|
||||
resources:
|
||||
requests:
|
||||
storage: 30Gi
|
||||
running: true
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
vm.kubevirt.io/flavor: small
|
||||
vm.kubevirt.io/os: "{{ os_version }}"
|
||||
vm.kubevirt.io/workload: server
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
kubevirt.io/domain: "{{ vm_name }}"
|
||||
kubevirt.io/size: small
|
||||
spec:
|
||||
domain:
|
||||
cpu:
|
||||
cores: 4
|
||||
sockets: 1
|
||||
threads: 1
|
||||
devices:
|
||||
disks:
|
||||
- disk:
|
||||
bus: virtio
|
||||
name: rootdisk
|
||||
- disk:
|
||||
bus: virtio
|
||||
name: cloudinitdisk
|
||||
interfaces:
|
||||
- masquerade: {}
|
||||
model: virtio
|
||||
name: default
|
||||
networkInterfaceMultiqueue: true
|
||||
rng: {}
|
||||
machine:
|
||||
type: pc-q35-rhel9.2.0
|
||||
resources:
|
||||
requests:
|
||||
memory: 8Gi
|
||||
evictionStrategy: LiveMigrate
|
||||
networks:
|
||||
- name: default
|
||||
pod: {}
|
||||
terminationGracePeriodSeconds: 180
|
||||
volumes:
|
||||
- dataVolume:
|
||||
name: "{{ vm_name }}"
|
||||
name: rootdisk
|
||||
- name: cloudinitdisk
|
||||
cloudInitNoCloud:
|
||||
userData: |-
|
||||
#cloud-config
|
||||
chpasswd: { expire: False }
|
||||
ssh_pwauth: False
|
||||
ssh_authorized_keys:
|
||||
- "{{ ssh_authorized_key }}"
|
||||
rh_subscription:
|
||||
activation-key: "{{ rh_subscription_key }}"
|
||||
org: "{{ rh_subscription_org }}"
|
||||
|
||||
- name: Wait for VM to be running
|
||||
redhat.openshift_virtualization.kubevirt_vm_info:
|
||||
name: "{{ vm_name }}"
|
||||
namespace: "{{ vm_namespace }}"
|
||||
wait: true
|
||||
14
openshift/cnv/wait.yml
Normal file
14
openshift/cnv/wait.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
- name: Wait for VMs to start and become ready
|
||||
hosts: "{{ _hosts | default(omit) }}"
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Wait for
|
||||
ansible.builtin.wait_for:
|
||||
port: 22
|
||||
host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
|
||||
search_regex: OpenSSH
|
||||
delay: 10
|
||||
retries: 10
|
||||
vars:
|
||||
ansible_connection: local
|
||||
Reference in New Issue
Block a user