forked from ansible/product-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,55 @@ | ||
--- | ||
- name: Lookup VM names to be snapshotted | ||
hosts: "{{ _hosts }}" | ||
gather_facts: false | ||
- name: Create a VM snapshot | ||
hosts: localhost | ||
tasks: | ||
- name: Get name of VirtualMachine | ||
ansible.builtin.set_stats: | ||
per_host: true | ||
- name: Debug | ||
ansible.builtin.debug: | ||
msg: "{{ ansible.builtin.lookup('ansible.builtin.inventory_hostnames', 'all') }}" | ||
|
||
- name: Get state of VirtualMachine | ||
redhat.openshift_virtualization.kubevirt_vm_info: | ||
name: "{{ vm_name }}" | ||
namespace: "{{ vm_namespace }}" | ||
register: state | ||
|
||
- name: Stop VirtualMachine | ||
redhat.openshift_virtualization.kubevirt_vm: | ||
name: "{{ vm_namespace }}" | ||
namespace: "{{ vm_namespace }}" | ||
running: false | ||
wait: true | ||
when: state.resources.0.spec.running | ||
|
||
- name: Create a VirtualMachineSnapshot | ||
kubernetes.core.k8s: | ||
definition: | ||
apiVersion: snapshot.kubevirt.io/v1alpha1 | ||
kind: VirtualMachineSnapshot | ||
metadata: | ||
generateName: "{{ vm_name }}-{{ ansible_date_time.iso8601 }}" | ||
namespace: "{{ vm_namespace }}" | ||
spec: | ||
source: | ||
apiGroup: kubevirt.io | ||
kind: VirtualMachine | ||
name: "{{ vm_name }}" | ||
wait: true | ||
wait_condition: | ||
type: Ready | ||
register: snapshot | ||
|
||
- name: Start VirtualMachine | ||
redhat.openshift_virtualization.kubevirt_vm: | ||
name: "{{ vm_name }}" | ||
namespace: "{{ vm_namesace }}" | ||
running: yes | ||
wait: yes | ||
when: state.resources.0.spec.running | ||
|
||
- name: Export snapshot name | ||
ansible.builtin.set_stats: | ||
data: | ||
my_var: "{{ inventory_hostname }}" | ||
vars: | ||
ansible_connection: local | ||
restore_snapshot_name: "{{ snapshot.result.metadata.name }}" | ||
|
||
#- name: Create a VM snapshot | ||
# hosts: localhost | ||
# tasks: | ||
# - name: Debug | ||
# ansible.builtin.debug: | ||
# msg: "{{ my_var }}" | ||
# | ||
# - name: Get state of VirtualMachine | ||
# redhat.openshift_virtualization.kubevirt_vm_info: | ||
# name: "{{ vm_name }}" | ||
# namespace: "{{ vm_namespace }}" | ||
# register: state | ||
# | ||
# - name: Stop VirtualMachine | ||
# redhat.openshift_virtualization.kubevirt_vm: | ||
# name: "{{ vm_namespace }}" | ||
# namespace: "{{ vm_namespace }}" | ||
# running: false | ||
# wait: true | ||
# when: state.resources.0.spec.running | ||
# | ||
# - name: Create a VirtualMachineSnapshot | ||
# kubernetes.core.k8s: | ||
# definition: | ||
# apiVersion: snapshot.kubevirt.io/v1alpha1 | ||
# kind: VirtualMachineSnapshot | ||
# metadata: | ||
# generateName: "{{ vm_name }}-{{ ansible_date_time.iso8601 }}" | ||
# namespace: "{{ vm_namespace }}" | ||
# spec: | ||
# source: | ||
# apiGroup: kubevirt.io | ||
# kind: VirtualMachine | ||
# name: "{{ vm_name }}" | ||
# wait: true | ||
# wait_condition: | ||
# type: Ready | ||
# register: snapshot | ||
# | ||
# - name: Start VirtualMachine | ||
# redhat.openshift_virtualization.kubevirt_vm: | ||
# name: "{{ vm_name }}" | ||
# namespace: "{{ vm_namesace }}" | ||
# running: yes | ||
# wait: yes | ||
# when: state.resources.0.spec.running | ||
# | ||
# - name: Export snapshot name | ||
# ansible.builtin.set_stats: | ||
# data: | ||
# restore_snapshot_name: "{{ snapshot.result.metadata.name }}" | ||
# | ||
# - debug: | ||
# msg: "Successfully created snapshot {{ snapshot.result.metadata.name }}" | ||
- debug: | ||
Check failure on line 54 in openshift/cnv/create_snapshot.yml GitHub Actions / pre-commitfqcn[action-core]
|
||
msg: "Successfully created snapshot {{ snapshot.result.metadata.name }}" |