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

3 thoughts on “RHV 4.1 / RHEV 4.1 Dynamic Inventory For Ansible Tower

  • Hello,
    I follow your site from long time, you are incredible!
    I have a stupid question:
    what if I just want to attach ansible and RHEV, and I would like to get “objects” info from RHEV. I mean running a playbook obtaining for example guests names list, guests operating systems types, etc.etc. without starting or stopping something. I just need to get infos about guests, clusters, and so on for a specific farm.

    Thank you for your time!
    Regards
    Alessio Dini

    • You could do this:

      [cc lang=”yaml”]

      – hosts: localhost
      connection: local
      vars_files:
      – ../vars.yml

      tasks:
      – name: Obtain SSO token
      ovirt_auth:
      url: “{{ url }}”
      username: “{{ username }}”
      password: “{{ password }}”
      insecure: “{{ insecure }}”

      – name: List vms
      ovirt_vms_facts:
      fetch_nested: true
      nested_attributes:
      – description
      auth: “{{ ovirt_auth }}”

      – name: set vms
      set_fact:
      vm: “{{ item.name }}: {{ item.snapshots |
      map(attribute=’description’) | join(‘,’) }}”
      with_items: “{{ ovirt_vms }}”
      loop_control:
      label: “{{ item.name }}”
      register: all_vms

      – name: make a list
      set_fact: vms=”{{ all_vms.results | map(attribute=’ansible_facts.vm’) |
      list }}”

      – name: Print vms
      debug:
      var: vms
      [/cc]

Leave a Reply

Your email address will not be published. Required fields are marked *

*


Hit Counter provided by laptop reviews