[Wanted] Examples using ansible with rhev

Latest response

Hi,

Anyone using ansible to deploy to rhev? Care to share your playbooks or any examples? Thanks,

Scott Miller's picture

Responses

Closest I've come to this is Vagrant with KVM, but would also be keen to see some Ansible playbooks using RHEV.

Interested to know what you're currently using in your automation stack with RHEV? (if it doesn't take the this thread too far off topic)

Hi,
I'm currently using python scripts for each task like create vm, add disk, add network interface, first boot.
This was fastest way how to do what I want, but it's not perfect :)
First of all I don't like that I need to pass my username and password and there is no other ways when you using API.
More sense will be writing new Ansible module because existing ovirt module is very limited. But for me it's too complicated. Example:
roles/ovirt/tasks/main.yml
- name: Create VM
connection: local
script: create_vm.py {{ ovirt[dc]['url'] }} {{ ovirt[dc]['cluster'] }} {{ inventory_hostname }} {{ cpu }} {{ memory }} {{ os }}
environment:
ovirt_username: "{{ovirt_username}}"
ovirt_password: "{{ovirt_password}}"
tags:
- ovirt roles/ovirt/files/create_vm.py

! /usr/bin/python

import sys
import os from ovirtsdk.api import API
from ovirtsdk.xml import params GB = 102410241024 USERNAME = os.environ.get('ovirt_username')
PASSWORD = os.environ.get('ovirt_password')
URL = sys.argv[1]
CLUSTER_NAME = sys.argv[2]
VM_NAME = sys.argv[3]
CPU = int(sys.argv[4])
MEMORY = int(sys.argv[5])
OS = sys.argv[6] try:
api = API(url=URL, username=USERNAME, password=PASSWORD, insecure=True)

vm params

vm_memory = MEMORY * GB
vm_cluster = api.clusters.get(name=CLUSTER_NAME)
vm_template = api.templates.get(name="lx00") vm_params = params.VM(name=VM_NAME,
os=params.OperatingSystem(OS),
cpu=params.CPU(topology=params.CpuTopology(sockets=CPU)),
type_="server",
memory=vm_memory,
cluster=vm_cluster,
template=vm_template)

create vm

try:
api.vms.add(vm=vm_params)
print "Virtual machine '%s' added." % VM_NAME except Exception as ex:
print "Adding virtual machine '%s' failed: %s" % (VM_NAME, ex)
sys.exit(1) api.disconnect() except Exception as ex:
print "Unexpected error: %s" % ex
sys.exit(1)

We're using it to provision our Gluster backend as well as deploy the VM's

-------- 1 Gluster Volume

- name: Gluster - create vm
  gluster_volume: state=present name={{ SiteName }}_vm brick=/mnt/gluster/vm/brick0 cluster={{ SiteName }}-{{ GlusterServer1 }}.{{ ansible_domain }},{{ SiteName }}-{{ GlusterServer2 }}.{{ ansible_domain }} replicas=2 force=yes start_on_create=yes
  when: inventory_hostname == "{{ SiteName }}-{{ GlusterServer1 }}.{{ ansible_domain }}"
  tags: glustervm
  run_once: true
  tags: glustersetup

-------VM Based on template

- name: vmsetup - create vm shell - jumpbox
  action: ovirt
     instance_name={{ SiteName }}-123-001
     resource_type=template
     instance_type=server
     image=RHELOS6
     user={{ ovirtAdmin }}
     password={{ ovirtAdminPWD }}
     url={{ ovirtURL }}
     instance_disksize=70
     zone=Default
     region=Default
     instance_cpus=2
     instance_nic=nic1
     instance_network={{ SiteName }}_vms_20
     instance_mem=4096
     disk_alloc=thin
     sdomain=VM
     instance_cores=1
     instance_os=rhel_6x64
     disk_int=virtio
  run_once: true

Little late to the party on this one, but...

I've got a working playbook using core (uses vars_prompt to get username/pw) and a modified one for Tower v3, which uses Survey to pass in the username/pw combo. A bit Heath Robinson but it works.

https://github.com/ffirg/ansible - search for "rhev"

Some little gotchas: The username if using internal needs to be username@internal else auth will fail.
You need ovirt-engine-sdk-python installed - sudo pip install 'ovirt-engine-sdk-python==3.6.5.2' It was fussy about versions, the latest didn't work with Tower v3. This was using RHEV 3.5.7 btw.

New modules has been implemented for Ansible 2.2 to work with RHV 4.0: https://docs.ansible.com/ansible/ovirt_auth_module.html https://docs.ansible.com/ansible/ovirt_vms_module.html https://docs.ansible.com/ansible/ovirt_disks_module.html

all includes examples. future planned delivery for Ansible 2.3 can be found here - https://www.ovirt.org/develop/release-management/features/infra/ansible_modules/

Another project working with ansible and ovirt deployment and utilities around it.

https://github.com/rhevm-qe-automation/ovirt-ansible

I am late as well, but thought I would forward this. It's a series of videos produced by Jon Benedict, who is the product marketing manager for Red Hat Virtualization:

https://www.youtube.com/watch?v=kXNX15BYS5s - Red Hat Virtualization + Ansible - Automation pt1 https://www.youtube.com/watch?v=4gHEG-hi6H0 - Red Hat Virtualization + Ansible - Automation pt2 https://www.youtube.com/watch?v=Q7eJon7bExw - Red Hat Virtualization + Ansible - Automation pt3

Calvin, thanks for the post - its exactly what I was looking for

Guys, Any chance of creating VM with custom UUID via ansible ? This feature is ready via GUI https://access.redhat.com/solutions/694583.

Was this helpful?

We appreciate your feedback. Leave a comment if you would like to provide more detail.
It looks like we have some work to do. Leave a comment to let us know how we could improve.
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.