# EC2 dynamic inv and group\_vars not working.

**URL:** <https://forum.ansible.com/t/ec2-dynamic-inv-and-group-vars-not-working/24444>\
**Category:** Ansible Project\
**Created:** [May 10, 2017, 8:36am UTC](https://forum.ansible.com/t/ec2-dynamic-inv-and-group-vars-not-working/24444 "2017-05-10T08:36:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leszek\_Niewiadomski](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Leszek\_Niewiadomski](https://forum.ansible.com/u/Leszek_Niewiadomski)\
**Post date:** [May 10, 2017, 8:36am UTC](https://forum.ansible.com/t/ec2-dynamic-inv-and-group-vars-not-working/24444/1 "2017-05-10T08:36:19Z")

</div>

Hello. I’ve got problem with dynamic inventory and group\_vars working in ansible:

Directory layout

`

- inventories
- scale
- ec2.py
- ec2.ini
- hosts
- group\_vars - link to …/…/group\_vars
- group\_vars
- roles
- playbook.yml
- ansible.cfg

`

group\_vars/scale\_webservers

`  
filebeat\_gatherlogs:

- apache
- exim  
`

Hosts file:

`  
[localhost]  
127.0.0.1

[tag\_Type\_sap]

[scale\_webservers:children]  
tag\_Type\_sap  
`

Running it shows variable is not defined:

`

ansible@ansible0:/usr/local/ansible$ ansible -i inventories/scale scale\_webservers -m debug -a “var=hostvars[‘filebeat\_gatherlogs’]”  
sap0 | SUCCESS =\> {  
“hostvars[‘filebeat\_logs’]”: “VARIABLE IS NOT DEFINED!”  
}  
`

Please help me solving it out. At least give me clues what have i did wrong.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 12, 2017, 2:35pm UTC](https://forum.ansible.com/t/ec2-dynamic-inv-and-group-vars-not-working/24444/2 "2017-05-12T14:35:47Z")

</div>

You are using the hostvars wrong. The first parameter is the hostname and the second is the variable.

hostvars[inventory\_hostname].filebeat\_logs

or

vars['filebeat\_logs']
