Skip to content

Instantly share code, notes, and snippets.

@rgolangh
Last active August 16, 2017 06:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rgolangh/1b90261f5a517d70afba0be31154d062 to your computer and use it in GitHub Desktop.
Save rgolangh/1b90261f5a517d70afba0be31154d062 to your computer and use it in GitHub Desktop.
Build an ovirt lab using ansible
---
- hosts: localhost
connection: local
vars:
#engine_prefix: /
engine_url: "http://example.com:8080/ovirt-engine/api"
engine_user: admin@internal
engine_password: PASSWORD
engine_insecure: true
#engine_cafile: /etc/pki/ovirt-engine/ca.pem
dc:
name: fakedc
data_domain_name: fakedata1
cluster:
name: fakecl
hosts:
count: 300
start: 1
spm_name: spm.fake
vms:
count: 3000
disks:
count: 1
template:
name: faketemplate1
engine_config:
InstallVds: "false"
UseHostNameIdentifier: "true"
SSLEnabled: "false"
EncryptHostCommunication: "false"
MaxNumberOfHostsInStoragePool: 1000
VdsRefreshRate: 3
post_tasks:
- name: Logout from oVirt
ovirt_auth:
state: absent
ovirt_auth: "{{ ovirt_auth }}"
tags:
- always
tasks:
- name: Engine config for fake lab
shell: "echo {{ item.key }}= | {{ engine_prefix|default('/usr') + '/bin' }}/engine-config -s {{ item.key }}={{ item.value }} --cver=general -p /proc/self/fd/0"
with_dict: "{{ engine_config }}"
tags:
- config
- name: "wait till engine to starts up"
uri:
url: "http://127.0.0.1:8080/ovirt-engine/services/health"
status_code: 200
register: result
until: result.status == 200
retries: 60
delay: 1
- name: Wait till vdsmfake is listening
uri:
url: "http://127.0.0.1:8081"
status_code: 200
register: result
until: result.status == 200
retries: 60
delay: 1
- name: Set NetworkManager to use dnsmasq
ini_file:
dest: /etc/NetworkManager/conf.d/dns.conf
option: dns
value: dnsmasq
section: main
become: true
- name: Resolve vdsm.fake to 127.0.0.1
copy:
dest: /etc/NetworkManager/dnsmasq.d/vdsmfake.conf
content: address=/vdsm.fake/127.0.0.1
become: true
- service:
name: NetworkManager
state: reloaded
become: true
- ovirt_auth:
url: "{{ engine_url }}"
username: "{{ engine_user }}"
password: "{{ engine_password }}"
ca_file: "{{ engine_cafile | default(omit) }}"
insecure: "{{ engine_insecure | default(true) }}"
tags:
- auth
- name: Create fake DC
ovirt_datacenters:
auth: "{{ ovirt_auth }}"
name: "{{ dc.name }}"
local: false
- name: Add Fake cluster
ovirt_clusters:
auth: "{{ ovirt_auth }}"
name: "{{ cluster.name }}"
data_center: "{{ dc.name }}"
cpu_type: Intel SandyBridge Family
- name: 1st Host
ovirt_hosts:
auth: "{{ ovirt_auth }}"
state: present
cluster: "{{ cluster.name }}"
name: "{{ hosts.spm_name }}"
address: spm.vdsm.fake
password: secret
comment: fake host on fake vdsm
- name: Add data domain
ovirt_storage_domains:
auth: "{{ ovirt_auth }}"
name: "{{ dc.data_domain_name }}"
host: "{{ hosts.spm_name }}"
data_center: "{{ dc.name }}"
nfs:
address: nowhere.hereaswell1
path: /path/data
version: auto
- name: Wait for dc to become active
ovirt_datacenters:
auth: "{{ ovirt_auth }}"
name: "{{ dc.name }}"
state: present
register: result
retries: 10
delay: 10
until: result.datacenter.status == "up"
- name: Add Hosts
ovirt_hosts:
auth: "{{ ovirt_auth }}"
state: present
cluster: "{{ cluster.name }}"
name: fake{{ item }}
address: fake{{ item }}.vdsm.fake
password: secret
with_sequence: count={{ hosts.count }} start={{ hosts.start }}
poll: 0
async: 300
tags:
- hosts
- name: Add vms
ovirt_vms:
auth: "{{ ovirt_auth }}"
cluster: "{{ cluster.name }}"
name: "fakeblank_{{ item }}"
nics:
- name: nic1
boot_devices:
- network
with_sequence: count={{ vms.count }}
register: addvms
async: 20
poll: 0
tags:
- vms
- name: Create disks
ovirt_disks:
auth: "{{ ovirt_auth }}"
vm_name: "fakeblank_{{ item }}"
name: "disk_of_vm_fakeblank_{{ item }}"
size: 1GiB
format: cow
interface: virtio
storage_domain: "{{ dc.data_domain_name }}"
with_sequence: count={{ vms.count }}
...
@mordechai
Copy link

mordechai commented Mar 6, 2017

# avoid headache of api version mismatch

  • pip:
    name: ovirt-engine-sdk-python
    version: '{{ovirt_version}}'

@rgolangh
Copy link
Author

rgolangh commented Mar 7, 2017

@mordechai nice! Adding it.

@rgolangh
Copy link
Author

rgolangh commented Mar 7, 2017

Will also add a oVirt/ovirt-vdsmfake task that will invoke it. Possibly we could add a task to configure dnsmasq to start with resolving a {{ vdsm-prefix }} to 127.0.0.1

@rgolangh
Copy link
Author

rgolangh commented Mar 7, 2017

@mordechai can you verify?

@rgolangh
Copy link
Author

This work can be replaced totally by the latest roles https://github.com/oVirt/ovirt-ansible/tree/master/roles/ovirt-infra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment