Ansible modules for KubeVirt management.
lib
: Ansible modules files for KubeVirt managementkubevirt_raw
: Allow to manage KubeVirt resources, VirtualMachineInstance, VirtualMachine, VirtualMachineInstanceReplicaSet and VirtualMachineInstancePresets.kubevirt_facts
: Gather facts about a given resource.kubevirt_vm_status
: Set an VirtualMachine to eitherrunning
orstopped
.kubevirt_scale_vmirs
: Scale up or down a VirtualMachineInstanceReplilcaSet.
tests
: Ansible playbook examples and unit tests
- Ansible >= 2.4.3.0
- KubeVirt Python SDK
- Kubernetes Python client
- KubeVirt
-
Install the modules:
-
From GitHub:
$ git clone https://github.com/kubevirt/ansible-kubevirt-modules
-
From Ansible Galaxy
$ ansible-galaxy install -p <roles_path> kubevirt.kubevirt-modules
-
-
Setting up the environment
$ export ANSIBLE_MODULE_UTILS=<module_path>/lib/ansible/module_utils
$ export ANSIBLE_LIBRARY=<module_path>/lib/ansible/modules
NOTE: These settings can instead be added to ansible.cfg as done in test/ansible.cfg
-
A working Kubernetes configuration is also required. It can also be created by issuing
oc login
if using KubeVirt with OpenShift. -
Once installed, add it to a playbook:
---
- hosts: localhost
roles:
- role: ansible-kubevirt-modules
install_python_requirements: no
- role: hello-underworld
Because the role is referenced, the hello-underworld
role is able to make use of the kubevirt modules.
- Virtual Machine Instance
- Virtual Machine
- Virtual Machine Instance ReplicaSet
- Stop Virtual Machine
- Scale Virtual Machine Instance Replica Set
- Virtual Machine Instance facts
- Virtual Machine facts
- Virtual Machine Instance ReplicaSet facts
- All Virtual Machine Instance facts
- Run the tests as follows:
$ export ANSIBLE_CONFIG=tests/ansible.cfg
$ ansible-playbook tests/playbooks/<playbook>
If your cluser has a self-signed certificate, you can include
verify_ssl = false
intests/ansible.cfg
-
The playbook examples, include cloud-init configuration, for being able to access the VMIs created.
-
For using SSH do as follows:
$ kubectl get all NAME READY STATUS RESTARTS AGE po/virt-launcher-bbecker-jw5kk 1/1 Running 0 22m $ kubectl expose pod virt-launcher-bbecker-jw5kk --port=27017 --target-port=22 --name=vmservice $ kubectl get svc vmservice NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE vmservice ClusterIP 172.30.133.9 <none> 27017/TCP 19m $ ssh -i tests/kubevirt_rsa -p 27017 [email protected]
NOTE: It might take a while for the VM to completely come up before SSH can be used.
-
For using
virtctl
:$ virtctl console <vmi_name>
Or
$ virtctl vnc <vmi_name>
NOTE: Use username
kubevirt
and passwordkubevirt
.
-
- Once one of the previous resources has been created, the facts module can be tested as well as follows:
$ ansible-playbook tests/playbooks/kubevirt_vm_facts.yml
The above command, will gather the information for the VM stated in the playbook and print out a JSON document based on KubeVirt VM spec.