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
# 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 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.


Step 6. Got to Settings
Inventory Scripts

And click on “Create a new custom inventory”

Step 7. Add a 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

and click save

Step 9. click on inventories
and add

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

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

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

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

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

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

  1. 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!
    Alessio Dini

    1. You could do this:

      [cc lang=”yaml”]

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

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

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

      – name: set vms
      vm: “{{ item.name }}: {{ item.snapshots |
      map(attribute=’description’) | join(‘,’) }}”
      with_items: “{{ ovirt_vms }}”
      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
      var: vms

  2. I am trying to bring in the Satellite inventory into the ansible tower. I am seeing this error.
    How to deal with this?

    2.183 INFO Updating inventory 10: Red Hat Satellite
    2.210 INFO Reading Ansible inventory source: /var/lib/awx/venv/awx/lib/python2.7/site-packages/awx/plugins/inventory/foreman.py
    Traceback (most recent call last):
    File “/usr/bin/awx-manage”, line 9, in
    load_entry_point(‘awx==3.2.3’, ‘console_scripts’, ‘awx-manage’)()
    File “/lib/python2.7/site-packages/awx/__init__.py”, line 107, in manage
    File “/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py”, line 354, in execute_from_command_line
    File “/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py”, line 346, in execute
    File “/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py”, line 394, in run_from_argv
    self.execute(*args, **cmd_options)
    File “/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py”, line 445, in execute
    output = self.handle(*args, **options)
    File “/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py”, line 661, in handle
    return self.handle_noargs(**options)
    File “/lib/python2.7/site-packages/awx/main/management/commands/inventory_import.py”, line 995, in handle_noargs
    File “/lib/python2.7/site-packages/awx/main/management/commands/inventory_import.py”, line 245, in load_inventory_source
    File “/lib/python2.7/site-packages/awx/main/management/commands/inventory_import.py”, line 180, in load
    File “/lib/python2.7/site-packages/awx/main/management/commands/inventory_import.py”, line 163, in command_to_json
    RuntimeError: ansible-inventory failed (rc=1) with stdout:

    [WARNING]: * Failed to parse /var/lib/awx/venv/awx/lib/python2.7/site-
    packages/awx/plugins/inventory/foreman.py with script plugin: Inventory script
    packages/awx/plugins/inventory/foreman.py) had an execution error:
    InsecureRequestWarning: Unverified HTTPS request is being made. Adding
    certificate verification is strongly advised. See:
    InsecureRequestWarning) Traceback (most recent call last): File
    packages/awx/plugins/inventory/foreman.py”, line 379, in
    sys.exit(not ForemanInventory().run()) File
    packages/awx/plugins/inventory/foreman.py”, line 374, in run
    self.get_inventory() File “/var/lib/awx/venv/awx/lib/python2.7/site-
    packages/awx/plugins/inventory/foreman.py”, line 327, in get_inventory
    self.update_cache() File “/var/lib/awx/venv/awx/lib/python2.7/site-
    packages/awx/plugins/inventory/foreman.py”, line 236, in update_cache for
    host in self._get_hosts(): File “/var/lib/awx/venv/awx/lib/python2.7/site-
    packages/awx/plugins/inventory/foreman.py”, line 170, in _get_hosts return
    self._get_json(“%s/api/v2/hosts” % self.foreman_url) File
    packages/awx/plugins/inventory/foreman.py”, line 149, in _get_json
    ret.raise_for_status() File “/var/lib/awx/venv/ansible/lib/python2.7/site-
    packages/requests/models.py”, line 928, in raise_for_status raise
    HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 404
    Client Error: Not Found for url: https://vxrsatmgt01.tpt01.rdu.bcbsnc.com/users

    [WARNING]: * Failed to parse /var/lib/awx/venv/awx/lib/python2.7/site-
    packages/awx/plugins/inventory/foreman.py with ini plugin:
    packages/awx/plugins/inventory/foreman.py:24: Expected key=value host variable
    assignment, got: __future__

    [WARNING]: Unable to parse /var/lib/awx/venv/awx/lib/python2.7/site-
    packages/awx/plugins/inventory/foreman.py as an inventory source

    ERROR! No inventory was parsed, please check your configuration and options.

Leave a Reply

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


This site uses Akismet to reduce spam. Learn how your comment data is processed.