Skip to content

Commit

Permalink
try this
Browse files Browse the repository at this point in the history
  • Loading branch information
l3acon committed Aug 20, 2024
1 parent 5103485 commit cbadac5
Showing 1 changed file with 51 additions and 63 deletions.
114 changes: 51 additions & 63 deletions openshift/cnv/create_snapshot.yml
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

Check failure on line 5 in openshift/cnv/create_snapshot.yml

View workflow job for this annotation

GitHub Actions / pre-commit

yaml[indentation]

Wrong indentation: expected at least 3
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

Check failure on line 45 in openshift/cnv/create_snapshot.yml

View workflow job for this annotation

GitHub Actions / pre-commit

yaml[truthy]

Truthy value should be one of \[false, true]
wait: yes

Check failure on line 46 in openshift/cnv/create_snapshot.yml

View workflow job for this annotation

GitHub Actions / pre-commit

yaml[truthy]

Truthy value should be one of \[false, true]
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

View workflow job for this annotation

GitHub Actions / pre-commit

fqcn[action-core]

Use FQCN for builtin module actions (debug).

Check failure on line 54 in openshift/cnv/create_snapshot.yml

View workflow job for this annotation

GitHub Actions / pre-commit

name[missing]

All tasks should be named.
msg: "Successfully created snapshot {{ snapshot.result.metadata.name }}"

0 comments on commit cbadac5

Please sign in to comment.