EC2 dynamic inv and group_vars not working.

14 views
Skip to first unread message

Leszek Niewiadomski

unread,
May 11, 2017, 2:35:08 PM5/11/17
to Ansible Project
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.

Kai Stian Olstad

unread,
May 12, 2017, 10:36:01 AM5/12/17
to ansible...@googlegroups.com
On 10. mai 2017 10:36, Leszek Niewiadomski wrote:
> 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']


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages