Choose inventory hosts.ini file based on condition

I have different staging environments under inventory.

Inventory/
Qa/
   Group_vars
   hosts.ini
Uat/
   group_vars
   hosts.ini
Prod/
   group_vars
   hosts.ini

I want to choose inventory file based on environment.

Within my playbooks I also use env variable.

When I run my ansible playbook like this it doesn't work. How can I do this?

ansible-playbook -i inventory/{{ env }}/ -e "env=prod"

Are you using right format? I can see Prod in inventory but in variable you used prod . Check the spelling

I have different staging environments under inventory.

[...]

Prod/
   group_vars
   hosts.ini

[...]

When I run my ansible playbook like this it doesn't work. How can I do this?

ansible-playbook -i inventory/{{ env }}/ -e "env=prod"

Is it 'prod' or 'Prod'?

I'm not sure if that (having {{ env }} in path) can work. AFAIR you
need a path to the hosts files. Have you tried ansible-playbook -i
inventory/Prod/hosts.ini?

Wawrzek

Sorry that prod / Prod is a typo.
I’m basically using same at both places.

I think 'hosts.ini' is missing from your command.

Wawrzek