# Only the vars associated with the first parent are getting defined even when the second parent is specified

**URL:** <https://forum.ansible.com/t/only-the-vars-associated-with-the-first-parent-are-getting-defined-even-when-the-second-parent-is-specified/14157>\
**Category:** Ansible Project\
**Created:** [December 14, 2013, 6:43am UTC](https://forum.ansible.com/t/only-the-vars-associated-with-the-first-parent-are-getting-defined-even-when-the-second-parent-is-specified/14157 "2013-12-14T06:43:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Cavedon](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@Mike\_Cavedon](https://forum.ansible.com/u/Mike_Cavedon)\
**Post date:** [December 14, 2013, 6:43am UTC](https://forum.ansible.com/t/only-the-vars-associated-with-the-first-parent-are-getting-defined-even-when-the-second-parent-is-specified/14157/1 "2013-12-14T06:43:45Z")

</div>

I have the following:

- name: router
- name: request\_router  
children: [router]  
vars:  
component\_script: ‘requestrouter.sh’  
process\_identifier: ‘log4j-dxad-web.xml’
- name: memcached\_router  
children: [router]  
vars:  
component\_script: ‘memcached-router.sh’  
process\_identifier: ‘log4j-memcached-router.xml’

When the following executes component\_script equals requestrouter.sh when it should equal memcached-router.sh.

- hosts: memcached\_router  
user: root  
vars\_files:

- vars/globals.yml  
tasks:

- include: task-to-execute.yml.

How do I get component\_script to be set as memcached-router.sh when using hosts: memcached\_router?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 14, 2013, 9:34pm UTC](https://forum.ansible.com/t/only-the-vars-associated-with-the-first-parent-are-getting-defined-even-when-the-second-parent-is-specified/14157/2 "2013-12-14T21:34:11Z")

</div>

So I am having trouble what children means here, this is not a playbook keyword and the system will yell about that … So a little confused.

– Michael

---

<div class="post-metadata">

**Author:** ![Mike\_Cavedon](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@Mike\_Cavedon](https://forum.ansible.com/u/Mike_Cavedon)\
**Post date:** [December 15, 2013, 4:43am UTC](https://forum.ansible.com/t/only-the-vars-associated-with-the-first-parent-are-getting-defined-even-when-the-second-parent-is-specified/14157/3 "2013-12-15T04:43:19Z")

</div>

Here is the issue reproduced. router is a child of both request\_router and memcached\_router. In order to kill request\_router, “log4j-dxad-web.xml” is looked for in the process running on the ‘router’ host. In order to kill memcached\_router, “log4j-memcached-router.xml” is looked for in the process running on the ‘router’ host.

(skytap\_env)-bash-4.1$ cat hosts  
[router]  
[router.releng.net](http://router.releng.net) ansible\_ssh\_host=172.24.233.2

[router:vars]

[request\_router]

[request\_router:vars]  
process\_identifier=log4j-dxad-web.xml

[request\_router:children]  
router

[memcached\_router]

[memcached\_router:vars]  
process\_identifier=log4j-memcached-router.xml

[memcached\_router:children]  
router

[matcher]  
[matcher.releng.net](http://matcher.releng.net) ansible\_ssh\_host=172.24.233.3

[matcher:children]  
ad\_matcher  
memcached\_matcher

[ad\_matcher]

[ad\_matcher:vars]  
process\_identifier=log4j-admatcher.xml

[memcached\_matcher]

[memcached\_matcher:vars]  
process\_identifier=log4j-memcached-matcher.xml

[realtime\_system\_components]

[realtime\_system\_components:vars]  
rts\_user=dxrts

[realtime\_system\_components:children]  
request\_router  
ad\_matcher  
(skytap\_env)-bash-4.1$

(skytap\_env)-bash-4.1$ cat ansible/kill.yml

- hosts: request\_router  
user: dataxu  
vars\_files:

- vars/globals.yml

- vars/realtime\_system.yml  
tasks:

- include: tasks/realtime\_system/kill.yml

- hosts: memcached\_router  
user: dataxu  
vars\_files:

- vars/globals.yml

- vars/realtime\_system.yml  
tasks:

- include: tasks/realtime\_system/kill.yml  
(skytap\_env)-bash-4.1$

(skytap\_env)-bash-4.1$ cat ansible/tasks/realtime\_system/kill.yml

- name: Kill process if not stopped gracefully  
shell: pgrep -f {{ process\_identifier }} && (echo “Killing”; pkill -9 -f {{ process\_identifier }});  
ignore\_errors: True

In the following, the second pgrep/kill command should be looking for log4j-memcached-router.xml

(skytap\_env)-bash-4.1$ ansible-playbook -v -i hosts ansible/kill.yml

PLAY [request\_router] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[router.releng.net](http://router.releng.net)]

TASK: [Kill process if not stopped gracefully] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [[router.releng.net](http://router.releng.net)] =\> {“changed”: true, “cmd”: "pgrep -f **log4j-dxad-web.xml** && (echo "Killing"; pkill -9 -f **log4j-dxad-web.xml** ); ", “delta”: “0:00:00.035682”, “end”: “2013-12-14 23:32:22.911873”, “item”: “”, “rc”: -9, “start”: “2013-12-14 23:32:22.876191”}  
stdout: 26041  
Killing  
…ignoring

PLAY [memcached\_router] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [Kill process if not stopped gracefully] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [[router.releng.net](http://router.releng.net)] =\> {“changed”: true, “cmd”: "pgrep -f **log4j-dxad-web.xml** && (echo "Killing"; pkill -9 -f **log4j-dxad-web.xml** ); ", “delta”: “0:00:00.030875”, “end”: “2013-12-14 23:32:28.376401”, “item”: “”, “rc”: -9, “start”: “2013-12-14 23:32:28.345526”}  
stdout: 26074  
Killing  
…ignoring

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[router.releng.net](http://router.releng.net) : ok=3 changed=2 unreachable=0 failed=0

If in the hosts file, I delete everything having to do with realtime\_system\_components (see first “cat hosts” above) which shouldn’t have anything to do with the kill commands, the opposite log4j xml file is looked for both times.

(skytap\_env)-bash-4.1$ cat hosts  
[router]  
[router.releng.net](http://router.releng.net) ansible\_ssh\_host=172.24.233.2

[router:vars]

[request\_router]

[request\_router:vars]  
process\_identifier=log4j-dxad-web.xml

[request\_router:children]  
router

[memcached\_router]

[memcached\_router:vars]  
process\_identifier=log4j-memcached-router.xml

[memcached\_router:children]  
router

[matcher]  
[matcher.releng.net](http://matcher.releng.net) ansible\_ssh\_host=172.24.233.3

[matcher:children]  
ad\_matcher  
memcached\_matcher

[ad\_matcher]

[ad\_matcher:vars]  
process\_identifier=log4j-admatcher.xml

[memcached\_matcher]

[memcached\_matcher:vars]  
process\_identifier=log4j-memcached-matcher.xml

(skytap\_env)-bash-4.1$ ansible-playbook -v -i hosts ansible/kill.yml

PLAY [request\_router] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[router.releng.net](http://router.releng.net)]

TASK: [Kill process if not stopped gracefully] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [[router.releng.net](http://router.releng.net)] =\> {“changed”: true, “cmd”: "pgrep -f **log4j-memcached-router.xml** && (echo "Killing"; pkill -9 -f log4j-memcached-router.xml); ", “delta”: “0:00:00.036037”, “end”: “2013-12-14 23:35:58.908763”, “item”: “”, “rc”: -9, “start”: “2013-12-14 23:35:58.872726”}  
stdout: 26152  
Killing  
…ignoring

PLAY [memcached\_router] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [Kill process if not stopped gracefully] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [[router.releng.net](http://router.releng.net)] =\> {“changed”: true, “cmd”: "pgrep -f **log4j-memcached-router.xml** && (echo "Killing"; pkill -9 -f log4j-memcached-router.xml); ", “delta”: “0:00:00.026807”, “end”: “2013-12-14 23:36:04.260145”, “item”: “”, “rc”: -9, “start”: “2013-12-14 23:36:04.233338”}  
stdout: 26185  
Killing  
…ignoring

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[router.releng.net](http://router.releng.net) : ok=3 changed=2 unreachable=0 failed=0

Mike

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 15, 2013, 4:30pm UTC](https://forum.ansible.com/t/only-the-vars-associated-with-the-first-parent-are-getting-defined-even-when-the-second-parent-is-specified/14157/4 "2013-12-15T16:30:48Z")

</div>

It’s hard to say what you’ve got in there wrong without seeing your entire playbook.

---

<div class="post-metadata">

**Author:** ![Mike\_Cavedon](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@Mike\_Cavedon](https://forum.ansible.com/u/Mike_Cavedon)\
**Post date:** [December 15, 2013, 6:29pm UTC](https://forum.ansible.com/t/only-the-vars-associated-with-the-first-parent-are-getting-defined-even-when-the-second-parent-is-specified/14157/5 "2013-12-15T18:29:40Z")

</div>

I’m pretty sure everything is in the post.

Re-post ansible/kill.yml:

-bash-4.1$ cat ansible/kill.yml

- hosts: request\_router  
user: dataxu  
vars\_files:

- vars/globals.yml

- vars/realtime\_system.yml  
tasks:

- include: tasks/realtime\_system/kill.yml

- hosts: memcached\_router  
user: dataxu  
vars\_files:

- vars/globals.yml

- vars/realtime\_system.yml  
tasks:

- include: tasks/realtime\_system/kill.yml  
-bash-4.1$

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 15, 2013, 8:49pm UTC](https://forum.ansible.com/t/only-the-vars-associated-with-the-first-parent-are-getting-defined-even-when-the-second-parent-is-specified/14157/6 "2013-12-15T20:49:43Z")

</div>

Yeah, I mean the task files to see what variables you are using, whether anything is hard coded, etc…

(This is probably best uploaded to [gist.github.com](http://gist.github.com))

---

<div class="post-metadata">

**Author:** ![Mike\_Cavedon](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@Mike\_Cavedon](https://forum.ansible.com/u/Mike_Cavedon)\
**Post date:** [December 15, 2013, 10:33pm UTC](https://forum.ansible.com/t/only-the-vars-associated-with-the-first-parent-are-getting-defined-even-when-the-second-parent-is-specified/14157/7 "2013-12-15T22:33:51Z")

</div>

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

-bash-4.1$ ansible-playbook -v -i **hosts** kill.yml

PLAY [request\_router] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[router.releng.net](http://router.releng.net)]

TASK: [Kill process if not stopped gracefully] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [[router.releng.net](http://router.releng.net)] =\> {“changed”: true, “cmd”: "pgrep -f **log4j-dxad-web.xml** && (echo "Killing"; pkill -9 -f **log4j-dxad-web.xml** ); ", “delta”: “0:00:00.034292”, “end”: “2013-12-15 17:31:13.982646”, “item”: “”, “rc”: -9, “start”: “2013-12-15 17:31:13.948354”}  
stdout: 13506  
Killing  
…ignoring

PLAY [memcached\_router] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [Kill process if not stopped gracefully] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [[router.releng.net](http://router.releng.net)] =\> {“changed”: true, “cmd”: "pgrep -f **log4j-dxad-web.xml** && (echo "Killing"; pkill -9 -f **log4j-dxad-web.xml** ); ", “delta”: “0:00:00.035120”, “end”: “2013-12-15 17:31:18.841508”, “item”: “”, “rc”: -9, “start”: “2013-12-15 17:31:18.806388”}  
stdout: 13523  
Killing  
…ignoring

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[router.releng.net](http://router.releng.net) : ok=3 changed=2 unreachable=0 failed=0

-bash-4.1$

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 16, 2013, 1:30pm UTC](https://forum.ansible.com/t/only-the-vars-associated-with-the-first-parent-are-getting-defined-even-when-the-second-parent-is-specified/14157/8 "2013-12-16T13:30:27Z")

</div>

Your problem is that the router has been added to both groups, and the variables overlap.

You probably want to move the variable into play level, with vars\_files, or similar.

The idea that variables are sourced from all groups is quite intentional, hosts may group by behavior or geography – for instance, a machine may be a webserver and also be running out of a particular datacenter and it might be addressed as “webservers” and need to pull in the info from the other geography-oriented group, etc.

---

<div class="post-metadata">

**Author:** ![Mike\_Cavedon](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@Mike\_Cavedon](https://forum.ansible.com/u/Mike_Cavedon)\
**Post date:** [December 16, 2013, 3:39pm UTC](https://forum.ansible.com/t/only-the-vars-associated-with-the-first-parent-are-getting-defined-even-when-the-second-parent-is-specified/14157/9 "2013-12-16T15:39:43Z")

</div>

If the same variable is defined for multiple parents ansible should be smart enough to return the value for the parent which is being referred to. At the very least, if this behavior is not going to be corrected, ansible should fail when the same variable is defined for multiple parents. Arbitrarily returning the value associated for any parent is a bug. I’ll work around it.
