2017-09-30 143 views
0

我有一个jinja模板,需要填充我的服务器的辅助ip。ansible ipv4辅助IP过滤

我试着运行下面的代码,它比我所需要的要多一点点。

tasks: 
    - name: debug2 
    debug: msg={{ ansible_enp0s8_iface1.ipv4_secondaries }} 

结果

ok: [localhost] => { 
"msg": [ 
    { 
     "address": "172.16.2.20", 
     "broadcast": "172.16.2.255", 
     "netmask": "255.255.255.0", 
     "network": "172.16.2.0" 
    } 
] 
} 

然而,当我运行以下

tasks: 
    - name: debug2 
    debug: msg={{ ansible_enp0s8_iface1.ipv4_secondaries.address }} 

我得到以下致命错误指示 “地址” 是不确定的。我不知道为什么会这样,因为它与主界面

fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'list object' has no attribute 'address'\n\nThe error appears to have been in '/root/test.yml': line 15, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n #debug: msg={{ ansible_enp0s8_iface1.ipv4_secondaries.address }}\n - name: debug1\n ^here\n"} 

回答

1

注意ipv4_secondaries显示在方括号中,这样,你知道,这是一个列表完美的作品。

所以,你应该从列表中选择一个元素,例如:

ansible_enp0s8_iface1.ipv4_secondaries[0].address 
+0

谢谢。正是我在找什么。我会对元素提示做一个心理记录。 – crusadecoder