How to access ansible_$interface where $interface is a registered value?

Hello, ansible experts.
I have a question regarding accessing ansible facts.

I have a system with interface named randomly and dynamically.
I successfully retrieved int name and registered it to variable.
Now, I want to know the IP address of it with ansible facts but how can I access it?

I tried to access “ansible_$interface” with following code,
`

  • name: retrieve interface
    (snip)
    register: interface

  • debug: msg=“{{ ansible_$interface.stdout[‘ipv4’][‘address’]}}”
    `

but all I got was simple characters.

ok: [node4] => { "msg": "{{ansible_$linked_bridge.stdout['ipv4']['address']}}" }

I know it’s a very fundamental question, but this variable problems always get in my way :frowning:

Here you go:

Hurray! thank you, Mr.Maciej

I never thought this simple :slight_smile:

2014年6月26日木曜日 16時59分59秒 UTC+9 Maciej Delmanowski:

Ansible has not supported $ substitution in a very very long time.

To generate a variable name programatically, do this through hostvars:

{[ hostvars[inventory_hostname][‘ansible_’ + linked + ‘_bridge’][‘stdout’][‘ipv4’][‘address’] }}