EC2 dynamic inv and group_vars not working.

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.

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']