Reputation: 5441
I want to use a variable to define which interface I want to use.
And the following playbook doesn't work:
- hosts: all
vars:
eth_to_use: eth0
tasks:
- debug: msg="{{ansible_{{eth_to_use}}.ipv4.address}}"
Upvotes: 1
Views: 546
Reputation: 68329
I know about this way:
- hosts: localhost
vars:
eth_to_use: en0
tasks:
- debug: msg="{{hostvars[inventory_hostname]['ansible_'+eth_to_use].ipv4[0].address}}"
Upvotes: 3