1
我想使用变量来定义我想要使用的接口。Ansible 2:是否可以使用变量作为字典键
而下面的剧本不起作用:
- hosts: all
vars:
eth_to_use: eth0
tasks:
- debug: msg="{{ansible_{{eth_to_use}}.ipv4.address}}"
我想使用变量来定义我想要使用的接口。Ansible 2:是否可以使用变量作为字典键
而下面的剧本不起作用:
- hosts: all
vars:
eth_to_use: eth0
tasks:
- debug: msg="{{ansible_{{eth_to_use}}.ipv4.address}}"
我知道这样说:
- hosts: localhost
vars:
eth_to_use: en0
tasks:
- debug: msg="{{hostvars[inventory_hostname]['ansible_'+eth_to_use].ipv4[0].address}}"
不错,如果通过IPv4的 –
@NelsonG'ipv4' [0]取代IPv4作品这里是一个列表,所以你不能只调用'ipv4.address' –