1

I am currently trying to use the Ovirt dynamic inventory module to create an inventory based on a patttern. I would like to be able to put variables in my inventory file like in a normal YAML file in order to use this inventory file for differents clusters and environments.

Here is my current inventory file and the ansible-playbook command

$ ansible-playbook -i inventory_ovirt.yml playbook.yaml --extra-vars "engine_url=https://rhv-cluster.example.com/ovirt-engine/api engine_user=user@ldap engine_password=pass"
---

plugin: ovirt.ovirt.ovirt
ovirt_url: "{{ engine_url }}"
ovirt_cafile: ""
ovirt_username: "{{ engine_user }}"
ovirt_password: "{{ engine_password }}"
ovirt_query_filter:
  search: 'name=*'
  case_sensitive: no

...

The playbook doesn't matter, as this error is happening before the playbook tasks.

- hosts: all
  gather_facts: false
  tasks:
    - ping:

Ansible is throwing this error :

Failed to parse inventory_ovirt.yml with auto plugin, Error during SSO authentcation access_denied : Cannot authenticate user '{{ engine_user }}@N/A': No valid profile found in credentials.

I was exptecting my inventory file to be constructed with the extra_vars i'm passing to Ansible at launch. Unfortunately, Ansible is interprating this as text.

Is there another method to use variables in a dynamic inventory file, or maybe to build it with variable before running the playbook ?

Alban V
  • 13
  • 5
  • Please provide a [mre] as an [edit] to your question. – Zeitounator Mar 24 '23 at 13:43
  • I do not think you can use variables for those parameters, at the very least for this particular plugin. Meanwhile, the [documentation](https://docs.ansible.com/ansible/latest/collections/ovirt/ovirt/ovirt_inventory.html#parameter-ovirt_password) states you can use `OVIRT_PASSWORD` and `OVIRT_USERNAME` environment variables in your current shell. So the easiest way is probably to not set them in your file but directly in your env. – Zeitounator Mar 28 '23 at 12:23

0 Answers0