awx icon indicating copy to clipboard operation
awx copied to clipboard

AWX 19.0+ OVIRT Inventory Source Doesn't work

Open rilindo opened this issue 3 years ago • 5 comments

Please confirm the following

  • [X] I agree to follow this project's code of conduct.
  • [X] I have checked the current issues for duplicates.
  • [X] I understand that AWX is open source software provided for free and that I am not entitled to status updates or other assurances.

Summary

I am trying to get AWX to use my OVIRT installation as an inventory, but it is failing to sync the hosts.

AWX version

AWX 19

Installation method

kubernetes

Modifications

no

Ansible version

What is included in AWX-EE (which is 2.11)

Operating system

CentOS Stream

Web browser

Firefox

Steps to reproduce

  1. Create ovirt credentials
  2. Add inventory
  3. Add inventory source
  4. Select ovirt credential.

Expected results

I should be able to sync inventory

Actual results

config file = None
configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections:/usr/share/automation-controller/collections
executable location = /usr/local/bin/ansible-inventory
python version = 3.8.6 (default, Jan 29 2021, 17:38:16) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
jinja version = 2.10.3
libyaml = True
No config file found; using defaults
[WARNING]: * Failed to parse /runner/inventory/ovirt.yml with auto plugin:
inventory config '/runner/inventory/ovirt.yml' specifies unknown plugin 'ovirt'
File "/usr/local/lib/python3.8/site-packages/ansible/inventory/manager.py", line 290, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/local/lib/python3.8/site-packages/ansible/plugins/inventory/auto.py", line 53, in parse
raise AnsibleParserError("inventory config '{0}' specifies unknown plugin '{1}'".format(path, plugin_name))
[WARNING]: Unable to parse /runner/inventory/ovirt.yml as an inventory source
ERROR! No inventory was parsed, please check your configuration and options.

Additional information

As far as I can tell, ovirt is included in the container:

bash-4.4$ ls -la /usr/share/ansible/collections/ansible_collections/
total 0
drwxr-xr-x. 13 root root 178 Sep  6 12:05 .
drwxr-xr-x.  3 root root  33 Sep  6 12:04 ..
drwxr-xr-x.  3 root root  17 Sep  6 12:05 amazon
drwxr-xr-x.  4 root root  34 Sep  6 12:05 ansible
drwxr-xr-x.  3 root root  17 Sep  6 12:05 awx
drwxr-xr-x.  3 root root  26 Sep  6 12:05 azure
drwxr-xr-x.  3 root root  20 Sep  6 12:05 community
drwxr-xr-x.  3 root root  19 Sep  6 12:05 google
drwxr-xr-x.  3 root root  18 Sep  6 12:05 kubernetes
drwxr-xr-x.  3 root root  19 Sep  6 12:05 openstack
drwxr-xr-x.  3 root root  19 Sep  6 12:05 ovirt
drwxr-xr-x.  3 root root  22 Sep  6 12:05 redhatinsights
drwxr-xr-x.  3 root root  21 Sep  6 12:05 theforeman

So it doesn't look like I should rebuild the container.

It seems to happen with most awx-ee versions, as I tried:

  • 0.1.1
  • 0.6.0
  • devel
  • latest

It seems to be similar to this PR:

https://github.com/ansible/awx/issues/9746

Notably, I am able to query the ovirt from within the awx-ee container:

bash-4.4$ ansible-inventory -i /runner/inventory/ --host cn01
{
    "affinity_groups": [],
    "affinity_labels": [],
    "cluster": "Default",
    "creation_time": "2021-07-25 01:56:17.680000+00:00",
    "creation_time_timestamp": 1627178177.68,
    "description": "",
    "devices": {
        "enp1s0": [
            "192.168.3.53",
            "fe80::6dc4:616d:ce22:a2af"
        ]
    },
    "fqdn": "cn01",
    "host": "ovirt04.example.com",
    "id": "b3f12479-0346-453a-848f-93947b7634e5",
    "name": "cn01",
    "os": "other_linux",
    "statistics": {
        "cpu.current.guest": 0.48,
        "cpu.current.hypervisor": 0.0,
        "cpu.current.total": 0.48,
        "cpu.usage.history": 0.0,
        "disks.usage": null,
        "elapsed.time": 1041019.0,
        "memory.buffered": 0.0,
        "memory.cached": 0.0,
        "memory.free": 1481633792.0,
        "memory.installed": 2147483648.0,
        "memory.unused": 724025344.0,
        "memory.usage.history": 31.0,
        "memory.used": 665719930.0,
        "migration.progress": 100.0,
        "network.current.total": 0.0,
        "network.usage.history": 0.0
    },
    "status": "up",
    "tags": [],
    "template": "Blank"
}

incidentally, this is what my inventory file looks like when I was testing from within the container:

---
plugin: ovirt.ovirt.ovirt
ovirt_url: https://ovirt-engine.example.com/ovirt-engine/api
ovirt_username: admin@internal
ovirt_password: mypassword

This suggests that the ovirt template was being generated with:

plugin: ovirt

Rather than:

plugin: ovirt.ovirt.ovirt

Though it is not clear how I can definitely prove that to be the case. I did try to specify plugin: ovirt.ovirt.ovirt in the source variables in an attempt to override the default, with no effects.

rilindo avatar Sep 08 '21 20:09 rilindo

same for AWX version 19.5.1

