RHV 4.1 / RHEV 4.1 Dynamic Inventory For Ansible Tower

Out of the box Ansible Tower 3.1.2 does not come with the Red Hat Virtualization 4.0 provider. You will find the instructions here to get it working:

Step 1: SSH into the ansible tower

[dobby@dobby ~]$ ssh root@tower.local.domb.com

Step 2: Install ovirt-engine-sdk-python

[root@towerldo ~]# yum install ovirt-engine-sdk-python

Step 3: cd into /opt/rh and get the ovirt.ini file

[root@towerldo ~]# cd /opt/rh
[root@towerldo ~]# wget https://raw.githubusercontent.com/ldomb/rhv4-for-tower/master/ovirt.ini

Step 4: Edit the values in /opt/rh/ovirt.ini with your correct RHV4 url (the path after your FQDN is “ovirt-engine/api” and password for the admin user

[root@towerldo ~]# cat /opt/rh/ovirt.ini
# Ansible RHV ini file
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible.  If not, see .

# Author: Laurent Domb based on Josha Inglis ovirt.ini for ovirt 3.6 and the gce.ini by Eric Johnson

[ovirt]
# ovirt Service Account configuration information can be stored in the
# libcloud ‘secrets.py’ file. Ideally, the ‘secrets.py’ file will already
# exist in your PYTHONPATH and be picked up automatically with an import
# statement in the inventory script. However, you can specify an absolute
# path to the secrets.py file with ‘libcloud_secrets’ parameter.
ovirt_api_secrets =

# If you are not going to use a ‘secrets.py’ file, you can set the necessary
# authorization parameters here.
ovirt_url = https://rhv.local.domb.com/ovirt-engine/api
ovirt_username = admin@internal
ovirt_password = iloveopensource

Step 5. Now login into ansible tower as privileged user who is allowed to add an inventory.

towerlogin

Step 6. Got to Settings
settings
Inventory Scripts
inventoryscripts

And click on “Create a new custom inventory”
add

Step 7. Add a name
name

Step 8. For the Custom Script get the https://raw.githubusercontent.com/ldomb/rhv4-for-tower/master/ovirt.py and paste the content into the field
custom

and click save
save

Step 9. click on inventories
inventories
and add
add

Step 10. In new inventory enter a name for you new RHV4 inventory
newinventory
and hit save
save
You will get redirected to the groups page where you create new group (+ ADD GROUP).
group

Step 11. For inventory choose custom script and add the script we added in step 7 under Custom Inventory Script
group2

Step 12. Once saved go back to the inventories tab and click on you new inventory
save

Step 13. You can new sync your new inventory by pressing the sync button
sync

Step 14. If everything goes well you should see something like
outputrhev