vars in inventory overwrite each other

52 views
Skip to first unread message

Christo Buschek

unread,
Jul 28, 2014, 7:58:22 AM7/28/14
to ansible...@googlegroups.com
I'm fairly new to Ansible, so maybe what I'm trying to do is bad anyway.

I use ansible to deploy all of our web applications. I use a special deploy playbook for every app. Now every app can be deployed to staging or production. For each of those environments I use a separate inventory such as `envs/staging'. Inside the inventory I use one group for every app and set certain environment specific variables in this way"

[app1]
app
.example.com
[app1:vars]
app
-port=3000
app_domain
=sub1.example.com


[app2]
app
.example.com
[app2:vars]
app
-port=3001
app_domain
=sub2.example.com

I would deploy an app like that: ansible-playbook -i envs/staging deploys/app2.yml -K

Now this doesn't work unfortunately. In my example it always takes the configuration of app1, even if I deploy app2. In my playbook for app2 I do have the following line: hosts: app2.

So my question would be, why is the playbook for app2 taking configuration options defined for app1? Do I use inventory variables wrong? Do otherpeople use ansible to deploy apps and how do they keep the environments separated?


UnlockYourBrain GmbH
c/o Smart Mobile Factory GmbH

Französische Str. 24

10117 Berlin

Germany


www.unlockyourbrain.com

Download at Google Play

Like us on Facebook


Geschäftsführer: Felix Nienstädt, Simon Smend

Unternehmenssitz: Berlin

Eingetragen am Handelsgericht Charlottenburg unter HRB 149905 B

Michael DeHaan

unread,
Jul 28, 2014, 10:11:56 AM7/28/14
to ansible...@googlegroups.com
Groups at the same level of depth will definitely override each other.

What you need to do is consider using role variables, or vars_files, or "vars", etc, or name the variable something like "app2_port"






--
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/c9a37542-c877-4b0d-884a-2a3aed53a2da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christo Buschek

unread,
Jul 29, 2014, 9:04:02 AM7/29/14
to ansible...@googlegroups.com
Okay, thanks for this info. I worked around it by creating a group_var file for each environment and import it into the playbook using vars_file. It works good enough for me.

Michael DeHaan

unread,
Jul 29, 2014, 9:33:41 AM7/29/14
to ansible...@googlegroups.com
Definitely do not import things out of "group_vars" with the vars_files directive, it would be ok to keep it in a different directory, but you are going to find this would confuse most ansible users using the directory for two purposes.




--
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.

Christo Buschek

unread,
Jul 29, 2014, 9:50:20 AM7/29/14
to ansible...@googlegroups.com
yeah, good point. Thanks.
> 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/XtoFnCQFwP0/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CA%2BnsWgyumGcLg2ktGY3w6QSO8vX0%2BKbMDEdenCn2kNhU5c7pXA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

--
*UnlockYourBrain GmbH*
c/o Smart Mobile Factory GmbH

Französische Str. 24

10117 Berlin

Germany


*www.unlockyourbrain.com <http://www.unlockyourbrain.com/>*

Download at *Google Play
<https://play.google.com/store/apps/details?id=co.unlockyourbrain&referrer=utm_source%3DMA%26utm_medium%3Demail%20footer%26utm_term%3Dgen%26utm_content%3Dgen%26utm_campaign%3Dgen>*

Like us on *Facebook*
Reply all
Reply to author
Forward
0 new messages