-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Welcome to the ovirt-ansible-example wiki!
This wiki will will go through playbooks created in this repository and explain how to setup environment.
Since oVirt Ansible modules are not yet part of the offical Ansible modules. We host them in this repository in library directory. These modules needs some helper utilities, which will be part of the Ansible as well in near future, but for now, we need to use these helper utilities from external upstream library called ovirt-ansible. So before using the modules please install this library as follows:
pip install ovirt-ansible
Once our utilitie will be part of the Ansible project, this step won't be needed. To check current status see this PR.
First we need to clone the git repository:
git clone [email protected]:machacekondra/ovirt-ansible-example.git
├── inventory
│ └── hosts
├── library
│ ├── ovirt_auth.py
│ ├── ovirt_clusters.py
│ ├── ovirt_datacenters.py
│ ├── ovirt_groups.py
│ ├── ovirt_hosts.py
│ ├── ovirt_networks.py
│ ├── ovirt_nics.py
│ ├── ovirt_permissions.py
│ ├── ovirt_snapshots.py
│ ├── ovirt_storage_domains.py
│ ├── ovirt_templates.py
│ └── ovirt_users.py
├── playbooks
│ ├── destroy_demo.yml
│ ├── library -> ../library
│ ├── ovirt_password.yml
│ └── setup_demo.yml
Examples structure may be familiar to you if you ever run any Ansible examples. The library directory contains all oVirt modules, which we will be using. inventory directory contains hosts file, which we will be using as our static inventory file. And finally playbooks directory, this directory contains our example playbooks.
This paragraph will finally go you through the playbooks and what they does.
First we need to create vault with oVirt user password, so we don't use this password in plaintext. There is tool which make it easy for your, just enter this command:
ansible-vault create ovirt_password.yml
This will fire up your editor. Create there password variable with password of your admin@internal user:
password: MySuperPasswordOfAdminAtInternal
Next it will ask your for a vault password and then it creates ovirt_password.yml file, with your vault.
This playbook contains tasks which will setup the oVirt environment, assuming that you have already your oVirt installed.
First line of playbook is yaml magic. Second line describes what the playbook does. The third line specifies the hosts which will be used. For the oVirt deployment it must be a host which has ovirt-anisble
library installed and must reach the oVirt machine.
---
- name: Setup oVirt environment
hosts: ovirt
First task will include our password of the oVirt API user and stores it in password variable.
- name: Include oVirt password
no_log: true
include_vars: ovirt_password.yml
Second task will obtain the SSO token using ovirt_auth module using varibales which we degined in inventory/hosts_ file. The SSO token will be revoked at the always at the end, even if some playbook will fail. As we are using Ansible block feature. The ovirt_auth module will create an ovirt_auth fact, which contain the SSO token, which we will be using later on in all modules.
- block
- name: Obtain SSO token
no_log: true
ovirt_auth:
url: "{{ url }}"
username: "{{ username }}"
password: "{{ password }}"
ca_file: "{{ ca_file }}"
...another tasks...
always:
- name: Revoke the SSO token
ovirt_auth:
state: absent
ovirt_auth: "{{ ovirt_auth }}"
To execute the playbook run following command from the clonned repository directory:
ansible-playbook -i inventory/hosts playbooks/setup_demo.yml --ask-vault-pass