# Strange variable issue

**URL:** <https://forum.ansible.com/t/strange-variable-issue/15197>\
**Category:** Ansible Project\
**Created:** [May 8, 2014, 5:27pm UTC](https://forum.ansible.com/t/strange-variable-issue/15197 "2014-05-08T17:27:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petr\_Sukharev](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@Petr\_Sukharev](https://forum.ansible.com/u/Petr_Sukharev)\
**Post date:** [May 8, 2014, 5:27pm UTC](https://forum.ansible.com/t/strange-variable-issue/15197/1 "2014-05-08T17:27:55Z")

</div>

Hi!

I have multiple projects and try to use ansible for all of them.

One of idea was to make my playbooks more flexible by specified variable files for each project. In this case i have one role - deploy software and multiple playbooks with config like this

But when i try to use some variables from dbvars file for hosts in db group - ansible say that cant find this variable. If i specified in this host group project\_name - all work fine… It make me little confused, because i specified this variable for all hosts on top…

---

<div class="post-metadata">

**Author:** ![Petr\_Sukharev](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@Petr\_Sukharev](https://forum.ansible.com/u/Petr_Sukharev)\
**Post date:** [May 8, 2014, 5:31pm UTC](https://forum.ansible.com/t/strange-variable-issue/15197/2 "2014-05-08T17:31:11Z")

</div>

Try to insert nice code from playbook and fail 🙂

Here is current link

[https://gist.github.com/anonymous/35117b7088079fba8af4](https://gist.github.com/anonymous/35117b7088079fba8af4)

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [May 9, 2014, 3:42pm UTC](https://forum.ansible.com/t/strange-variable-issue/15197/3 "2014-05-09T15:42:08Z")

</div>

I might be missing something but using group\_vars solves this problem  
cleanly for me.

group\_vars/all are 'globals'  
group\_vars/webservers are available to all webservers

and so on.

---

<div class="post-metadata">

**Author:** ![Petr\_Sukharev](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@Petr\_Sukharev](https://forum.ansible.com/u/Petr_Sukharev)\
**Post date:** [May 9, 2014, 4:06pm UTC](https://forum.ansible.com/t/strange-variable-issue/15197/4 "2014-05-09T16:06:50Z")

</div>

Thanks for your reply!

I have multiple projects and each of them have webservers, bases or other groups. With your solution i need to use various names for this groups - test\_app, prod1\_app, prod2\_app and others… It will be real hard to manage all this group names

My point is - why variable from “all” section in playbook doesnt work in lower part of same playbook - for app or db hosts. And how to deal with it 🙂

---

<div class="post-metadata">

**Author:** ![Renald\_Casagraude](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@Renald\_Casagraude](https://forum.ansible.com/u/Renald_Casagraude)\
**Post date:** [May 9, 2014, 8:14pm UTC](https://forum.ansible.com/t/strange-variable-issue/15197/5 "2014-05-09T20:14:34Z")

</div>

Do you need to use defaults/main.yml for sane defaults inside your role ?

R.

---

<div class="post-metadata">

**Author:** ![Petr\_Sukharev](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@Petr\_Sukharev](https://forum.ansible.com/u/Petr_Sukharev)\
**Post date:** [May 10, 2014, 7:27pm UTC](https://forum.ansible.com/t/strange-variable-issue/15197/6 "2014-05-10T19:27:48Z")

</div>

Сб. 10 мая 2014 00:14:34, Rénald Casagraude писал:

> Do you need to use defaults/main.yml for sane defaults inside your role ?
> 
> R.

This file keep variables for role. I need variable for all host groups in playbook. I think, best way is use -e key, or write this variable in inventory file.. Hmm, try this solution tommorow...
