Choose inventory hosts.ini file based on condition

23 views
Skip to first unread message

Saranya N

unread,
May 28, 2019, 11:31:53 AM5/28/19
to Ansible Project
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"

vinoth kumar

unread,
May 31, 2019, 1:21:00 AM5/31/19
to ansible...@googlegroups.com
Are you using right format? I can see Prod in inventory but in variable you used prod . Check the spelling 

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a3626294-830b-45a3-933e-d5b3cf29694f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Wawrzek Niewodniczanski

unread,
Jun 3, 2019, 8:08:36 AM6/3/19
to ansible...@googlegroups.com
On Tue, 28 May 2019 at 16:31, Saranya N <saranya...@gmail.com> wrote:
>
> 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
--
Dr Wawrzyniec Niewodniczański or Wawrzek for short
PhD in Quantum Chemistry & MSc in Molecular Engineering
WWW: http://wawrzek.name E-MAIL: jo...@wawrzek.name
Linux User #177124

Saranya Nagaraj

unread,
Jun 3, 2019, 9:37:05 PM6/3/19
to ansible...@googlegroups.com
Sorry that prod / Prod is a typo.
I'm basically using same at both places.

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/GcxV5MRlGrg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAC7-vpABq7GXHvCjRqZFYeEu8-3ACurLnRefqGtYUigTQiPO-A%40mail.gmail.com.

Wawrzek Niewodniczanski

unread,
Jun 4, 2019, 2:59:06 AM6/4/19
to ansible...@googlegroups.com
On Tue, 4 Jun 2019 at 02:36, Saranya Nagaraj <saranya...@gmail.com> wrote:
>
> Sorry that prod / Prod is a typo.
> I'm basically using same at both places.
>

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

I think 'hosts.ini' is missing from your command.
Reply all
Reply to author
Forward
0 new messages