Ansible 有virsh/libvirt模塊幢竹,我們可以使用virsh模塊創(chuàng)建虛擬機(jī)耳峦,改名,更改存儲焕毫,關(guān)機(jī)妇萄,啟動等等一系列操作(https://docs.ansible.com/ansible/latest/modules/virt_module.html) 但是沒有快照管理……也可能我沒找到。好在我們有萬能的command模塊咬荷。
關(guān)于命令行操作快照冠句,請參考:2019-04-26 KVM虛擬機(jī)快照命令行管理
ansible劇本這樣寫:
---
- hosts: xx.xxx.xxx.x
become_user: root
become: true
tasks:
- name: Create Snapshot for axtest99
command: virsh snapshot-create-as --domain axtest99 --name {{ ansible_date_time.date }} --description "This is snapshot test"
#以當(dāng)前日期作為快照名稱
- name: List Snapshot for axtest99
command: virsh snapshot-list axtest99
register: ax_result
#創(chuàng)建完快照看下效果,結(jié)果放到變量里
- name: echo ax_result
debug:
msg: "{{ax_result}}"
#顯示輸出剛才的結(jié)果
多臺虛擬機(jī)的話幸乒,多寫幾行就行了懦底。