Variables About Other Hosts

13 views
Skip to first unread message

Raul SEVILLA CAÑAVATE

unread,
Jun 29, 2015, 9:24:52 AM6/29/15
to ansible...@googlegroups.com

I'm getting problems while trying to access variables from another host in my Ansible template.
I'm using a SSH proxycommand configuration to access 'internal' instances in EC2.
My inventory host file is like:

cat  /etc/hosts
[test1]
test1
[test2]
test2

My SSH configuration:

Host test1
User ubuntu
IdentityFile /home/dev/.ssh/private-key
Hostname XX.XX.XX.XX
StrictHostKeyChecking no

Host test2
User ubuntu
IdentityFile /home/dev/.ssh/private-key
Hostname 10.0.1.10
ProxyCommand ssh -F /home/dev/thing/ssh_config -W %h:%p test1
StrictHostKeyChecking no
ControlMaster auto
ControlPath /home/dev/.ssh/tmp/%h_%p_%r

and my template is like:

{{ hostvars['test1'] }}
{{ hostvars['test2'] }}

The first line in the previous template gives me all host variables, but the second, only shows:
{'inventory_hostname': 'test2', 'group_names': ['test2'], 'inventory_hostname_short': 'test2'}

How do i fix it?

Brian Coca

unread,
Jul 2, 2015, 5:41:36 PM7/2/15
to ansible...@googlegroups.com
soo .. you should really not overwrite /etc/hosts to make it your
inventory, this might break many things in your system, by default
ansible uses /etc/ansible/hosts which should not affect anything else.

what vars are you expecting? where are they defined?

--
Brian Coca
Reply all
Reply to author
Forward
0 new messages