Back to the main page
Lifecycle management of a VM in OVMM pool using Ansible
Intro
The custom Ansible module for this has been developed by Oracle.
Installation
Download from OTN
Ansible checks for the custom module in "library" subdirectory of the directory where a playbook is stored, hence place ovmm_vm.py in that location.
Playbook
The playbook (named ca-zdudic3_present.yml) for a VM (named ca-zdudic3) to be present is:
---
- name: Create a VM on hw-ovm-pool pool
# no need to use inventory,
# this is host from where you run this playbook
hosts: localhost
tasks:
- name: Create a Virtual Machine
ovmm_vm:
state: present
name: ca-zdudic3
ovm_user: ovmm_user
ovm_pass: password
ovm_host: ovm-manager.company.com # this is OVM Manager
ovm_port: 7002
server_pool: hw-ovm-pool # create in this pool
repository: HQ-Main
memory: 2048
vcpu_cores: 1
boot_order: PXE
networks: ['VLAN 318'] # make sure to use desired vlan
# root disk = 10G and second one 1G
disks: [['ca-zdudic3.img', 10737418240, 'HQ-Main'], ['ca-zdudic3_u01.img', 1073741824, 'HQ-Main']]
register: testout
- name: dump test output
debug:
msg: '{{ testout }}'
Create a VM
Run the playbook to create a VM. The command is :
ansible-playbook ca-zdudic3_present.yml
Warning about inventory can be ignored. Expect to see this output.
PLAY [Create a VM on hw-ovm-pool]
*************************
TASK [Gathering Facts]
*************************************************
ok: [localhost]
TASK [Create a Virtual Machine]
**************************************************
changed: [localhost]
TASK [dump test output]
********************************************
ok: [localhost] => {
"msg": {
"changed": true,
"failed": false,
"msg": "VM created",
"warnings": [
"Module did not set no_log for ovm_pass"
]
}
}
PLAY RECAP
**********************************************
localhost : ok=3 changed=1 unreachable=0 failed=0
The VM is created.
This description is automatically created.
Idempotency
An operation is idempotent if the result of performing it once is exactly the same as the result of performing it repeatedly without any intervening actions.
Run again
ansible-playbook ca-zdudic3_present.yml
it reads that the VM exist, reports its ID, and nothing has been changed.
TASK [dump test output]
*********************************
ok: [localhost] => {
"msg": {
"changed": false,
"failed": false,
"msg": "VM exists and has id 0004fb0000060000f27871ab06175683",
"warnings": [
"Module did not set no_log for ovm_pass"
]
}
}
PLAY RECAP
*****************************************************************
localhost ok=3 changed=0 unreachable=0 failed=0
Delete a VM
The playbook for deleting a VM is:
---
- name: Delete a VM from hw-ovm-pool
hosts: localhost
tasks:
- name: Delete a Virtual Machine
ovmm_vm:
state: absent
name: ca-zdudic3
ovm_user: ovmm_user
ovm_pass: password
ovm_host: ovm-manager.company.com
ovm_port: 7002
register: testout
- name: dump test output
debug:
msg: '{{ testout }}'
Delete VM with command
ansible-playbook ca-zdudic3_delete.yml
and result is
ok: [localhost] => {
"msg": {
"changed": true,
"failed": false,
"msg": "VM Deleted",
"warnings": [
"Module did not set no_log for ovm_pass"
]
}
}
Run playbook again, and it's reported that "VM doesn't exist"
Start and stop a VM
Playbooks for start and stop of the VM is like the one for deletion,except "state" is start and stop.
Back to the main page