[英]Use ansible facts to filter interfaces with fact = value
I want to use ansible facts to filter the network interfaces where their module is set to igb.我想使用可靠的事实来过滤其模块设置为 igb 的网络接口。
I know that I can run this command and get the network facts for all interfaces.我知道我可以运行此命令并获取所有接口的网络事实。 (inc the module for each interface) (包括每个接口的模块)
ansible -m setup -a 'gather_subset=network' host.so.com
I've tried using these variables below and doing a debug on the variable, hoping to see the names of the interfaces with that module, but i can only get it to output all facts for interfaces with module=ibg instead of just the device name.我已经尝试在下面使用这些变量并对变量进行调试,希望看到该模块的接口名称,但我只能让它输出带有 module=ibg 的接口的所有事实,而不仅仅是设备名称.
allNetworkModules: "{{ ansible_facts | dict2items | selectattr('value.module', 'defined') | map(attribute='value') | list }}"
ixgbe_module: "{{ ansible_facts | dict2items | selectattr('value.module', 'defined') | selectattr('value.module', 'equalto', 'igb') | list }}"
Can anyone tell me how I can filter to just get the interface names please?谁能告诉我如何过滤以获取接口名称?
Thank you谢谢
If you want to see just the names of all the interfaces using a particular module, you could do something like this:如果您只想查看使用特定模块的所有接口的名称,您可以执行以下操作:
- hosts: localhost
gather_facts: true
vars:
module_name: e1000e
tasks:
- debug:
msg: >-
{{
ansible_facts | dict2items
| selectattr('value.module', 'defined')
| selectattr('value.module', 'equalto', module_name)
| map(attribute='key')
| list
}}
On my system, which has a single e1000e
nic, this will output:在我的系统上,它有一个e1000e
网卡,这将输出:
TASK [debug] *****************************************************************************************************************************************************************
ok: [localhost] => {
"msg": [
"eth0"
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.