armagankaratosun avatar Jan 30 '22 23:01 armagankaratosun

Adding use_fqcn = True to class rhv in the file https://github.com/ansible/awx/blob/devel/awx/main/models/inventory.py fixes this issue:

class rhv(PluginFileInjector):
    """ovirt uses the custom credential templating, and that is all"""

    plugin_name = 'ovirt'
    base_injector = 'template'
    initial_version = '2.9'
    namespace = 'ovirt'
    collection = 'ovirt'
    downstream_namespace = 'redhat'
    downstream_collection = 'rhv'
    use_fqcn = True

hsahmed avatar Mar 29 '22 14:03 hsahmed

@mabashian the above issue is still present in the latest version (21.3) and is again fixed by adding the use_fqcn = True as above. Would it help if I send a pull request for the above change?

hsahmed avatar Jul 26 '22 09:07 hsahmed

Adding use_fqcn = True to class rhv in the file https://github.com/ansible/awx/blob/devel/awx/main/models/inventory.py fixes this issue:

class rhv(PluginFileInjector):
    """ovirt uses the custom credential templating, and that is all"""

    plugin_name = 'ovirt'
    base_injector = 'template'
    initial_version = '2.9'
    namespace = 'ovirt'
    collection = 'ovirt'
    downstream_namespace = 'redhat'
    downstream_collection = 'rhv'
    use_fqcn = True

Hi! Can you describe in detail how you solved this problem? Thanks in advance!

ingvarrwvw avatar Aug 09 '22 09:08 ingvarrwvw

@ingvarrwvw

On your AWX deployment, in the web container (if your deployment name is awx01 then the container is awx01-web), change the file /var/lib/awx/venv/awx/lib/python3.9/site-packages/awx/main/models/inventory.py with the changes in my comment (only change required is adding use_fqcn = True to the rhv class).

How to change this file in the container depends on your setup and deployment method. For AWX operator deployments, the file should work if added using custom volumes for web web_extra_volume_mounts check https://github.com/ansible/awx-operator#custom-volume-and-volume-mount-options

hsahmed avatar Aug 09 '22 13:08 hsahmed

@ingvarrwvw

On your AWX deployment, in the web container (if your deployment name is awx01 then the container is awx01-web), change the file /var/lib/awx/venv/awx/lib/python3.9/site-packages/awx/main/models/inventory.py with the changes in my comment (only change required is adding use_fqcn = True to the rhv class).

How to change this file in the container depends on your setup and deployment method. For AWX operator deployments, the file should work if added using custom volumes for web web_extra_volume_mounts check https://github.com/ansible/awx-operator#custom-volume-and-volume-mount-options

I added the specified parameter, connected this script as an external volume, but this did not solve the problem - the error is the same

ingvarrwvw avatar Aug 15 '22 12:08 ingvarrwvw

@ingvarrwvw it has to be done on both web and task containers. Below is my config map and deployment file (unchanged sections cropped for clarity):

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: ovirt-inventory-fix
  namespace: awx
data:
  inventory.py: |
    # Copyright (c) 2015 Ansible, Inc.
    # All Rights Reserved.

    # Python
    import datetime
--- CROPPED ---

    class rhv(PluginFileInjector):
        """ovirt uses the custom credential templating, and that is all"""

        plugin_name = 'ovirt'
        base_injector = 'template'
        initial_version = '2.9'
        namespace = 'ovirt'
        collection = 'ovirt'
        downstream_namespace = 'redhat'
        downstream_collection = 'rhv'
        use_fqcn = True

--- CROPPED ---

And in the deployment file:

  web_extra_volume_mounts: |
    - name: inventory-py
      mountPath: /var/lib/awx/venv/awx/lib/python3.9/site-packages/awx/main/models/inventory.py
      subPath: inventory.py

  task_extra_volume_mounts: |
    - name: inventory-py
      mountPath: /var/lib/awx/venv/awx/lib/python3.9/site-packages/awx/main/models/inventory.py
      subPath: inventory.py

hsahmed avatar Aug 15 '22 12:08 hsahmed

@ingvarrwvw it has to be done on both web and task containers. Below is my config map and deployment file (unchanged sections cropped for clarity):

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: ovirt-inventory-fix
  namespace: awx
data:
  inventory.py: |
    # Copyright (c) 2015 Ansible, Inc.
    # All Rights Reserved.

    # Python
    import datetime
--- CROPPED ---

    class rhv(PluginFileInjector):
        """ovirt uses the custom credential templating, and that is all"""

        plugin_name = 'ovirt'
        base_injector = 'template'
        initial_version = '2.9'
        namespace = 'ovirt'
        collection = 'ovirt'
        downstream_namespace = 'redhat'
        downstream_collection = 'rhv'
        use_fqcn = True

--- CROPPED ---

And in the deployment file:

  web_extra_volume_mounts: |
    - name: inventory-py
      mountPath: /var/lib/awx/venv/awx/lib/python3.9/site-packages/awx/main/models/inventory.py
      subPath: inventory.py

  task_extra_volume_mounts: |
    - name: inventory-py
      mountPath: /var/lib/awx/venv/awx/lib/python3.9/site-packages/awx/main/models/inventory.py
      subPath: inventory.py

Yes, when adding task_volume - worked now, thanks! This plugin allow to get the names of ovirt-nodes ?

ingvarrwvw avatar Aug 15 '22 14:08 ingvarrwvw