ansible - 如何使用ansible根据该行中特定字段的条件值从url逐行获取
问题描述
ip-address cpu ram .. 如果这些是不同的字段并且我有多行,如何仅获取那些 cpu 字段值大于 75 的行。
使用查找模块,我可以一一获取行,但是如何为字段应用条件。
- debug: msg="{{item}}"
when: item > 30
with_items: "{{ lookup('url', 'http://{{ inventory_hostname }}:9200/_cat/nodes?h=ram.percent', wantlist=True) }}"
这里所有的值都被打印出来了。未应用该条件。
解决方案
因为你的测试是item
在数值上是否大于30,但是item
是一个字符串。
您至少希望尝试将 item 强制转换为int
:
debug: var=item
when: '(item|int) > 30'
with_items: # etc etc
推荐阅读
- python - 从股票世界中回测算法
- php - 警告:尝试访问第 43 行 /mytheme/functions.php 中 bool 类型值的数组偏移量
- pip - 为什么 intallin cvxpy 给我这个错误?
- dataweave - Mule 4:Dataweave 2.0:我正在尝试将部分响应保存在数组中,但是当我尝试使用“dropWhile”浏览它们时,它对我不起作用
- python - 如何在 bazel 中为 Python 和 pip 选择运行时?
- c++ - Esp8266 使用 + 而不是空格保存 Wlan 名称
- python - 如何将 pandas 数据框列中的时间值与定义的时间值进行比较?
- python - Python - 尝试对 Pandas DataFrame 上的 2 列进行排序时出现“TypeError: unhashable type: 'numpy.ndarray'”
- sql-server - SQL Server Management Studio:获取两个日期列之间的数据
- javascript - 如何在没有换行符或空格的情况下打印数组?