ansible ipv4辅助IP过滤 [英] ansible ipv4 secondary IP filtering
本文介绍了ansible ipv4辅助IP过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Jinja模板,需要用服务器的辅助IP填充.
I have a jinja template that needs to be populated with my server's secondary ip's.
我尝试运行以下内容,该内容比我所需要的更多.
I tried running the following which provides me with a little bit more than what i need.
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 }}
我收到以下致命错误,指示地址"未定义.我不确定为什么会发生这种情况,因为它可以与主界面完美配合
I get the following fatal error indicating "address" is undefined. I am not sure why this is happening since it works perfectly with the primary interface
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"}
推荐答案
请注意,ipv4_secondaries
显示在方括号中,这样您就知道它是一个列表.
Note that ipv4_secondaries
is displayed in a square brackets, this way you know that it's a list.
因此,您应该从列表中选择一个元素,例如:
So you should choose an element from the list, e.g.:
ansible_enp0s8_iface1.ipv4_secondaries[0].address
这篇关于ansible ipv4辅助IP过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文