Skip to content

mhenriks/ansible-kubevirt-modules

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ansible KubeVirt Modules

Ansible modules for KubeVirt management.

Contents

  • lib: Ansible modules files for KubeVirt management
    • kubevirt_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 either running or stopped.
    • kubevirt_scale_vmirs: Scale up or down a VirtualMachineInstanceReplilcaSet.
  • tests: Ansible playbook examples and unit tests

Requirements

Installation and usage

  1. Install the modules:

    1. From GitHub:

      $ git clone https://github.com/kubevirt/ansible-kubevirt-modules
    2. From Ansible Galaxy

      $ ansible-galaxy install -p <roles_path> kubevirt.kubevirt-modules
  2. 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

  1. A working Kubernetes configuration is also required. It can also be created by issuing oc login if using KubeVirt with OpenShift.

  2. Install KubeVirt Python SDK

  3. Install Kubernetes Python client

  4. 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.

Playbook examples

Local testing

  1. 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 in tests/ansible.cfg

  1. The playbook examples, include cloud-init configuration, for being able to access the VMIs created.

    1. 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.

    2. For using virtctl:

      $ virtctl console <vmi_name>

      Or

      $ virtctl vnc <vmi_name>

      NOTE: Use username kubevirt and password kubevirt.

Facts

  • 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.

About

Ansible modules for KubeVirt management

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%