Manage Snapshot via Ansible

Manage Snapshot via Ansible

I created playbook to make snapshot via Ansible.

Before test please create your secret.yml with passwords something like.


vcenter: <ip address>
username: administrator@vsphere.local
password: Passw0rd!!

 

Link to downolad snapshot.yml

 

For vmware_guest_snapshot ansible module you can use some snippet like below.

I use just fief because for creating snapshot you don’t need all.

I test uuid: 420bdbef-83f9-8689-cfc3-8d24e90223bf and name and both was working.

Let’s test it.

“Run ansible Playbook remotely via ssh”.

When playbook runs you can see some logs and if result is changed this is good good sign.

I logged to vcenter and check if snapshot was created.

All look’s fine. Snapshot was created.

 

Below more useful examples for manage snapshots like below.

 

 - name: Create a snapshot
    vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: present
      snapshot_name: snap1
      description: snap1_description
    delegate_to: localhost


  - name: Remove a snapshot
    vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: absent
      snapshot_name: snap1
    delegate_to: localhost


  - name: Revert to a snapshot
    vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: revert
      snapshot_name: snap1
    delegate_to: localhost


  - name: Remove all snapshots of a VM
    vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: remove_all
    delegate_to: localhost


  - name: Take snapshot of a VM using quiesce and memory flag on
    vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: present
      snapshot_name: dummy_vm_snap_0001
      quiesce: yes
      memory_dump: yes
    delegate_to: localhost


  - name: Remove a snapshot and snapshot subtree
    vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: absent
      remove_children: yes
      snapshot_name: snap1
    delegate_to: localhost


  - name: Rename a snapshot
    vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: present
      snapshot_name: current_snap_name
      new_snapshot_name: im_renamed
      new_description: "{{ new_snapshot_description }}"
    delegate_to: localhost




Please Comment and Subscribe

 136 total views,  2 views today