首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ansible ipv4辅助IP过滤?

ansible ipv4辅助IP过滤?
EN

Stack Overflow用户
提问于 2018-08-28 07:45:13
回答 1查看 0关注 0票数 0

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

我尝试运行以下内容,这比我需要的更多。

代码语言:javascript
复制
 tasks:
  - name: debug2
    debug: msg={{ ansible_enp0s8_iface1.ipv4_secondaries }}

结果

代码语言:javascript
复制
ok: [localhost] => {
"msg": [
    {
        "address": "172.16.2.20", 
        "broadcast": "172.16.2.255", 
        "netmask": "255.255.255.0", 
        "network": "172.16.2.0"
    }
]
}

但是,当我运行以下

代码语言:javascript
复制
tasks:
  - name: debug2
    debug: msg={{ ansible_enp0s8_iface1.ipv4_secondaries.address }}

我得到以下致命错误,表明“地址”未定义。我不确定为什么会发生这种情况,因为它与主界面完美配合

代码语言:javascript
复制
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"}
EN

回答 1

Stack Overflow用户

发布于 2018-08-28 17:35:39

请注意,ipv4_secondaries它显示在方括号中,这样您就知道它是一个列表。

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

代码语言:javascript
复制
ansible_enp0s8_iface1.ipv4_secondaries[0].address
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100002463

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档