How to use variables in Ansible dynamic inventory file?

1k Views Asked by At

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 ?

0

There are 0 best solutions below